1111use Illuminate \Support \Facades \Config ;
1212use Illuminate \Support \Facades \Route ;
1313use Vizir \KeycloakWebGuard \Auth \KeycloakAccessToken ;
14- use Vizir \KeycloakWebGuard \Auth \Guard \KeycloakWebGuard ;
1514
1615class KeycloakService
1716{
1817 /**
1918 * The Session key for token
2019 */
21- const KEYCLOAK_SESSION = '_keycloak_token ' ;
20+ public const KEYCLOAK_SESSION = '_keycloak_token ' ;
2221
2322 /**
2423 * The Session key for state
2524 */
26- const KEYCLOAK_SESSION_STATE = '_keycloak_state ' ;
25+ public const KEYCLOAK_SESSION_STATE = '_keycloak_state ' ;
2726
2827 /**
2928 * Keycloak URL
@@ -95,6 +94,11 @@ class KeycloakService
9594 */
9695 protected $ httpClient ;
9796
97+ /**
98+ * @var array of strings
99+ */
100+ protected $ scopes = ['openid ' ];
101+
98102 /**
99103 * The Constructor
100104 * You can extend this service setting protected variables before call
@@ -133,6 +137,8 @@ public function __construct(ClientInterface $client)
133137 $ this ->redirectLogout = Config::get ('keycloak-web.redirect_logout ' );
134138 }
135139
140+ $ this ->scopes = array_merge ($ this ->scopes , Config::get ('keycloak-web.scopes ' ));
141+
136142 $ this ->state = $ this ->generateRandomState ();
137143 $ this ->httpClient = $ client ;
138144 }
@@ -148,7 +154,7 @@ public function getLoginUrl()
148154 {
149155 $ url = $ this ->getOpenIdValue ('authorization_endpoint ' );
150156 $ params = [
151- 'scope ' => ' openid ' ,
157+ 'scope ' => implode ( ' ' , $ this -> scopes ) ,
152158 'response_type ' => 'code ' ,
153159 'client_id ' => $ this ->getClientId (),
154160 'redirect_uri ' => $ this ->callbackUrl ,
@@ -275,7 +281,7 @@ public function refreshAccessToken($credentials)
275281 * Invalidate Refresh
276282 *
277283 * @param string $refreshToken
278- * @return array
284+ * @return bool
279285 */
280286 public function invalidateRefreshToken ($ refreshToken )
281287 {
@@ -302,6 +308,7 @@ public function invalidateRefreshToken($refreshToken)
302308 /**
303309 * Get access token from Code
304310 * @param array $credentials
311+ * @throws Exception
305312 * @return array
306313 */
307314 public function getUserProfile ($ credentials )
0 commit comments