Skip to content

Commit

Permalink
Fixed wrong redirect_uri when popup is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodge committed Jul 14, 2014
1 parent 3ae0a4b commit 9df4ea0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Yii2 EAuth Change Log
=====================

### 2.2.2 (15.07.2014)
* Fixed wrong redirect_uri when popup is used

### 2.2.1 (25.04.2014)
* Fix missing query params in callback urls (#26)
* Follow Yii2 code style
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/eauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
url += url.indexOf('?') >= 0 ? '&' : '?';
if (url.indexOf('redirect_uri=') === -1)
url += 'redirect_uri=' + encodeURIComponent(redirect_uri) + '&';
url += 'js';
url += 'js=';

var centerWidth = (window.screen.width - options.popup.width) / 2,
centerHeight = (window.screen.height - options.popup.height) / 2;
Expand Down
22 changes: 14 additions & 8 deletions src/oauth2/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,23 @@ protected function getProxy()
*/
protected function getCallbackUrl()
{
$route = Yii::$app->getRequest()->getQueryParams();
array_unshift($route, '');

// Can not use these params in OAuth2 callbacks
foreach (['code', 'state'] as $param) {
if (isset($route[$param])) {
unset($route[$param]);
if (isset($_GET['redirect_uri'])) {
$url = $_GET['redirect_uri'];
}
else {
$route = Yii::$app->getRequest()->getQueryParams();
array_unshift($route, '');

// Can not use these params in OAuth2 callbacks
foreach (['code', 'state', 'redirect_uri'] as $param) {
if (isset($route[$param])) {
unset($route[$param]);
}
}

$url = Url::to($route, true);
}

$url = Url::to($route, true);
return $url;
}

Expand Down
24 changes: 21 additions & 3 deletions src/services/FacebookOAuth2Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ public function getAccessTokenArgumentNames()
*/
public function parseAccessTokenResponse($response)
{
// Facebook gives us a query string...
parse_str($response, $data);
return $data;
// Facebook gives us a query string or json
if ($response[0] === '{') {
return json_decode($response, true);
}
else {
parse_str($response, $data);
return $data;
}
}

/**
Expand All @@ -95,4 +100,17 @@ protected function fetchResponseError($response)
return null;
}
}

/**
* @param array $data
* @return string|null
*/
public function getAccessTokenResponseError($data)
{
$error = $this->fetchResponseError($data);
if (!$error) {
return null;
}
return $error['code'].': '.$error['message'];
}
}

0 comments on commit 9df4ea0

Please sign in to comment.