From 080059837b56007eb7d65db1b36bd734a9653430 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 5 Oct 2019 18:39:01 +0530 Subject: [PATCH 01/14] feat: amazon OAuth (conditional) --- app/config/providers.php | 5 ++ app/controllers/auth.php | 3 + src/Auth/OAuth/Amazon.php | 127 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 src/Auth/OAuth/Amazon.php diff --git a/app/config/providers.php b/app/config/providers.php index b45ca52a74..7cfe0c9440 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -61,4 +61,9 @@ return [ 'icon' => 'icon-apple', 'enabled' => false, ], + 'amazon' => [ + 'developers' => 'https://www.dropbox.com/developers/documentation', + 'icon' => 'icon-amazon', + 'enabled' => true, + ], ]; diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 75d7da05f2..22c4aaacae 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -730,6 +730,9 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); + // Uncomment this while testing amazon oAuth + $state = html_entity_decode($state); + if (!empty($state)) { try { $state = array_merge($defaultState, json_decode($state, true)); diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php new file mode 100644 index 0000000000..d280b02765 --- /dev/null +++ b/src/Auth/OAuth/Amazon.php @@ -0,0 +1,127 @@ +appID). + '&redirect_uri='.urlencode($this->callback). + '&response_type=code'. + '&state='.urlencode(json_encode($this->state)). + '&scope=profile'; + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code): string + { + + $headers[] = 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'; + $accessToken = $this->request( + 'POST', + 'https://api.amazon.com/auth/o2/token', + $headers, + 'code=' . urlencode($code) . + '&client_id=' . urlencode($this->appID) . + '&client_secret=' . urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback). + '&grant_type=authorization_code' + ); + $accessToken = json_decode($accessToken, true); + + if (isset($accessToken['access_token'])) { + return $accessToken['access_token']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['user_id'])) { + return $user['user_id']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['email'])) { + return $user['email']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['name'])) { + return $user['name']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken): array + { + if (empty($this->user)) { + $user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.urlencode($accessToken)); + $this->user = json_decode($user, true); + } + return $this->user; + } +} From 0d53d260daa085195f5f990437c251f7f40d0f07 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 5 Oct 2019 18:42:46 +0530 Subject: [PATCH 02/14] feat: lint fix --- app/controllers/auth.php | 2 +- src/Auth/OAuth/Amazon.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 22c4aaacae..a904c1abd6 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -731,7 +731,7 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') $validateURL = new URL(); // Uncomment this while testing amazon oAuth - $state = html_entity_decode($state); + // $state = html_entity_decode($state); if (!empty($state)) { try { diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index d280b02765..0b52f681f9 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -42,7 +42,6 @@ class Amazon extends OAuth */ public function getAccessToken(string $code): string { - $headers[] = 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'; $accessToken = $this->request( 'POST', From 39faf2f05b82cd884e6ca0b392076f69da19cec4 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 5 Oct 2019 18:43:28 +0530 Subject: [PATCH 03/14] chore: disabled amazon oAuth --- app/config/providers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/providers.php b/app/config/providers.php index 7cfe0c9440..d4c05b9a9d 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -64,6 +64,6 @@ return [ 'amazon' => [ 'developers' => 'https://www.dropbox.com/developers/documentation', 'icon' => 'icon-amazon', - 'enabled' => true, + 'enabled' => false, ], ]; From 965a68afd381c7e80ae07644013c73a9952f5418 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 5 Oct 2019 18:46:07 +0530 Subject: [PATCH 04/14] chore: added Amazon OAuth Docs --- src/Auth/OAuth/Amazon.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index 0b52f681f9..d9cf84e73f 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -7,6 +7,7 @@ use Auth\OAuth; // Reference Material // https://developer.amazon.com/docs/login-with-amazon/authorization-code-grant.html // https://developer.amazon.com/docs/login-with-amazon/register-web.html +// https://developer.amazon.com/docs/login-with-amazon/obtain-customer-profile.html class Amazon extends OAuth { /** From d126ebc787c93333ed1cb1d8ac7400958cbf7987 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 02:05:30 +0530 Subject: [PATCH 05/14] chore: added amazon image --- public/images/oauth/amazon.png | Bin 0 -> 4989 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public/images/oauth/amazon.png diff --git a/public/images/oauth/amazon.png b/public/images/oauth/amazon.png new file mode 100644 index 0000000000000000000000000000000000000000..9ce2da81e0a6929c408a1cbb0f05e7b9c3fb5d07 GIT binary patch literal 4989 zcmai2cTm$oxBbxsq$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/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index 2c9a99b8da..fbe4b65b1a 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -124,7 +124,7 @@ class Apple extends OAuth { if (empty($this->user)) { $headers[] = 'Authorization: Bearer '. urlencode($accessToken); - $user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers); + $user = $this->request('POST', '', $headers); $this->user = json_decode($user, true); } From da9504a14c49fa5b2e70e3b7cbe172e157a41498 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 02:17:28 +0530 Subject: [PATCH 07/14] chore: corrected apple Image size --- app/config/providers.php | 7 ++++++- public/images/oauth/apple.png | Bin 1683 -> 1360 bytes 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/config/providers.php b/app/config/providers.php index d4c05b9a9d..fe54486a03 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -57,7 +57,7 @@ return [ 'enabled' => true, ], 'apple' => [ - 'developers' => 'https://www.dropbox.com/developers/documentation', + 'developers' => 'https://developer.apple.com/', 'icon' => 'icon-apple', 'enabled' => false, ], @@ -66,4 +66,9 @@ return [ 'icon' => 'icon-amazon', 'enabled' => false, ], + 'amazon' => [ + 'developers' => 'https://www.dropbox.com/developers/documentation', + 'icon' => 'icon-amazon', + 'enabled' => false, + ], ]; diff --git a/public/images/oauth/apple.png b/public/images/oauth/apple.png index ca56e16bc8a523c01a7aef8ee98a37b1bf11b570..b0fdfd14f055970a22144a33cef8f0d79747b60d 100644 GIT binary patch literal 1360 zcmV-W1+V&vP)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00002 zVoOIv0RM-N%)bBt010qNS#tmY0AK(B0AB#8wP^DI000McNliru;|c{7F9Ba(C`bSR z1Vc$gK~#9!?V8_fTU8vuKlx>UXiSYuJJK5GYL`lv$*PnhmZ4NP!3U9o`ZNU*@xe!5 z1pfiS2Q4Bf6JLgt`D+XrG&)d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gGAAuO-;1goHCs zaGaJV|GYnciTWhNJED7>ms_c;ubW4j#t}{XrP>$2h~tmsWzEFU7-@KIqi!`9b`+bLuVY-ysR? zzCFCv#s2Enf4R3YFz!lxDCuEDi>rb|KO|?xLrW!x2I@|Z%S^|lB?TY$$DVp2DSK(b zw5k)TTrIHp2cG`^|oFYDEJt@UwE>T@h-MH+tR#ZtXkk#uq4)3qP zXqv<<5rJB&JNuY;oXWLHZNxL(B_|O+yV8SxD4nYJ z-%rQtFJ#;uKJnB!kiwwl<57p{d_fX#!wo-@gX1lOqV5E<0S<90x2ic>v6EKx<2L7d nD=c47Wfx#nNBBRKwT Date: Sun, 6 Oct 2019 02:18:27 +0530 Subject: [PATCH 08/14] feat: added vk to providers --- app/config/providers.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/config/providers.php b/app/config/providers.php index fe54486a03..e268426287 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -66,9 +66,9 @@ return [ 'icon' => 'icon-amazon', 'enabled' => false, ], - 'amazon' => [ - 'developers' => 'https://www.dropbox.com/developers/documentation', - 'icon' => 'icon-amazon', + 'vk' => [ + 'developers' => 'https://vk.com/dev', + 'icon' => 'icon-vk', 'enabled' => false, ], ]; From ea2fc826372aa01603e95ea763bb5f21b6f012bf Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 02:20:02 +0530 Subject: [PATCH 09/14] chore: updated amazon developers url --- app/config/providers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/providers.php b/app/config/providers.php index e268426287..5ebbf51651 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -62,7 +62,7 @@ return [ 'enabled' => false, ], 'amazon' => [ - 'developers' => 'https://www.dropbox.com/developers/documentation', + 'developers' => 'https://developer.amazon.com/apps-and-games/services-and-apis', 'icon' => 'icon-amazon', 'enabled' => false, ], From 99dd990a6c8634d522bf84949690f1cc07a1dc98 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 16:30:05 +0530 Subject: [PATCH 10/14] feat: vk OAuth Done --- app/config/providers.php | 2 +- src/Auth/OAuth/Vk.php | 154 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/Auth/OAuth/Vk.php diff --git a/app/config/providers.php b/app/config/providers.php index 5ebbf51651..444519ba26 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -69,6 +69,6 @@ return [ 'vk' => [ 'developers' => 'https://vk.com/dev', 'icon' => 'icon-vk', - 'enabled' => false, + 'enabled' => true, ], ]; diff --git a/src/Auth/OAuth/Vk.php b/src/Auth/OAuth/Vk.php new file mode 100644 index 0000000000..46f2742ac1 --- /dev/null +++ b/src/Auth/OAuth/Vk.php @@ -0,0 +1,154 @@ +appID). + '&redirect_uri='.urlencode($this->callback). + '&response_type=code'. + '&state='.urlencode(json_encode($this->state)). + '&v='.urlencode($this->version). + '&scope=openid+email'; + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code): string + { + + $headers[] = 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'; + $accessToken = $this->request( + 'POST', + 'https://oauth.vk.com/access_token?', + $headers, + 'code=' . urlencode($code) . + '&client_id=' . urlencode($this->appID) . + '&client_secret=' . urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback) + ); + $accessToken = json_decode($accessToken, true); + + if(isset($accessToken['email'])){ + $this->user['email'] = $accessToken['email']; + } + + if(isset($accessToken['user_id'])){ + $this->user['user_id'] = $accessToken['user_id']; + } + + if (isset($accessToken['access_token'])) { + return $accessToken['access_token']; + } + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken): string + { + + $user = $this->getUser($accessToken); + + if (isset($user['user_id'])) { + return $user['user_id']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken): string + { + + $user = $this->getUser($accessToken); + + if (isset($user['email'])) { + return $user['email']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['name'])) { + return $user['name']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken): array + { + if (empty($this->user['name'])) { + $user = $this->request( + 'GET', + 'https://api.vk.com/method/users.get?'. + 'v='.urlencode($this->version). + '&fields=id,name,email,first_name,last_name'. + '&access_token='.urlencode($accessToken) + ); + + $user = json_decode($user, true); + $this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name']; + + } + return $this->user; + } +} From cb0ca885c1cb8e51bd07483e72cf9136bd358a91 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 16:31:34 +0530 Subject: [PATCH 11/14] chore: lint fix --- src/Auth/OAuth/Vk.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Auth/OAuth/Vk.php b/src/Auth/OAuth/Vk.php index 46f2742ac1..ad860aff84 100644 --- a/src/Auth/OAuth/Vk.php +++ b/src/Auth/OAuth/Vk.php @@ -40,7 +40,7 @@ class Vk extends OAuth 'client_id='.urlencode($this->appID). '&redirect_uri='.urlencode($this->callback). '&response_type=code'. - '&state='.urlencode(json_encode($this->state)). + '&state='.urlencode(json_encode($this->state)). '&v='.urlencode($this->version). '&scope=openid+email'; } @@ -52,7 +52,6 @@ class Vk extends OAuth */ public function getAccessToken(string $code): string { - $headers[] = 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'; $accessToken = $this->request( 'POST', @@ -65,11 +64,11 @@ class Vk extends OAuth ); $accessToken = json_decode($accessToken, true); - if(isset($accessToken['email'])){ + if (isset($accessToken['email'])) { $this->user['email'] = $accessToken['email']; } - if(isset($accessToken['user_id'])){ + if (isset($accessToken['user_id'])) { $this->user['user_id'] = $accessToken['user_id']; } @@ -86,8 +85,7 @@ class Vk extends OAuth */ public function getUserID(string $accessToken): string { - - $user = $this->getUser($accessToken); + $user = $this->getUser($accessToken); if (isset($user['user_id'])) { return $user['user_id']; @@ -103,8 +101,7 @@ class Vk extends OAuth */ public function getUserEmail(string $accessToken): string { - - $user = $this->getUser($accessToken); + $user = $this->getUser($accessToken); if (isset($user['email'])) { return $user['email']; @@ -138,7 +135,7 @@ class Vk extends OAuth { if (empty($this->user['name'])) { $user = $this->request( - 'GET', + 'GET', 'https://api.vk.com/method/users.get?'. 'v='.urlencode($this->version). '&fields=id,name,email,first_name,last_name'. @@ -147,7 +144,6 @@ class Vk extends OAuth $user = json_decode($user, true); $this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name']; - } return $this->user; } From 8a200a409ed9dc09200687b1d982d0e26a4a3c7f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 17:27:39 +0530 Subject: [PATCH 12/14] chore: added vk icon --- public/images/oauth/vk.png | Bin 0 -> 3163 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public/images/oauth/vk.png diff --git a/public/images/oauth/vk.png b/public/images/oauth/vk.png new file mode 100644 index 0000000000000000000000000000000000000000..481303ab7cd4e3081831a63ff6629799896a1e6b GIT binary patch literal 3163 zcmb_eX*kqh8~$1Pr|gw%5wc{N3}YMnGGgpTO15k@8T%4rWXae-rK18pQp;Ei04iQG9y^|+asg+3gfReML;)Z?5&#aVq3~q@cmf81RR;i2P6q%^ zZ+xA(D)rzWCqq3LaQ4@78{el;BNx2&@B2}adJ}j6e5iiBP2HULha2mjpS$=EqmneX zWAzgNFdD#NT6fT6>u-YHZAlz4rlxlVA%Qmg>|K}e?|>!fOhQ@XGLKbgm4G9(dF=n@gToh~9G6J2(^J+pD<6D~;jj4muf`)~n3VP4Ce zq+1!UV#DhoT+->ytnyW~np!Py`R&U12lu&tjxr`Moi!j&Zag_& z)%x(@o>a-{Dy84c6MA~662p}32qkLq;IrJA=`?xbx$=cED_%!!=EXOsB_SkGXZc6T zCR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W``53}LkU$u9M?Fs}-Am>2;i9XMsu2IcvY zZ+t4Nd!NP9Ft&x;_nmo_zEBDTTanY);4w!$q}l2T5x#qb(r9u!Os&ZC9^^qM_v>8r z&|05`A(ir8DHj===Zv6tU)b?#@UWF>g+~cIj|e5F?2#Ec7D$%@SmI=1lHzd@Q#1#(FaeK-j2-MC3noN)#%N^ zqj^XxGi?YW9R9ZK%h@D0zFDC-|D)tB`K;?Sk-1Ns^*Atb)fgsf8}`$%vSRzw0h(1c zX2(SYWw*cZkZyhgXqKt+QtDuh_8=xqPD69R`Xs~%8+cm^*2N7(B*~^Dum01hM!B`k zqexhOeuPpJt?^jFzXrKDwp7lZTt08|PQ@BbU#{t4$j07k7cX`^+h1q1cvln`fb6&w zp;V8qm1PDAb#L?7r#xs~l`Z4GY>-{oJbYEw)o@8(oLV7v>s5Fiz{9}xE;Aju z7M!sn`6e&?8$>#a%EsQazyZ{>l7E$#miXi7Os#S4&ypC~pBT`Yzd29({`y{UX42N0 zpQIpZ)`{dcHJB`2(zp_(xVH`+yH@k7x6F?HXIeVsGm}3HE7RTVSN5oyZA9wx&UFZ9 z9hnHr9DnO!x2Z4XI!a4pgyp1HeZZ~ZG+Z!{z)Ywl>+y`MLjz82-C%rTs}&|s{0|Dk zlYFgrVnzHUs-xB9%2Nkv!o(irdiyfiUlLpnVQo36IL(WBvXFb>!=Bb=_Js&#G48^K zUxr0Y^%UtzrqeUp;n%vqYue=I+Xj*t4RvlwF@G-qzmYRK{+6_Rp|GMn>Yy#+uWRM+ z;^_ZS+1d9Y6#!YV3=|{-27wjs$S5kyDk#gyNP-oV!C)?1`M;C-e+3?1F0PM){ Date: Sun, 6 Oct 2019 18:26:44 +0530 Subject: [PATCH 13/14] feat: implemented abstract method parseState --- app/config/providers.php | 2 +- app/controllers/auth.php | 36 ++++++++++++++++++------------------ src/Auth/OAuth.php | 13 +++++++++++++ src/Auth/OAuth/Amazon.php | 10 ++++++++++ 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/config/providers.php b/app/config/providers.php index 444519ba26..140dbeaf6f 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -64,7 +64,7 @@ return [ 'amazon' => [ 'developers' => 'https://developer.amazon.com/apps-and-games/services-and-apis', 'icon' => 'icon-amazon', - 'enabled' => false, + 'enabled' => true, ], 'vk' => [ 'developers' => 'https://vk.com/dev', diff --git a/app/controllers/auth.php b/app/controllers/auth.php index a904c1abd6..849f783113 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -733,24 +733,6 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') // Uncomment this while testing amazon oAuth // $state = html_entity_decode($state); - if (!empty($state)) { - try { - $state = array_merge($defaultState, json_decode($state, true)); - } catch (\Exception $exception) { - throw new Exception('Failed to parse login state params as passed from OAuth provider'); - } - } else { - $state = $defaultState; - } - - if (!$validateURL->isValid($state['success'])) { - throw new Exception('Invalid redirect URL for success login', 400); - } - - if (!empty($state['failure']) && !$validateURL->isValid($state['failure'])) { - throw new Exception('Invalid redirect URL for failure login', 400); - } - $appId = $project->getAttribute('usersOauth'.ucfirst($provider).'Appid', ''); $appSecret = $project->getAttribute('usersOauth'.ucfirst($provider).'Secret', '{}'); @@ -769,6 +751,24 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') $oauth = new $classname($appId, $appSecret, $callback); + if (!empty($state)) { + try { + $state = array_merge($defaultState, $oauth->parseState($state)); + } catch (\Exception $exception) { + throw new Exception('Failed to parse login state params as passed from OAuth provider'); + } + } else { + $state = $defaultState; + } + + if (!$validateURL->isValid($state['success'])) { + throw new Exception('Invalid redirect URL for success login', 400); + } + + if (!empty($state['failure']) && !$validateURL->isValid($state['failure'])) { + throw new Exception('Invalid redirect URL for failure login', 400); + } + $accessToken = $oauth->getAccessToken($code); if (empty($accessToken)) { diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 70d7f448cf..cbae4638e4 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -78,6 +78,19 @@ abstract class OAuth */ abstract public function getUserName(string $accessToken):string; + // The parseState function was designed specifically for Amazon OAuth Adapter to override. + // The response from Amazon is html encoded and hence it needs to be html_decoded before + // json_decoding + + /** + * @param $state + * + * @return json + */ + public function parseState(string $state) { + return json_decode($state, true); + } + /** * @param string $method * @param string $url diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index d9cf84e73f..95744e9ba3 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -23,6 +23,16 @@ class Amazon extends OAuth return 'amazon'; } + /** + * @param $state + * + * @return json + */ + public function parseState(string $state) { + return json_decode(html_entity_decode($state), true); + } + + /** * @return string */ From d2ebafb23749b52c21c079d89d01b7d3787d44b2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 18:28:01 +0530 Subject: [PATCH 14/14] chore: lint fix --- src/Auth/OAuth.php | 5 +++-- src/Auth/OAuth/Amazon.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index cbae4638e4..a96ebb7a68 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -79,7 +79,7 @@ abstract class OAuth abstract public function getUserName(string $accessToken):string; // The parseState function was designed specifically for Amazon OAuth Adapter to override. - // The response from Amazon is html encoded and hence it needs to be html_decoded before + // The response from Amazon is html encoded and hence it needs to be html_decoded before // json_decoding /** @@ -87,7 +87,8 @@ abstract class OAuth * * @return json */ - public function parseState(string $state) { + public function parseState(string $state) + { return json_decode($state, true); } diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index 95744e9ba3..71bb8aaee6 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -28,7 +28,8 @@ class Amazon extends OAuth * * @return json */ - public function parseState(string $state) { + public function parseState(string $state) + { return json_decode(html_entity_decode($state), true); }