Skip to content

Class GSecrets

Stefan Kientzler edited this page Apr 26, 2023 · 5 revisions

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!!!

Constants

Constant Description
TOKEN_COOKIE refreshtoken are saved in cookies
TOKEN_FILE refreshtoken are saved in files on the server

Overview

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.

Methods

__construct

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

[go to top]


getAccessToken

Gets the last saved accesToken.

public GSecrets::getAccessToken() : array

Return Type: array

[go to top]


getClientSecrets

Get full path and filename of the oauth client configuration file.

public GSecrets::getClientSecrets() : string

Return Type: string

[go to top]


getRefreshToken

Gets the last saved refreshToken.

public GSecrets::getRefreshToken() : string

Return Type: string

[go to top]


logout

Logout from the google account.

public GSecrets::logout() : void

Deletes a saved access- and refreshToken.

[go to top]


saveAccessToken

Save accessToken.

public GSecrets::saveAccessToken(array $aToken) : void

Parameters:

Parameter Type Description
aToken array

[go to top]


saveRefreshToken

Save the refreshToken.

public GSecrets::saveRefreshToken(string $strRefreshToken) : void

Parameters:

Parameter Type Description
strRefreshToken string

[go to top]


setSecretsFilename

Sets the filename of the google oauth client configuration file.

public GSecrets::setSecretsFilename(string $strSecretsFilename) : void

Parameters:

Parameter Type Description
strSecretsFilename string

[go to top]


setSecretsPath

Set the path where the secrets- and token files are located.

public GSecrets::setSecretsPath(string $strSecretsPath) : void

The directory must not be write-protected and should be protected agains access from outside (.htacces: deny from all).

Parameters:

Parameter Type Description
strSecretsPath string

[go to top]


Clone this wiki locally