[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Nest 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://developer.nest.com/documentation 9 */ 10 11 namespace OAuth\OAuth2\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\OAuth2\Token\StdOAuth2Token; 20 21 /** 22 * Nest service. 23 * 24 * @author Pedro Amorim <contact@pamorim.fr> 25 * @license http://www.opensource.org/licenses/mit-license.html MIT License 26 * 27 * @see https://developer.nest.com/documentation 28 */ 29 class Nest extends AbstractService 30 { 31 public function __construct( 32 CredentialsInterface $credentials, 33 ClientInterface $httpClient, 34 TokenStorageInterface $storage, 35 $scopes = [], 36 ?UriInterface $baseApiUri = null 37 ) { 38 parent::__construct( 39 $credentials, 40 $httpClient, 41 $storage, 42 $scopes, 43 $baseApiUri, 44 true 45 ); 46 47 if (null === $baseApiUri) { 48 $this->baseApiUri = new Uri('https://developer-api.nest.com/'); 49 } 50 } 51 52 /** 53 * {@inheritdoc} 54 */ 55 public function getAuthorizationEndpoint() 56 { 57 return new Uri('https://home.nest.com/login/oauth2'); 58 } 59 60 /** 61 * {@inheritdoc} 62 */ 63 public function getAccessTokenEndpoint() 64 { 65 return new Uri('https://api.home.nest.com/oauth2/access_token'); 66 } 67 68 /** 69 * {@inheritdoc} 70 */ 71 protected function getAuthorizationMethod() 72 { 73 return static::AUTHORIZATION_METHOD_QUERY_STRING_V4; 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 protected function parseAccessTokenResponse($responseBody) 80 { 81 $data = json_decode($responseBody, true); 82 83 if (null === $data || !is_array($data)) { 84 throw new TokenResponseException('Unable to parse response.'); 85 } elseif (isset($data['error'])) { 86 throw new TokenResponseException( 87 'Error in retrieving token: "' . $data['error'] . '"' 88 ); 89 } 90 91 $token = new StdOAuth2Token(); 92 $token->setAccessToken($data['access_token']); 93 $token->setLifeTime($data['expires_in']); 94 95 if (isset($data['refresh_token'])) { 96 $token->setRefreshToken($data['refresh_token']); 97 unset($data['refresh_token']); 98 } 99 100 unset($data['access_token'], $data['expires_in']); 101 102 $token->setExtraParams($data); 103 104 return $token; 105 } 106 }
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 |