Skip to content

Commit

Permalink
Extract duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Dec 27, 2014
1 parent 7c5137b commit 6c9d77e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/AdamWathan/EloquentOAuth/Providers/GitHubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ protected function getUserDataUrl()

protected function parseTokenResponse($response)
{
$data = json_decode($response);
if (! isset($data->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $data->access_token;
return $this->parseJsonTokenResponse($response);
}

protected function requestUserData()
Expand Down
6 changes: 1 addition & 5 deletions src/AdamWathan/EloquentOAuth/Providers/GoogleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ protected function getUserDataUrl()

protected function parseTokenResponse($response)
{
$data = json_decode($response);
if (! isset($data->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $data->access_token;
return $this->parseJsonTokenResponse($response);
}

protected function parseUserDataResponse($response)
Expand Down
6 changes: 1 addition & 5 deletions src/AdamWathan/EloquentOAuth/Providers/InstagramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ protected function compileScopes()

protected function parseTokenResponse($response)
{
$data = json_decode($response);
if (! isset($data->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $data->access_token;
return $this->parseJsonTokenResponse($response);
}

protected function requestUserData()
Expand Down
6 changes: 1 addition & 5 deletions src/AdamWathan/EloquentOAuth/Providers/LinkedInProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ protected function getUserDataUrl()

protected function parseTokenResponse($response)
{
$response = json_decode($response);
if (! isset($response->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $response->access_token;
return $this->parseJsonTokenResponse($response);
}

protected function buildUserDataUrl()
Expand Down
9 changes: 9 additions & 0 deletions src/AdamWathan/EloquentOAuth/Providers/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ protected function getAuthorizationCode()
return $this->input->get('code');
}

protected function parseJsonTokenResponse($response)
{
$response = json_decode($response);
if (! isset($response->access_token)) {
throw new InvalidAuthorizationCodeException;
}
return $response->access_token;
}

abstract protected function getAuthorizeUrl();
abstract protected function getAccessTokenBaseUrl();
abstract protected function getUserDataUrl();
Expand Down

0 comments on commit 6c9d77e

Please sign in to comment.