@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 81 lines 1.7 kB view raw
1<?php 2 3/** 4 * Authentication adapter for Amazon OAuth2. 5 */ 6final class PhutilAmazonAuthAdapter extends PhutilOAuthAuthAdapter { 7 8 public function getAdapterType() { 9 return 'amazon'; 10 } 11 12 public function getAdapterDomain() { 13 return 'amazon.com'; 14 } 15 16 public function getAccountID() { 17 return $this->getOAuthAccountData('user_id'); 18 } 19 20 public function getAccountEmail() { 21 return $this->getOAuthAccountData('email'); 22 } 23 24 public function getAccountName() { 25 return null; 26 } 27 28 public function getAccountImageURI() { 29 return null; 30 } 31 32 public function getAccountURI() { 33 return null; 34 } 35 36 public function getAccountRealName() { 37 return $this->getOAuthAccountData('name'); 38 } 39 40 protected function getAuthenticateBaseURI() { 41 return 'https://www.amazon.com/ap/oa'; 42 } 43 44 protected function getTokenBaseURI() { 45 return 'https://api.amazon.com/auth/o2/token'; 46 } 47 48 public function getScope() { 49 return 'profile'; 50 } 51 52 public function getExtraAuthenticateParameters() { 53 return array( 54 'response_type' => 'code', 55 ); 56 } 57 58 public function getExtraTokenParameters() { 59 return array( 60 'grant_type' => 'authorization_code', 61 ); 62 } 63 64 protected function loadOAuthAccountData() { 65 $uri = new PhutilURI('https://api.amazon.com/user/profile'); 66 $uri->replaceQueryParam('access_token', $this->getAccessToken()); 67 68 $future = new HTTPSFuture($uri); 69 list($body) = $future->resolvex(); 70 71 try { 72 return phutil_json_decode($body); 73 } catch (PhutilJSONParserException $ex) { 74 throw new Exception( 75 pht('Expected valid JSON response from Amazon account data request.'), 76 0, 77 $ex); 78 } 79 } 80 81}