zend-blog-3-backend

Форк
0
/
DropboxProvider.php 
125 строк · 3.1 Кб
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: morontt
5
 * Date: 05.10.17
6
 * Time: 22:55
7
 */
8

9
namespace App\OAuth2\Client;
10

11
use League\OAuth2\Client\Provider\AbstractProvider;
12
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
13
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
14
use League\OAuth2\Client\Token\AccessToken;
15
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
16
use Psr\Http\Message\ResponseInterface;
17

18
class DropboxProvider extends AbstractProvider
19
{
20
    use BearerAuthorizationTrait;
21

22
    /**
23
     * @var string Key used in the access token response to identify the resource owner
24
     */
25
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'account_id';
26

27
    /**
28
     * Returns the base URL for authorizing a client.
29
     *
30
     * Eg. https://oauth.service.com/authorize
31
     *
32
     * @return string
33
     */
34
    public function getBaseAuthorizationUrl()
35
    {
36
        return 'https://api.dropbox.com/oauth2/authorize';
37
    }
38

39
    /**
40
     * Returns the base URL for requesting an access token.
41
     *
42
     * Eg. https://oauth.service.com/token
43
     *
44
     * @param array $params
45
     *
46
     * @return string
47
     */
48
    public function getBaseAccessTokenUrl(array $params)
49
    {
50
        return 'https://api.dropbox.com/oauth2/token';
51
    }
52

53
    /**
54
     * Returns the URL for requesting the resource owner's details.
55
     *
56
     * @param AccessToken $token
57
     *
58
     * @return string
59
     */
60
    public function getResourceOwnerDetailsUrl(AccessToken $token)
61
    {
62
        return 'https://api.dropbox.com/2/users/get_current_account';
63
    }
64

65
    /**
66
     * Builds the authorization URL.
67
     *
68
     * @param  array $options
69
     *
70
     * @return string Authorization URL
71
     */
72
    public function getAuthorizationUrl(array $options = [])
73
    {
74
        return parent::getAuthorizationUrl(
75
            array_merge(
76
                [
77
                    'approval_prompt' => [],
78
                ],
79
                $options
80
            )
81
        );
82
    }
83

84
    /**
85
     * Returns the default scopes used by this provider.
86
     *
87
     * This should only be the scopes that are required to request the details
88
     * of the resource owner, rather than all the available scopes.
89
     *
90
     * @return array
91
     */
92
    protected function getDefaultScopes()
93
    {
94
        return [];
95
    }
96

97
    /**
98
     * Checks a provider response for errors.
99
     *
100
     * @param  ResponseInterface $response
101
     * @param  array|string $data Parsed response data
102
     *
103
     * @throws IdentityProviderException
104
     */
105
    protected function checkResponse(ResponseInterface $response, $data)
106
    {
107
        if (isset($data['error'])) {
108
            throw new IdentityProviderException($data['error'] ?: $response->getReasonPhrase(), $response->getStatusCode(), $response);
109
        }
110
    }
111

112
    /**
113
     * Generates a resource owner object from a successful resource owner
114
     * details request.
115
     *
116
     * @param  array $response
117
     * @param  AccessToken $token
118
     *
119
     * @return ResourceOwnerInterface
120
     */
121
    protected function createResourceOwner(array $response, AccessToken $token)
122
    {
123
        return new DropboxResourceOwner($response);
124
    }
125
}
126

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.