-
Notifications
You must be signed in to change notification settings - Fork 1
Class GSecrets
Full name: \SKien\Google\GSecrets
Helper class for the maintenance of the oauth client data and tokens.
Note:
This class ofers the functionality to save tokens in files on the server. This 'mode' was implemented for development purposes:
- for easier read the tokens returned by the google API
- to work on a local development environment where the development server is NOT the localhost but the redirectURI also is not accessible from outside. In that case, only the login have to be made directly on the machine where the webserver runs - all subsequent calls to the API uses the tokens from the files created after the oauth-login has called the redirectURI.
For of security issues DO NOT USE THIS MODE for public environments!!!
| Constant | Description |
|---|---|
TOKEN_COOKIE |
refreshtoken are saved in cookies |
TOKEN_FILE |
refreshtoken are saved in files on the server |
| Method | Description |
|---|---|
| __construct | Create an instance of the class. |
| getAccessToken | Gets the last saved accesToken. |
| getClientSecrets | Get full path and filename of the oauth client configuration file. |
| getRefreshToken | Gets the last saved refreshToken. |
| logout | Logout from the google account. |
| saveAccessToken | Save accessToken. |
| saveRefreshToken | Save the refreshToken. |
| setSecretsFilename | Sets the filename of the google oauth client configuration file. |
| setSecretsPath | Set the path where the secrets- and token files are located. |
Create an instance of the class.
public GSecrets::__construct(int $iKeepLoggedIn, int $iSaveTokensAt = self::TOKEN_COOKIE)DO NOT USE $iSaveTokensAt = self::TOKEN_FILE IN PUBLIC ENVIRONMENT
In 'self::TOKEN_FILE - Mode' the $iKeepLoggedIn param is ignored since the tokens
saved in files that never expires unless they are deleted manually...
Parameters:
| Parameter | Type | Description |
|---|---|---|
iKeepLoggedIn |
int | 0 (default) -> session only, -1 -> 'forever', other value -> days to keep the login |
iSaveTokensAt |
int |
self::TOKEN_COOKIE (default) or self::TOKEN_FILE
|
Gets the last saved accesToken.
public GSecrets::getAccessToken() : arrayReturn Type: array
Get full path and filename of the oauth client configuration file.
public GSecrets::getClientSecrets() : stringReturn Type: string
Gets the last saved refreshToken.
public GSecrets::getRefreshToken() : stringReturn Type: string
Logout from the google account.
public GSecrets::logout() : voidDeletes a saved access- and refreshToken.
Save accessToken.
public GSecrets::saveAccessToken(array $aToken) : voidParameters:
| Parameter | Type | Description |
|---|---|---|
aToken |
array |
Save the refreshToken.
public GSecrets::saveRefreshToken(string $strRefreshToken) : voidParameters:
| Parameter | Type | Description |
|---|---|---|
strRefreshToken |
string |
Sets the filename of the google oauth client configuration file.
public GSecrets::setSecretsFilename(string $strSecretsFilename) : voidParameters:
| Parameter | Type | Description |
|---|---|---|
strSecretsFilename |
string |
Set the path where the secrets- and token files are located.
public GSecrets::setSecretsPath(string $strSecretsPath) : voidThe directory must not be write-protected and should be protected
agains access from outside (.htacces: deny from all).
Parameters:
| Parameter | Type | Description |
|---|---|---|
strSecretsPath |
string |
build with phpDocumentor 3 using template phpdoc2githubwiki / (2023-04-26)