Просмотр исходного кода

Merge branch 'master' of https://github.com/unaio/una

AntonLV 8 лет назад
Родитель
Сommit
4492168e25

+ 3 - 1
inc/classes/BxDolPush.php

@@ -59,7 +59,9 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
 			'contents' => !empty($aMessage['contents']) && is_array($aMessage['contents']) ? $aMessage['contents'] : array(),
 			'headings' => !empty($aMessage['headings']) && is_array($aMessage['headings']) ? $aMessage['headings'] : array(),
 			'url' => !empty($aMessage['url']) ? $aMessage['url'] : '',
-			'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : ''
+            'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : '',
+            'ios_badgeType' => 'Increase',
+            'ios_badgeCount' => 1,
 		);
 
 		$oChannel = curl_init();

+ 116 - 0
plugins/OAuth/OAuth2/Service/BattleNet.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace OAuth\OAuth2\Service;
+
+//-----------------------------------------------------------------------------
+use OAuth\OAuth2\Token\StdOAuth2Token;
+use OAuth\Common\Http\Exception\TokenResponseException;
+use OAuth\Common\Http\Uri\Uri;
+use OAuth\Common\Consumer\CredentialsInterface;
+use OAuth\Common\Http\Client\ClientInterface;
+use OAuth\Common\Storage\TokenStorageInterface;
+use OAuth\Common\Http\Uri\UriInterface;
+
+//-----------------------------------------------------------------------------
+class BattleNet extends AbstractService { 
+    
+    /** -----------------------------------------------------------------------
+     * Defined scopes.
+     *
+     * @link https://dev.battle.net/docs
+     */
+    const SCOPE_WOW_PROFILE = "wow.profile";
+    const SCOPE_SC2_PROFILE = "sc2.profile";
+    
+    /** -----------------------------------------------------------------------
+     * Defined API URIs.
+     *
+     * @link https://dev.battle.net/docs
+     */
+    const API_URI_US  = 'https://us.api.battle.net/';
+    const API_URI_EU  = 'https://eu.api.battle.net/';
+    const API_URI_KR  = 'https://kr.api.battle.net/';
+    const API_URI_TW  = 'https://tw.api.battle.net/';
+    const API_URI_CN  = 'https://api.battlenet.com.cn/';
+    const API_URI_SEA = 'https://sea.api.battle.net/';
+    
+    public function __construct( CredentialsInterface $credentials,
+                                 ClientInterface $httpClient,
+                                 TokenStorageInterface $storage,
+                                 $scopes = array(),
+                                 UriInterface $baseApiUri = null ) {
+                                 
+        parent::__construct( $credentials, $httpClient, $storage, 
+                             $scopes, $baseApiUri );
+        
+        if( $baseApiUri === null ) {
+            $this->baseApiUri = new Uri( self::API_URI_US );
+        }
+    }
+    
+    /** -----------------------------------------------------------------------
+     * Translates the current base API URI into an OAuth base URI. 
+     *
+     * @returns string Base URI of oauth services.
+     */
+    private function GetOAuthBaseUri() {
+    
+        // i love china
+        switch( $this->baseApiUri ) {
+            case self::API_URI_US:  return 'https://us.battle.net/oauth/';
+            case self::API_URI_EU:  return 'https://eu.battle.net/oauth/';
+            case self::API_URI_KR:  return 'https://kr.battle.net/oauth/';
+            case self::API_URI_TW:  return 'https://tw.battle.net/oauth/';
+            case self::API_URI_CN:  return 'https://www.battlenet.com.cn/oauth/';
+            case self::API_URI_SEA: return 'https://sea.battle.net/oauth/'; 
+        }
+        
+    }
+    
+    /** -----------------------------------------------------------------------
+     * {@inheritdoc}
+     */
+    public function getAuthorizationEndpoint() {
+        return new Uri( $this->GetOAuthBaseUri() . 'authorize' );
+    }
+    
+    /** -----------------------------------------------------------------------
+     * {@inheritdoc}
+     */
+    public function getAccessTokenEndpoint() {
+        return new Uri( $this->GetOAuthBaseUri() . 'token' );
+    }
+    
+    /** -----------------------------------------------------------------------
+     * {@inheritdoc}
+     */
+    protected function getAuthorizationMethod()
+    {
+        return static::AUTHORIZATION_METHOD_QUERY_STRING;
+    }
+    
+    /** -----------------------------------------------------------------------
+     * {@inheritdoc}
+     */
+    protected function parseAccessTokenResponse( $responseBody )
+    {
+        $data = json_decode($responseBody, true);
+        if( $data === null || !is_array($data) ) {
+            throw new TokenResponseException( 'Unable to parse response.' );
+        } elseif( isset($data['error']) ) {
+            $err = $data['error'];
+            throw new TokenResponseException( 
+                                "Error in retrieving token: \"$err\"" );
+        }
+        
+        $token = new StdOAuth2Token( $data['access_token'], null, 
+                                     $data['expires_in'] );
+        
+        unset( $data['access_token'] );
+        unset( $data['expires_in'] );
+        
+        $token->setExtraParams( $data );
+        
+        return $token;
+    }
+}

+ 8 - 0
plugins/OAuth/OAuth2/Service/Bitrix24.php

@@ -39,6 +39,14 @@ class Bitrix24 extends AbstractService
         return new Uri(sprintf('%s/oauth/token/', $this->baseApiUri));
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    protected function getAuthorizationMethod()
+    {
+        return static::AUTHORIZATION_METHOD_QUERY_STRING_V4;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
plugins/OAuth/OAuth2/Service/Buffer.php

@@ -108,7 +108,7 @@ class Buffer extends AbstractService
         return $data['code'];
     }
 
