Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sso provider wrap key null issue #160

Merged
merged 1 commit into from
Aug 19, 2022
Merged
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ SSO_CALLBACK=${APP_URL}/oauth/callback
# for example: { "data": "id": "name": "John Doe", "email": "john@example.com" }
# If you would like to use a custom key instead of data, you may define it here.
# you can also do something like 'data.user' if its nested.
# or you can set it to null if sso provider user endpoint response is not wrapped in a key.
# or you can set it to nothing (do not set it to value 'null'. just leave it empty value)
# if sso provider user endpoint response is not wrapped in a key.
SSO_PROVIDER_USER_ENDPOINT_DATA_WRAP_KEY="data"
# The keys that should be present in the sso provider user endpoint response
SSO_PROVIDER_USER_ENDPOINT_KEYS="id,email,name"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ SSO_CALLBACK=${APP_URL}/oauth/callback
# Mostly, your sso provider user endpoint response is wrapped in a `data` key.
# for example: { "data": "id": "name": "John Doe", "email": "john@example.com" }
# If you would like to use a custom key instead of data, you may define it here.
# or you can set it to null if sso provider user endpoint response is not wrapped in a key.
# you can also do something like 'data.user' if its nested.
# or you can set it to nothing (do not set it to value 'null'. just leave it empty value)
# if sso provider user endpoint response is not wrapped in a key.
SSO_PROVIDER_USER_ENDPOINT_DATA_WRAP_KEY="data"
# The keys that should be present in the sso provider user endpoint response
SSO_PROVIDER_USER_ENDPOINT_KEYS="id,email,name"
Expand Down
4 changes: 2 additions & 2 deletions app/SocialProviders/SsoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ protected function mapUserToObject(array $user)
$providerUserEndpointKeys = config('services.sso.provider_user_endpoint_keys') ?? 'id,email,name';
$providerId = config('services.sso.provider_id') ?? 'id';

if($providerUserEndpointDataWrapKey !== null) {
if($providerUserEndpointDataWrapKey) {
$user = Arr::get($user, $providerUserEndpointDataWrapKey);
}

if ($user === null || !Arr::has($user, explode(',', $providerUserEndpointKeys))) {
if($providerUserEndpointDataWrapKey !== null) {
if($providerUserEndpointDataWrapKey) {
throw new RuntimeException("The SSO user endpoint should return an {$providerUserEndpointKeys} in the `{$providerUserEndpointDataWrapKey}` field of the JSON response.");
} else {
throw new RuntimeException("The SSO user endpoint should return an {$providerUserEndpointKeys} in the JSON response.");
Expand Down
3 changes: 2 additions & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
* for example: { "data": "id": "name": "John Doe", "email": "john@example.com" }
* If you would like to use a custom key instead of data, you may define it here.
* you can also set something like 'data.user' if its nested.
* or you can set it to null if sso provider user endpoint response is not wrapped in a key.
* or you can set it to nothing (do not set it to value 'null'. just leave it empty value)
* if sso provider user endpoint response is not wrapped in a key.
*/
'provider_user_endpoint_data_wrap_key' => env('SSO_PROVIDER_USER_ENDPOINT_DATA_WRAP_KEY'),
// The keys that should be present in the sso provider user endpoint response
Expand Down