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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Bitly.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.44 KiB


 001  <?php
 002  namespace OAuth\OAuth2\Service;
 003   
 004  use OAuth\OAuth2\Token\StdOAuth2Token;
 005  use OAuth\Common\Http\Exception\TokenResponseException;
 006  use OAuth\Common\Http\Uri\Uri;
 007  use OAuth\Common\Consumer\Credentials;
 008  use OAuth\Common\Http\Client\ClientInterface;
 009  use OAuth\Common\Storage\TokenStorageInterface;
 010  use OAuth\Common\Http\Uri\UriInterface;
 011   
 012  class Bitly extends AbstractService
 013  {
 014      public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
 015      {
 016          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
 017          if( null === $baseApiUri ) {
 018              $this->baseApiUri = new Uri('https://api-ssl.bitly.com/v3/');
 019          }
 020      }
 021   
 022      /**
 023       * @return \OAuth\Common\Http\Uri\UriInterface
 024       */
 025      public function getAuthorizationEndpoint()
 026      {
 027          return new Uri('https://bitly.com/oauth/authorize');
 028      }
 029   
 030      /**
 031       * @return \OAuth\Common\Http\Uri\UriInterface
 032       */
 033      public function getAccessTokenEndpoint()
 034      {
 035          return new Uri('https://api-ssl.bitly.com/oauth/access_token');
 036      }
 037   
 038      /**
 039       * @param string $responseBody
 040       * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
 041       * @throws \OAuth\Common\Http\Exception\TokenResponseException
 042       */
 043      protected function parseAccessTokenResponse($responseBody)
 044      {
 045          $data = json_decode( $responseBody, true );
 046   
 047          if( null === $data || !is_array($data) ) {
 048              throw new TokenResponseException('Unable to parse response.');
 049          } elseif( isset($data['error'] ) ) {
 050              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 051          }
 052   
 053          $token = new StdOAuth2Token();
 054   
 055   
 056          $token->setAccessToken( $data['access_token'] );
 057          // I'm invincible!!!
 058          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
 059          unset( $data['access_token'] );
 060          $token->setExtraParams( $data );
 061   
 062          return $token;
 063      }
 064   
 065      /**
 066       * Retrieves and stores the OAuth2 access token after a successful authorization.
 067       *
 068       * @param string $code The access code from the callback.
 069       * @return \OAuth\OAuth2\Token\TokenInterface $token
 070       * @throws TokenResponseException
 071       */
 072      public function requestAccessToken($code)
 073      {
 074          $bodyParams = array(
 075              'code'          => $code,
 076              'client_id'     => $this->credentials->getConsumerId(),
 077              'client_secret' => $this->credentials->getConsumerSecret(),
 078              'redirect_uri'  => $this->credentials->getCallbackUrl(),
 079              'grant_type'    => 'authorization_code',
 080          );
 081   
 082          $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $this->getExtraOAuthHeaders());
 083   
 084          // we can scream what we want that we want bitly to return a json encoded string (format=json), but the
 085          // WOAH WATCH YOUR LANGUAGE ;) service doesn't seem to like screaming, hence we need to manually parse the result
 086          $parsedResult = array();
 087          parse_str($responseBody, $parsedResult);
 088   
 089          $token = $this->parseAccessTokenResponse( json_encode($parsedResult) );
 090          $this->storage->storeAccessToken( $this->service(), $token );
 091   
 092          return $token;
 093      }
 094   
 095      /**
 096       * @return int
 097       */
 098      protected function getAuthorizationMethod()
 099      {
 100          return static::AUTHORIZATION_METHOD_QUERY_STRING;
 101      }
 102  }
 103