1 | <?php |
||
30 | class OAuthClient extends AbstractServiceClient |
||
31 | { |
||
32 | /* |
||
33 | * Authentication types constants |
||
34 | * |
||
35 | * The "code" type means that the application will use an intermediate code to obtain an access token. |
||
36 | * The "token" type will result a user is redirected back to the application with an access token in a URL |
||
37 | */ |
||
38 | const CODE_AUTH_TYPE = 'code'; |
||
39 | const TOKEN_AUTH_TYPE = 'token'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $clientId = ''; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $clientSecret = ''; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $serviceDomain = 'oauth.yandex.ru'; |
||
55 | |||
56 | /** |
||
57 | * @param string $clientId |
||
58 | * @param string $clientSecret |
||
59 | */ |
||
60 | 24 | public function __construct($clientId = '', $clientSecret = '') |
|
65 | |||
66 | /** |
||
67 | * @param string $clientId |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | 24 | public function setClientId($clientId) |
|
77 | |||
78 | /** |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function getClientId() |
|
82 | { |
||
83 | 2 | return $this->clientId; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param string $clientSecret |
||
88 | * |
||
89 | * @return self |
||
90 | */ |
||
91 | 24 | public function setClientSecret($clientSecret) |
|
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | 2 | public function getClientSecret() |
|
105 | |||
106 | /** |
||
107 | * @param string $type |
||
108 | * @param string $state optional string |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 2 | public function getAuthUrl($type = self::CODE_AUTH_TYPE, $state = null) |
|
121 | |||
122 | /** |
||
123 | * Sends a redirect to the Yandex authentication page. |
||
124 | * |
||
125 | * @param bool $exit indicates whether to stop the PHP script immediately or not |
||
126 | * @param string $type a type of the authentication procedure |
||
127 | * @param string $state optional string |
||
128 | * @return bool|void |
||
129 | */ |
||
130 | 1 | public function authRedirect($exit = true, $type = self::CODE_AUTH_TYPE, $state = null) |
|
136 | |||
137 | /** |
||
138 | * Exchanges a temporary code for an access token. |
||
139 | * |
||
140 | * @param $code |
||
141 | * |
||
142 | * @throws AuthRequestException on a known request error |
||
143 | * @throws AuthResponseException on a response format error |
||
144 | * @throws RequestException on an unknown request error |
||
145 | * |
||
146 | * @return self |
||
147 | */ |
||
148 | 6 | public function requestAccessToken($code) |
|
204 | } |
||
205 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: