Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 and 403]

(no description)

File Size: 715 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Google_Client  - X-Ref

The Google API Client
https://github.com/google/google-api-php-client

__construct($config = null)   X-Ref
Construct the Google Client.

param: $config Google_Config or string for the ini file to load

getLibraryVersion()   X-Ref
Get a string containing the version of the library.

return: string

authenticate($code, $crossClient = false)   X-Ref
Attempt to exchange a code for an valid authentication token.
If $crossClient is set to true, the request body will not include
the request_uri argument
Helper wrapped around the OAuth 2.0 implementation.

param: $code string code from accounts.google.com
param: $crossClient boolean, whether this is a cross-client authentication
return: string token

loadServiceAccountJson($jsonLocation, $scopes)   X-Ref
Loads a service account key and parameters from a JSON
file from the Google Developer Console. Uses that and the
given array of scopes to return an assertion credential for
use with refreshTokenWithAssertionCredential.

param: string $jsonLocation File location of the project-key.json.
param: array $scopes The scopes to assert.
return: Google_Auth_AssertionCredentials.

setAuthConfig($json)   X-Ref
Set the auth config from the JSON string provided.
This structure should match the file downloaded from
the "Download JSON" button on in the Google Developer
Console.

param: string $json the configuration json

setAuthConfigFile($file)   X-Ref
Set the auth config from the JSON file in the path
provided. This should match the file downloaded from
the "Download JSON" button on in the Google Developer
Console.

param: string $file the file location of the client json

prepareScopes()   X-Ref

return: array

setAccessToken($accessToken)   X-Ref
Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl()
or Google_Client#getAccessToken().

param: string $accessToken JSON encoded string containing in the following format:

setAuth(Google_Auth_Abstract $auth)   X-Ref
Set the authenticator object

param: Google_Auth_Abstract $auth

setIo(Google_IO_Abstract $io)   X-Ref
Set the IO object

param: Google_IO_Abstract $io

setCache(Google_Cache_Abstract $cache)   X-Ref
Set the Cache object

param: Google_Cache_Abstract $cache

setLogger(Google_Logger_Abstract $logger)   X-Ref
Set the Logger object

param: Google_Logger_Abstract $logger

createAuthUrl()   X-Ref
Construct the OAuth 2.0 authorization request URI.

return: string

getAccessToken()   X-Ref
Get the OAuth 2.0 access token.

return: string $accessToken JSON encoded string in the following format:

getRefreshToken()   X-Ref
Get the OAuth 2.0 refresh token.

return: string $refreshToken refresh token or null if not available

isAccessTokenExpired()   X-Ref
Returns if the access_token is expired.

return: bool Returns True if the access_token is expired.

setState($state)   X-Ref
Set OAuth 2.0 "state" parameter to achieve per-request customization.

param: string $state

setAccessType($accessType)   X-Ref

param: string $accessType Possible values for access_type include:

setApprovalPrompt($approvalPrompt)   X-Ref

param: string $approvalPrompt Possible values for approval_prompt include:

setLoginHint($loginHint)   X-Ref
Set the login hint, email address or sub id.

param: string $loginHint

setApplicationName($applicationName)   X-Ref
Set the application name, this is included in the User-Agent HTTP header.

param: string $applicationName

setClientId($clientId)   X-Ref
Set the OAuth 2.0 Client ID.

param: string $clientId

setClientSecret($clientSecret)   X-Ref
Set the OAuth 2.0 Client Secret.

param: string $clientSecret

setRedirectUri($redirectUri)   X-Ref
Set the OAuth 2.0 Redirect URI.

param: string $redirectUri

setRequestVisibleActions($requestVisibleActions)   X-Ref
If 'plus.login' is included in the list of requested scopes, you can use
this method to define types of app activities that your app will write.
You can find a list of available types here:

param: array $requestVisibleActions Array of app activity types

setDeveloperKey($developerKey)   X-Ref
Set the developer key to use, these are obtained through the API Console.

param: string $developerKey

setHostedDomain($hd)   X-Ref
Set the hd (hosted domain) parameter streamlines the login process for
Google Apps hosted accounts. By including the domain of the user, you
restrict sign-in to accounts at that domain.

