1 | <?php |
||
30 | class WebServerApplication extends Client { |
||
31 | /** |
||
32 | * Response type constants |
||
33 | */ |
||
34 | const RESPONSE_TYPE_CODE = 'code'; |
||
35 | |||
36 | /** |
||
37 | * Access type constants |
||
38 | */ |
||
39 | const ACCESS_TYPE_ONLINE = 'online', |
||
40 | ACCESS_TYPE_OFFLINE = 'offline'; |
||
41 | |||
42 | /** |
||
43 | * Approval constants |
||
44 | */ |
||
45 | const APPROVAL_PROMPT_AUTO = 'auto', |
||
46 | APPROVAL_PROMPT_FORCE = 'force'; |
||
47 | |||
48 | /** |
||
49 | * Grant type constants |
||
50 | */ |
||
51 | const GRANT_TYPE_AUTHORIZATION = 'authorization_code', |
||
52 | GRANT_TYPE_REFRESH = 'refresh_token'; |
||
53 | |||
54 | /** |
||
55 | * Google Api endpoints |
||
56 | */ |
||
57 | const ENDPOINT_INITIAL_REQUEST = 'https://accounts.google.com/o/oauth2/auth', |
||
58 | ENDPOINT_ACCESS_TOKEN_REQUEST = 'https://accounts.google.com/o/oauth2/token', |
||
59 | ENDPOINT_REVOKE_TOKEN = 'https://accounts.google.com/o/oauth2/revoke'; |
||
60 | |||
61 | /** |
||
62 | * @var Token access token |
||
63 | */ |
||
64 | private $Token = null; |
||
65 | |||
66 | /** |
||
67 | * Setter for token value |
||
68 | * @param Token $Token token object |
||
69 | * @return Client self |
||
70 | */ |
||
71 | 1 | public function setToken(Token $Token) { |
|
76 | |||
77 | /** |
||
78 | * Getter for token |
||
79 | * @return Token access token value |
||
80 | */ |
||
81 | 2 | public function getToken() { |
|
84 | |||
85 | /** |
||
86 | * Method for create authorization url |
||
87 | * @param string[] $scopes set of permissions |
||
88 | * @param string $state something state |
||
89 | * @param string $responseType type of the response |
||
90 | * @param string $accessType type of the access. Online or offline |
||
91 | * @param string $approvalPrompt type of re-prompted user consent |
||
92 | * @return string url string for user authorization |
||
93 | */ |
||
94 | 1 | public function createAuthUrl(array $scopes, $state = '', $responseType = self::RESPONSE_TYPE_CODE, $accessType = self::ACCESS_TYPE_ONLINE, $approvalPrompt = self::APPROVAL_PROMPT_AUTO, $loginHint = '') { |
|
111 | |||
112 | /** |
||
113 | * Get access token by user authorization code |
||
114 | * @param string $code user authorization code |
||
115 | * @return Error|Token Google Api response object |
||
116 | */ |
||
117 | public function authorizeByCode($code) { |
||
132 | |||
133 | /** |
||
134 | * Get access by refresh token |
||
135 | * @param string $refreshToken refresh token |
||
136 | * @return Error|Token Google Api response object |
||
137 | */ |
||
138 | public function refresh($refreshToken) { |
||
152 | |||
153 | /** |
||
154 | * Revoke access or refresh token |
||
155 | * If the token is an access token and it has a corresponding refresh token, the refresh token will also be revoked |
||
156 | * @param string $token user access or refresh token |
||
157 | * @return bool revoke token result |
||
158 | */ |
||
159 | public function revoke($token) { |
||
169 | } |
||
170 |