mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-20 18:43:20 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
63 lines
2.4 KiB
PHP
63 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Identity\Social;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Audit\Action;
|
|
use App\Modules\Clients\ClientProvisioning;
|
|
use App\Modules\Identity\AuthSource;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* A provider identity signing in for the first time, with no local
|
|
* account yet.
|
|
*
|
|
* Always a client, never staff — there is no role parameter on this path,
|
|
* so no misconfiguration can let an identity provider mint an account
|
|
* with authority over the installation. v1's equivalent had a
|
|
* `social_login_default_role` setting that offered staff roles.
|
|
*
|
|
* Approval is the provider's own `auto_approve`, not the
|
|
* `ClientsAutoApprove` a self-registration asks, for the reason LDAP
|
|
* already established: one is about strangers arriving at a public form,
|
|
* the other about people a provider you configured has authenticated.
|
|
* `ClientsAutoGroup` stays shared, since which group a new client joins
|
|
* does not turn on how they arrived.
|
|
*/
|
|
class SocialProvisioner
|
|
{
|
|
public function __construct(
|
|
private readonly ClientProvisioning $clients,
|
|
) {}
|
|
|
|
/**
|
|
* @param bool $autoApprove Decided by the caller, not read from the
|
|
* settings row: an address the provider
|
|
* never verified goes to the approval
|
|
* queue whatever the setting says.
|
|
*/
|
|
public function provision(SocialSettings $settings, SocialIdentity $identity, bool $autoApprove): ?User
|
|
{
|
|
if (! $settings->auto_provision || $identity->email === null) {
|
|
return null;
|
|
}
|
|
|
|
return $this->clients->provision(
|
|
name: $identity->name ?? $identity->email,
|
|
email: $identity->email,
|
|
// A password they will never use and never learn: this account
|
|
// signs in through the provider. Generated rather than left
|
|
// null so nothing downstream has to special-case an empty
|
|
// hash, and it is why promoting one to staff requires setting
|
|
// a real password — see AccountConversion::requiresNewPassword().
|
|
password: Str::password(64),
|
|
action: Action::SocialClientProvisioned,
|
|
source: AuthSource::Social,
|
|
autoApprove: $autoApprove,
|
|
context: ['provider' => $settings->provider->label()],
|
|
);
|
|
}
|
|
}
|