param: $hd string - the domain to use.

setPrompt($prompt)   X-Ref
Set the prompt hint. Valid values are none, consent and select_account.
If no value is specified and the user has not previously authorized
access, then the user is shown a consent screen.

param: $prompt string

setOpenidRealm($realm)   X-Ref
openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth
2.0. It is used in OpenID 2.0 requests to signify the URL-space for which
an authentication request is valid.

param: $realm string - the URL-space to use.

setIncludeGrantedScopes($include)   X-Ref
If this is provided with the value true, and the authorization request is
granted, the authorization will include any previous authorizations
granted to this user/application combination for other scopes.

param: $include boolean - the URL-space to use.

refreshToken($refreshToken)   X-Ref
Fetches a fresh OAuth 2.0 access token with the given refresh token.

param: string $refreshToken

revokeToken($token = null)   X-Ref
Revoke an OAuth2 access token or refresh token. This method will revoke the current access
token, if a token isn't provided.

param: string|null $token The token (access token or a refresh token) that should be revoked.
return: boolean Returns True if the revocation was successful, otherwise False.

verifyIdToken($token = null)   X-Ref
Verify an id_token. This method will verify the current id_token, if one
isn't provided.

param: string|null $token The token (id_token) that should be verified.
return: Google_Auth_LoginTicket Returns an apiLoginTicket if the verification was

verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)   X-Ref
Verify a JWT that was signed with your own certificates.

param: $id_token string The JWT token
param: $cert_location array of certificates
param: $audience string the expected consumer of the token
param: $issuer string the expected issuer, defaults to Google
param: [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
return: mixed token information if valid, false if not

setAssertionCredentials(Google_Auth_AssertionCredentials $creds)   X-Ref

param: $creds Google_Auth_AssertionCredentials

setScopes($scopes)   X-Ref
Set the scopes to be requested. Must be called before createAuthUrl().
Will remove any previously configured scopes.

param: array $scopes, ie: array('https://www.googleapis.com/auth/plus.login',

addScope($scope_or_scopes)   X-Ref
This functions adds a scope to be requested as part of the OAuth2.0 flow.
Will append any scopes not previously requested to the scope parameter.
A single string will be treated as a scope to request. An array of strings
will each be appended.

param: $scope_or_scopes string|array e.g. "profile"

getScopes()   X-Ref
Returns the list of scopes requested by the client

return: array the list of scopes

setUseBatch($useBatch)   X-Ref
Declare whether batch calls should be used. This may increase throughput
by making multiple requests in one connection.

param: boolean $useBatch True if the batch support should

setDefer($defer)   X-Ref
Declare whether making API calls should make the call immediately, or
return a request which can be called with ->execute();

param: boolean $defer True if calls should not be executed right away.

execute($request)   X-Ref
Helper method to execute deferred HTTP requests.

param: $request Google_Http_Request|Google_Http_Batch
return: object of the type of the expected class or array.

shouldDefer()   X-Ref
Whether or not to return raw requests

return: boolean

getAuth()   X-Ref

return: Google_Auth_Abstract Authentication implementation

getIo()   X-Ref

return: Google_IO_Abstract IO implementation

getCache()   X-Ref

return: Google_Cache_Abstract Cache implementation

getLogger()   X-Ref

return: Google_Logger_Abstract Logger implementation

getClassConfig($class, $key = null)   X-Ref
Retrieve custom configuration for a specific class.

param: $class string|object - class or instance of class to retrieve
param: $key string optional - key to retrieve
return: array

setClassConfig($class, $config, $value = null)   X-Ref
Set configuration specific to a given class.
$config->setClassConfig('Google_Cache_File',
array('directory' => '/tmp/cache'));

param: $class string|object - The class name for the configuration
param: $config string key or an array of configuration values
param: $value string optional - if $config is a key, the value

getBasePath()   X-Ref

return: string the base URL to use for calls to the APIs

getApplicationName()   X-Ref

return: string the name of the application

isAppEngine()   X-Ref
Are we running in Google AppEngine?
return bool