-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/auth0 3rd party provider #93
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9529d03
fix: emit OTP do not attemp to create password reset link if user is …
smarcet 930c37a
chore: add auth0 socialite provider
smarcet 31eb023
chore: add tenant logic
smarcet 34ffe6f
chore: add tenant to auth request (OIDC)
smarcet 53e1a46
chore: fix on empty tenant
smarcet 8153bfb
Update app/Strategies/DisplayResponseUserAgentStrategy.php
smarcet 7a7d272
Update app/libs/Auth/SocialLoginProviders.php
smarcet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,4 @@ | ||||||
| <?php namespace App\libs\Auth; | ||||||
| use Illuminate\Support\Facades\Config; | ||||||
|
|
||||||
| /** | ||||||
| * Copyright 2021 OpenStack Foundation | ||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|
|
@@ -14,6 +12,10 @@ | |||||
| * limitations under the License. | ||||||
| **/ | ||||||
|
|
||||||
| use Illuminate\Support\Facades\Config; | ||||||
| use Illuminate\Support\Facades\Log; | ||||||
| use Illuminate\Support\Facades\Request; | ||||||
|
|
||||||
| /** | ||||||
| * Class SocialLoginProviders | ||||||
| * @package App\libs\Auth | ||||||
|
|
@@ -25,41 +27,116 @@ final class SocialLoginProviders | |||||
| const LinkedIn = "linkedin"; | ||||||
| const Google = "google"; | ||||||
| const OKTA = 'okta'; | ||||||
| const LFID = 'lfid'; | ||||||
|
|
||||||
| const ValidProviders = [ | ||||||
| self::Facebook, | ||||||
| self::LinkedIn, | ||||||
| self::Apple, | ||||||
| //self::Google | ||||||
| self::OKTA, | ||||||
| self::LFID, | ||||||
| ]; | ||||||
|
|
||||||
| /** | ||||||
| * @param string $provider | ||||||
| * @return bool | ||||||
| */ | ||||||
| public static function isSupportedProvider(string $provider):bool{ | ||||||
| public static function isSupportedProvider(string $provider): bool | ||||||
| { | ||||||
| return in_array($provider, self::ValidProviders); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @param string $provider | ||||||
| * @return bool | ||||||
| */ | ||||||
| public static function isEnabledProvider(string $provider):bool{ | ||||||
| return !empty(Config::get("services.".$provider.".client_id", null)) && | ||||||
| !empty(Config::get("services.".$provider.".client_secret", null)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @return string[] | ||||||
| * @param string $provided_tenant | ||||||
| * @return array | ||||||
| */ | ||||||
| public static function buildSupportedProviders():array{ | ||||||
| public static function buildSupportedProviders(string $provided_tenant = ''): array | ||||||
| { | ||||||
| Log::debug("SocialLoginProviders::buildSupportedProviders", ["provided_tenant" => $provided_tenant]); | ||||||
| $res = []; | ||||||
| foreach(self::ValidProviders as $provider){ | ||||||
| if(self::isEnabledProvider($provider)) | ||||||
| $tenant = trim(Request::get('tenant', $provided_tenant)); | ||||||
| $allowed_3rd_party_providers = self::toList( | ||||||
| Config::get("tenants.$tenant.allowed_3rd_party_providers", '') | ||||||
| ); | ||||||
|
|
||||||
| Log::debug("SocialLoginProviders::buildSupportedProviders", ["tenant" => $tenant, "allowed_3rd_party_providers" => $allowed_3rd_party_providers]); | ||||||
| foreach (self::ValidProviders as $provider) { | ||||||
| Log::debug("SocialLoginProviders::buildSupportedProviders", ["tenant" => $tenant, "provider" => $provider]); | ||||||
|
|
||||||
| if (!self::isEnabledProvider($provider)) { | ||||||
| Log::warning("SocialLoginProviders::buildSupportedProviders provider is not enabled.", ["tenant" => $tenant, "provider" => $provider]); | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| // check if the 3rd party provider has defined some exclusive tenants ... | ||||||
| $tenants = self::toList( | ||||||
| Config::get("services.$provider.tenants", '') | ||||||
| ); | ||||||
|
|
||||||
| // If no tenant param was provided, any enabled provider is allowed. | ||||||
| if ($tenant === '' && count($tenants)==0) { | ||||||
|
smarcet marked this conversation as resolved.
Outdated
|
||||||
| $res[$provider] = ucfirst($provider); | ||||||
| continue; | ||||||
| } | ||||||
| Log::debug(sprintf("SocialLoginProviders::buildSupportedProviders provider %s is enabled", $provider)); | ||||||
| // 1. check if we have exclusive tenants defined at provider level | ||||||
| if (count($tenants) > 0 && !in_array($tenant, $tenants)) { | ||||||
| // tenant is not defined on the exclusive collection of the provider | ||||||
| Log::warning | ||||||
| ( | ||||||
| sprintf | ||||||
| ( | ||||||
| "SocialLoginProviders::buildSupportedProviders provider %s is not enabled for tenant %s", | ||||||
| $provider, | ||||||
| $tenant | ||||||
| ), | ||||||
| ["tenants" => $tenants] | ||||||
| ); | ||||||
| continue; | ||||||
| } | ||||||
| // 2. check if the tenant has that provider enabled | ||||||
| if (!count($tenants) && !in_array($provider, $allowed_3rd_party_providers)) { | ||||||
|
||||||
| if (!count($tenants) && !in_array($provider, $allowed_3rd_party_providers)) { | |
| if (count($tenants) == 0 && !in_array($provider, $allowed_3rd_party_providers)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.