Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FitBit.php
01 <?php
02 namespace OAuth\OAuth1\Service;
03
04 use OAuth\OAuth1\Signature\SignatureInterface;
05 use OAuth\OAuth1\Token\StdOAuth1Token;
06 use OAuth\Common\Http\Exception\TokenResponseException;
07 use OAuth\Common\Http\Uri\Uri;
08 use OAuth\Common\Consumer\Credentials;
09 use OAuth\Common\Http\Uri\UriInterface;
10 use OAuth\Common\Storage\TokenStorageInterface;
11 use OAuth\Common\Http\Client\ClientInterface;
12
13 class FitBit extends AbstractService
14 {
15 public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, SignatureInterface $signature, UriInterface $baseApiUri = null)
16 {
17 parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
18 if( null === $baseApiUri ) {
19 $this->baseApiUri = new Uri('https://api.fitbit.com/1/');
20 }
21 }
22
23 /**
24 * @return \OAuth\Common\Http\Uri\UriInterface
25 */
26 public function getRequestTokenEndpoint()
27 {
28 return new Uri('https://api.fitbit.com/oauth/request_token');
29 }
30
31 /**
32 * @return \OAuth\Common\Http\Uri\UriInterface
33 */
34 public function getAuthorizationEndpoint()
35 {
36 return new Uri('https://www.fitbit.com/oauth/authorize');
37 }
38
39 /**
40 * @return \OAuth\Common\Http\Uri\UriInterface
41 */
42 public function getAccessTokenEndpoint()
43 {
44 return new Uri('https://api.fitbit.com/oauth/access_token');
45 }
46
47 /**
48 * We need a separate request token parser only to verify the `oauth_callback_confirmed` parameter. For the actual
49 * parsing we can just use the default access token parser.
50 *
51 * @param string $responseBody
52 * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth1\Token\StdOAuth1Token
53 * @throws \OAuth\Common\Http\Exception\TokenResponseException
54 */
55 protected function parseRequestTokenResponse($responseBody)
56 {
57 parse_str($responseBody, $data);
58
59 if( null === $data || !is_array($data) ) {
60 throw new TokenResponseException('Unable to parse response.');
61 } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') {
62 throw new TokenResponseException('Error in retrieving token.');
63 }
64
65 return $this->parseAccessTokenResponse($responseBody);
66 }
67
68 /**
69 * @param string $responseBody
70 * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth1\Token\StdOAuth1Token
71 * @throws \OAuth\Common\Http\Exception\TokenResponseException
72 */
73 protected function parseAccessTokenResponse($responseBody)
74 {
75 parse_str($responseBody, $data);
76
77 if( null === $data || !is_array($data) ) {
78 throw new TokenResponseException('Unable to parse response.');
79 } elseif( isset($data['error'] ) ) {
80 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
81 }
82
83 $token = new StdOAuth1Token();
84
85 $token->setRequestToken( $data['oauth_token'] );
86 $token->setRequestTokenSecret( $data['oauth_token_secret'] );
87 $token->setAccessToken( $data['oauth_token'] );
88 $token->setAccessTokenSecret( $data['oauth_token_secret'] );
89
90 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
91 unset( $data['oauth_token'], $data['oauth_token_secret'] );
92 $token->setExtraParams( $data );
93
94 return $token;
95 }
96 }
97