-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Okta Provider * Fix styles. * Clean up composer json * Add extraConfig values for base_url
- Loading branch information
0 parents
commit dcda134
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Okta; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class OktaExtendSocialite | ||
{ | ||
/** | ||
* Execute the provider. | ||
*/ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled) | ||
{ | ||
$socialiteWasCalled->extendSocialite('okta', __NAMESPACE__.'\Provider'); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Okta; | ||
|
||
use SocialiteProviders\Manager\OAuth2\User; | ||
use Laravel\Socialite\Two\ProviderInterface; | ||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
|
||
class Provider extends AbstractProvider implements ProviderInterface | ||
{ | ||
/** | ||
* Unique Provider Identifier. | ||
*/ | ||
const IDENTIFIER = 'OKTA'; | ||
|
||
/** | ||
* Scopes defintions. | ||
* | ||
* @see http://developer.okta.com/docs/api/resources/oidc.html#scopes | ||
*/ | ||
const SCOPE_OPENID = 'openid'; | ||
const SCOPE_PROFILE = 'profile'; | ||
const SCOPE_EMAIL = 'email'; | ||
const SCOPE_ADDRESS = 'address'; | ||
const SCOPE_PHONE = 'phone'; | ||
const SCOPE_OFFLINE_ACCESS = 'offline_access'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = [ | ||
'openid', | ||
'profile', | ||
'email', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopeSeparator = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getOktaUrl() | ||
{ | ||
return $this->getConfig('base_url'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function additionalConfigKeys() | ||
{ | ||
return ['base_url']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getAuthUrl($state) | ||
{ | ||
return $this->buildAuthUrlFromBase($this->getOktaUrl().'/oauth2/v1/authorize', $state); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenUrl() | ||
{ | ||
return $this->getOktaUrl().'/oauth2/v1/token'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUserByToken($token) | ||
{ | ||
$response = $this->getHttpClient()->get($this->getOktaUrl().'/oauth2/v1/userinfo', [ | ||
'headers' => [ | ||
'Authorization' => 'Bearer '.$token, | ||
], | ||
]); | ||
|
||
return json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function mapUserToObject(array $user) | ||
{ | ||
return (new User())->setRaw($user)->map([ | ||
'id' => array_get($user, 'sub'), | ||
'email' => array_get($user, 'email'), | ||
'email_verified' => array_get($user, 'email_verified', false), | ||
'nickname' => array_get($user, 'nickname'), | ||
'name' => array_get($user, 'name'), | ||
'first_name' => array_get($user, 'given_name'), | ||
'last_name' => array_get($user, 'family_name'), | ||
'profileUrl' => array_get($user, 'profile'), | ||
'address' => array_get($user, 'address'), | ||
'phone' => array_get($user, 'phone'), | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenFields($code) | ||
{ | ||
return array_merge(parent::getTokenFields($code), [ | ||
'grant_type' => 'authorization_code', | ||
]); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "socialiteproviders/okta", | ||
"description": "Okta OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"authors": [{ | ||
"name": "Chase Coney", | ||
"email": "[email protected]" | ||
}], | ||
"require": { | ||
"php": "^5.6 || ^7.0", | ||
"socialiteproviders/manager": "~2.0 || ~3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\Okta\\": "" | ||
} | ||
} | ||
} |