[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 500px service. 4 * 5 * @author Pedro Amorim <contact@pamorim.fr> 6 * @license http://www.opensource.org/licenses/mit-license.html MIT License 7 * 8 * @see https://developers.500px.com/ 9 */ 10 11 namespace OAuth\OAuth1\Service; 12 13 use OAuth\Common\Consumer\CredentialsInterface; 14 use OAuth\Common\Http\Client\ClientInterface; 15 use OAuth\Common\Http\Exception\TokenResponseException; 16 use OAuth\Common\Http\Uri\Uri; 17 use OAuth\Common\Http\Uri\UriInterface; 18 use OAuth\Common\Storage\TokenStorageInterface; 19 use OAuth\OAuth1\Signature\SignatureInterface; 20 use OAuth\OAuth1\Token\StdOAuth1Token; 21 22 /** 23 * 500px service. 24 * 25 * @author Pedro Amorim <contact@pamorim.fr> 26 * @license http://www.opensource.org/licenses/mit-license.html MIT License 27 * 28 * @see https://developers.500px.com/ 29 */ 30 class FiveHundredPx extends AbstractService 31 { 32 public function __construct( 33 CredentialsInterface $credentials, 34 ClientInterface $httpClient, 35 TokenStorageInterface $storage, 36 SignatureInterface $signature, 37 ?UriInterface $baseApiUri = null 38 ) { 39 parent::__construct( 40 $credentials, 41 $httpClient, 42 $storage, 43 $signature, 44 $baseApiUri 45 ); 46 47 if (null === $baseApiUri) { 48 $this->baseApiUri = new Uri('https://api.500px.com/v1/'); 49 } 50 } 51 52 /** 53 * {@inheritdoc} 54 */ 55 public function getRequestTokenEndpoint() 56 { 57 return new Uri('https://api.500px.com/v1/oauth/request_token'); 58 } 59 60 /** 61 * {@inheritdoc} 62 */ 63 public function getAuthorizationEndpoint() 64 { 65 return new Uri('https://api.500px.com/v1/oauth/authorize'); 66 } 67 68 /** 69 * {@inheritdoc} 70 */ 71 public function getAccessTokenEndpoint() 72 { 73 return new Uri('https://api.500px.com/v1/oauth/access_token'); 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 protected function parseRequestTokenResponse($responseBody) 80 { 81 parse_str($responseBody, $data); 82 83 if (null === $data || !is_array($data)) { 84 throw new TokenResponseException('Unable to parse response.'); 85 } elseif (!isset($data['oauth_callback_confirmed']) 86 || $data['oauth_callback_confirmed'] !== 'true' 87 ) { 88 throw new TokenResponseException('Error in retrieving token.'); 89 } 90 91 return $this->parseAccessTokenResponse($responseBody); 92 } 93 94 /** 95 * {@inheritdoc} 96 */ 97 protected function parseAccessTokenResponse($responseBody) 98 { 99 parse_str($responseBody, $data); 100 101 if (null === $data || !is_array($data)) { 102 throw new TokenResponseException('Unable to parse response.'); 103 } elseif (isset($data['error'])) { 104 throw new TokenResponseException( 105 'Error in retrieving token: "' . $data['error'] . '"' 106 ); 107 } 108 109 $token = new StdOAuth1Token(); 110 111 $token->setRequestToken($data['oauth_token']); 112 $token->setRequestTokenSecret($data['oauth_token_secret']); 113 $token->setAccessToken($data['oauth_token']); 114 $token->setAccessTokenSecret($data['oauth_token_secret']); 115 116 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); 117 unset($data['oauth_token'], $data['oauth_token_secret']); 118 $token->setExtraParams($data); 119 120 return $token; 121 } 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |