-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from kasperrt/master
Added dataporten as service
- Loading branch information
Showing
5 changed files
with
100 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,30 @@ | ||
<?php | ||
|
||
namespace OAuth\Plugin; | ||
|
||
use OAuth\OAuth2\Service\Dataporten; | ||
|
||
class DataportenAdapter extends AbstractAdapter { | ||
|
||
/** | ||
* Retrieve the user's data | ||
* | ||
* The array needs to contain at least 'user', 'email', 'name' and optional 'grps' | ||
* | ||
* @return array | ||
*/ | ||
public function getUser() { | ||
$JSON = new \JSON(JSON_LOOSE_TYPE); | ||
$data = array(); | ||
|
||
$result = $JSON->decode($this->oAuth->request('https://auth.dataporten.no/userinfo')); | ||
$result_grous = $JSON->decode($this->oAuth->request('https://groups-api.dataporten.no/groups/me/groups')); | ||
|
||
$data['user'] = $result['user']['userid']; | ||
$data['name'] = $result['user']['name']; | ||
$data['mail'] = $result['user']['email']; | ||
|
||
return $data; | ||
} | ||
|
||
} |
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
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
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
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,63 @@ | ||
<?php | ||
|
||
namespace OAuth\OAuth2\Service; | ||
|
||
use OAuth\OAuth2\Token\StdOAuth2Token; | ||
use OAuth\Common\Http\Exception\TokenResponseException; | ||
use OAuth\OAuth2\Service\Exception\InvalidAccessTypeException; | ||
use OAuth\Common\Http\Uri\Uri; | ||
|
||
class Dataporten extends AbstractService | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAuthorizationEndpoint() | ||
{ | ||
return new Uri('https://auth.dataporten.no/oauth/authorization'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAccessTokenEndpoint() | ||
{ | ||
return new Uri('https://auth.dataporten.no/oauth/token'); | ||
} | ||
|
||
protected function getAuthorizationMethod() | ||
{ | ||
return static::AUTHORIZATION_METHOD_HEADER_BEARER; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function parseAccessTokenResponse($responseBody) | ||
{ | ||
$data = json_decode($responseBody, true); | ||
|
||
if (null === $data || !is_array($data)) { | ||
throw new TokenResponseException('Unable to parse response.'); | ||
} elseif (isset($data['error'])) { | ||
throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); | ||
} | ||
|
||
$token = new StdOAuth2Token(); | ||
$token->setAccessToken($data['access_token']); | ||
$token->setLifetime($data['expires_in']); | ||
|
||
if (isset($data['refresh_token'])) { | ||
$token->setRefreshToken($data['refresh_token']); | ||
unset($data['refresh_token']); | ||
} | ||
|
||
unset($data['access_token']); | ||
unset($data['expires_in']); | ||
|
||
$token->setExtraParams($data); | ||
|
||
return $token; | ||
} | ||
} |