11<?php namespace App \libs \Auth ;
2- use Illuminate \Support \Facades \Config ;
3-
42/**
53 * Copyright 2021 OpenStack Foundation
64 * Licensed under the Apache License, Version 2.0 (the "License");
1311 * See the License for the specific language governing permissions and
1412 * limitations under the License.
1513 **/
16-
14+ use Illuminate \Support \Facades \Config ;
15+ use Illuminate \Support \Facades \Log ;
16+ use Illuminate \Support \Facades \Request ;
1717/**
1818 * Class SocialLoginProviders
1919 * @package App\libs\Auth
@@ -25,16 +25,15 @@ final class SocialLoginProviders
2525 const LinkedIn = "linkedin " ;
2626 const Google = "google " ;
2727 const OKTA = 'okta ' ;
28-
29- const AUTH0 = 'auth0 ' ;
28+ const LFID = 'lfid ' ;
3029
3130 const ValidProviders = [
3231 self ::Facebook,
3332 self ::LinkedIn,
3433 self ::Apple,
3534 //self::Google
3635 self ::OKTA ,
37- self ::AUTH0 ,
36+ self ::LFID ,
3837 ];
3938
4039 /**
@@ -59,9 +58,53 @@ public static function isEnabledProvider(string $provider):bool{
5958 */
6059 public static function buildSupportedProviders ():array {
6160 $ res = [];
61+ $ tenant = null ;
62+ $ allowed_3rd_party_providers = [];
63+
64+ if (Request::has ("tenant " )){
65+ $ tenant = trim (Request::get ("tenant " ));
66+ $ allowed_3rd_party_providers = explode (', ' ,Config::get ("tenants. " .$ tenant .".allowed_3rd_party_providers " ,"" ));
67+ }
68+
69+ Log::debug ("SocialLoginProviders::buildSupportedProviders " , ["tenant " => $ tenant , "allowed_3rd_party_providers " => $ allowed_3rd_party_providers ]);
6270 foreach (self ::ValidProviders as $ provider ){
63- if (self ::isEnabledProvider ($ provider ))
71+ Log::debug ("SocialLoginProviders::buildSupportedProviders " , ["tenant " => $ tenant , "provider " => $ provider ]);
72+ // check if the 3rd party provider has defined some exclusive tenants ...
73+ $ tenants = explode (', ' , Config::get ("services. " .$ provider .".tenants " ,"" ));
74+ // check first its enabled ...
75+ if (self ::isEnabledProvider ($ provider )) {
76+ Log::debug (sprintf ( "SocialLoginProviders::buildSupportedProviders provider %s is enabled " , $ provider ));
77+ if (!empty ($ tenant )){
78+ if (count ($ tenants ) > 0 && !in_array ($ tenant , $ tenants )){ // check if we have tenants defined at provider level
79+ Log::warning
80+ (
81+ sprintf
82+ (
83+ "SocialLoginProviders::buildSupportedProviders provider %s is not enabled for tenant %s " ,
84+ $ provider ,
85+ $ tenant
86+ ),
87+ ["tenants " => $ tenants ]
88+ );
89+ continue ;
90+ } // else check if the tenant has that provider enabled
91+ else if (!in_array ($ provider , $ allowed_3rd_party_providers )) {
92+ Log::warning
93+ (
94+ sprintf
95+ (
96+ "SocialLoginProviders::buildSupportedProviders provider %s is not enabled for tenant %s " ,
97+ $ provider ,
98+ $ tenant
99+ ),
100+ ["allowed_3rd_party_providers " => $ allowed_3rd_party_providers ]
101+ );
102+ continue ;
103+ }
104+ }
105+ Log::debug (sprintf ("SocialLoginProviders::buildSupportedProviders provider %s is enabled " , $ provider ));
64106 $ res [$ provider ] = ucfirst ($ provider );
107+ }
65108 }
66109 return $ res ;
67110 }
0 commit comments