Skip to content

Commit

Permalink
Merge pull request #8 from Wisembly/fix-azurev2
Browse files Browse the repository at this point in the history
Azurev2 | Fix getUserInformation and paths
  • Loading branch information
guillaumepotier authored Sep 16, 2016
2 parents 47ec57e + 688caf9 commit 8793611
Showing 1 changed file with 7 additions and 43 deletions.
50 changes: 7 additions & 43 deletions OAuth/ResourceOwner/AzureV2ResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class AzureV2ResourceOwner extends GenericOAuth2ResourceOwner
* {@inheritDoc}
*/
protected $paths = array(
'identifier' => 'sub',
'nickname' => 'preferred_username',
'realname' => 'name',
'email' => 'email',
'profilepicture' => null,
'identifier' => 'id',
'email' => 'mail',
'nickname' => 'mail',
'realname' => 'displayName',
'firstName' => 'givenName',
'lastName' => 'surname'
);

/**
Expand Down Expand Up @@ -79,43 +80,6 @@ public function refreshAccessToken($refreshToken, array $extraParameters = array
return parent::refreshAccessToken($refreshToken, $extraParameters);
}

/**
* {@inheritDoc}
*/
public function getUserInformation(array $accessToken, array $extraParameters = array())
{
// from http://stackoverflow.com/a/28748285/624544
list(, $jwt, ) = explode('.', $accessToken['id_token'], 3);

// if the token was urlencoded, do some fixes to ensure that it is valid base64 encoded
$jwt = str_replace('-', '+', $jwt);
$jwt = str_replace('_', '/', $jwt);

// complete token if needed
switch (strlen($jwt) % 4) {
case 0:
break;

case 2:
$jwt .= '=';

case 3:
$jwt .= '=';
break;

default:
throw new \InvalidArgumentException('Invalid base64 format sent back');
}

$response = $this->getUserResponse();
$response->setResponse(base64_decode($jwt));

$response->setResourceOwner($this);
$response->setOAuthToken(new OAuthToken($accessToken));

return $response;
}

/**
* {@inheritDoc}
*/
Expand All @@ -126,7 +90,7 @@ protected function configureOptions(OptionsResolver $resolver)
$resolver->setRequired(array('scope'));

$resolver->setDefaults(array(
'infos_url' => '',
'infos_url' => 'https://graph.microsoft.com/v1.0/me',
'authorization_url' => 'https://login.microsoftonline.com/%s/oauth2/%s/authorize',
'access_token_url' => 'https://login.microsoftonline.com/%s/oauth2/%s/token',
'application' => 'common',
Expand Down

0 comments on commit 8793611

Please sign in to comment.