-    public function requestAccessToken($code)
+    public function requestAccessToken($code, $state = null)
     {
         $bodyParams = array(
             'client_id'     => $this->credentials->getConsumerId(),

+ 6 - 2
plugins/OAuth/OAuth2/Service/Facebook.php

@@ -158,8 +158,12 @@ class Facebook extends AbstractService
      */
     protected function parseAccessTokenResponse($responseBody)
     {
-        // Facebook gives us a query string ... Oh wait. JSON is too simple, understand ?
-        parse_str($responseBody, $data);
+        $data = @json_decode($responseBody, true);
+
+        // Facebook gives us a query string on old api (v2.0)
+        if (!$data) {
+            parse_str($responseBody, $data);
+        }
 
         if (null === $data || !is_array($data)) {
             throw new TokenResponseException('Unable to parse response.');

+ 3 - 1
plugins/OAuth/OAuth2/Service/Google.php

@@ -35,6 +35,7 @@ class Google extends AbstractService
     const SCOPE_GPLUS_STREAM_READ           = 'https://www.googleapis.com/auth/plus.stream.read';
     const SCOPE_GPLUS_STREAM_WRITE          = 'https://www.googleapis.com/auth/plus.stream.write';
     const SCOPE_GPLUS_MEDIA                 = 'https://www.googleapis.com/auth/plus.media.upload';
+    const SCOPE_EMAIL_PLUS                  = 'https://www.googleapis.com/auth/plus.profile.emails.read';
 
     // Google Drive
     const SCOPE_DOCUMENTSLIST               = 'https://docs.google.com/feeds/';
@@ -49,7 +50,8 @@ class Google extends AbstractService
 
     // Adwords
     const SCOPE_ADSENSE                     = 'https://www.googleapis.com/auth/adsense';
-    const SCOPE_ADWORDS                     = 'https://www.googleapis.com/auth/adwords/';
+    const SCOPE_ADWORDS                     = 'https://www.googleapis.com/auth/adwords';
+    const SCOPE_ADWORDS_DEPRECATED          = 'https://www.googleapis.com/auth/adwords/'; //deprecated in v201406 API version
     const SCOPE_GAN                         = 'https://www.googleapis.com/auth/gan'; // google affiliate network...?
 
     //Doubleclick for Publishers

+ 86 - 0
plugins/OAuth/OAuth2/Service/Mondo.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace OAuth\OAuth2\Service;
+
+use OAuth\OAuth2\Token\StdOAuth2Token;
+use OAuth\Common\Http\Exception\TokenResponseException;
+use OAuth\Common\Http\Uri\Uri;
+use OAuth\Common\Consumer\CredentialsInterface;
+use OAuth\Common\Http\Client\ClientInterface;
+use OAuth\Common\Storage\TokenStorageInterface;
+use OAuth\Common\Http\Uri\UriInterface;
+
+class Mondo extends AbstractService
+{
+    public function __construct(
+        CredentialsInterface $credentials,
+        ClientInterface $httpClient,
+        TokenStorageInterface $storage,
+        $scopes = array(),
+        UriInterface $baseApiUri = null
+    ) {
+        parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
+
+        if (null === $baseApiUri) {
+            $this->baseApiUri = new Uri('https://api.getmondo.co.uk');
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getAuthorizationEndpoint()
+    {
+        return new Uri('https://auth.getmondo.co.uk');
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getAccessTokenEndpoint()
+    {
+        return new Uri('https://api.getmondo.co.uk/oauth2/token');
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function getAuthorizationMethod()
+    {
+        return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function parseAccessTokenResponse($responseBody)
+    {
+        $data = json_decode($responseBody, true);
+
+        if (null === $data || !is_array($data)) {
+            throw new TokenResponseException('Unable to parse response.');
+        } elseif (isset($data['error'])) {
+            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+        }
+
+
+        $token = new StdOAuth2Token();
+        $token->setAccessToken($data['access_token']);
+
+        if (isset($data['expires_in'])) {
+            $token->setLifetime($data['expires_in']);
+            unset($data['expires_in']);
+        }
+
+        if (isset($data['refresh_token'])) {
+            $token->setRefreshToken($data['refresh_token']);
+            unset($data['refresh_token']);
+        }
+
+        unset($data['access_token']);
+
+        $token->setExtraParams($data);
+
+        return $token;
+    }
+}

+ 1 - 1
plugins/OAuth/OAuth2/Service/Pocket.php

@@ -85,7 +85,7 @@ class Pocket extends AbstractService
         return $data['code'];
     }
     
-    public function requestAccessToken($code)
+    public function requestAccessToken($code, $state = null)
     {
         $bodyParams = array(
             'consumer_key'     => $this->credentials->getConsumerId(),

+ 1 - 1
plugins/OAuth/OAuth2/Service/Salesforce.php

@@ -34,7 +34,7 @@ class Salesforce extends AbstractService
      */
     public function getAccessTokenEndpoint()
     {
-        return new Uri('https://na1.salesforce.com/services/oauth2/token');
+        return new Uri('https://login.salesforce.com/services/oauth2/token');
     }
 
     /**

+ 2 - 1
plugins/OAuth/OAuth2/Service/ServiceInterface.php

@@ -29,10 +29,11 @@ interface ServiceInterface extends BaseServiceInterface
      * Retrieves and stores/returns the OAuth2 access token after a successful authorization.
      *
      * @param string $code The access code from the callback.
+     * @param string $state
      *
      * @return TokenInterface $token
      *
      * @throws TokenResponseException
      */
-    public function requestAccessToken($code);
+    public function requestAccessToken($code, $state = null);
 }