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