Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example.complete
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ OIDC_GROUPS_CLAIM=groups
OIDC_REMOVE_FROM_GROUPS=false
OIDC_EXTERNAL_ID_CLAIM=sub
OIDC_END_SESSION_ENDPOINT=false
OIDC_AUTO_REGISTER=true

# Disable default third-party services such as Gravatar and Draw.IO
# Service-specific options will override this option
Expand Down
15 changes: 10 additions & 5 deletions app/Access/Oidc/OidcService.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,17 @@ protected function processAccessTokenCallback(OidcAccessToken $accessToken, Oidc
throw new OidcException(trans('errors.oidc_already_logged_in'));
}


try {
$user = $this->registrationService->findOrRegister(
$userDetails['name'],
$userDetails['email'],
$userDetails['external_id']
);
if ($this->config()['auto_register'] === false) {
$user = $this->registrationService->findOrFail($userDetails['external_id']);
} else {
$user = $this->registrationService->findOrRegister(
$userDetails['name'],
$userDetails['email'],
$userDetails['external_id']
);
}
} catch (UserRegistrationException $exception) {
throw new OidcException($exception->getMessage());
}
Expand Down
19 changes: 19 additions & 0 deletions app/Access/RegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ protected function registrationAllowed(): bool
return in_array($authMethod, $authMethodsWithRegistration) && setting('registration-enabled');
}

/**
* Attempt to find a user in the system.
* For use with external auth systems since password is auto-generated.
*
* @throws UserRegistrationException
*/
public function findOrFail(string $externalId): User
{
$user = User::query()
->where('external_auth_id', '=', $externalId)
->first();

if (is_null($user)) {
throw new UserRegistrationException(trans('auth.failed'), '/login');
}

return $user;
}

/**
* Attempt to find a user in the system otherwise register them as a new
* user. For use with external auth systems since password is auto-generated.
Expand Down
3 changes: 3 additions & 0 deletions app/Config/oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
// A string value is used as the URL.
'end_session_endpoint' => env('OIDC_END_SESSION_ENDPOINT', false),

// Enable Auto Register
'auto_register' => env('OIDC_AUTO_REGISTER', true),

// Add extra scopes, upon those required, to the OIDC authentication request
// Multiple values can be provided comma seperated.
'additional_scopes' => env('OIDC_ADDITIONAL_SCOPES', null),
Expand Down