Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
Google_Client Class Reference

Public Member Functions

 __construct ($config=null)
 Construct the Google Client.
 
 addScope ($scope_or_scopes)
 This functions adds a scope to be requested as part of the OAuth2.0 flow.
 
 authenticate ($code, $crossClient=false)
 Attempt to exchange a code for an valid authentication token.
 
 createAuthUrl ()
 Construct the OAuth 2.0 authorization request URI.
 
 execute ($request)
 Helper method to execute deferred HTTP requests.
 
 getAccessToken ()
 Get the OAuth 2.0 access token.
 
 getApplicationName ()
 
 getAuth ()
 
 getBasePath ()
 
 getCache ()
 
 getClassConfig ($class, $key=null)
 Retrieve custom configuration for a specific class.
 
 getIo ()
 
 getLibraryVersion ()
 Get a string containing the version of the library.
 
 getLogger ()
 
 getRefreshToken ()
 Get the OAuth 2.0 refresh token.
 
 getScopes ()
 Returns the list of scopes requested by the client.
 
 isAccessTokenExpired ()
 Returns if the access_token is expired.
 
 isAppEngine ()
 Are we running in Google AppEngine? return bool.
 
 loadServiceAccountJson ($jsonLocation, $scopes)
 Loads a service account key and parameters from a JSON file from the Google Developer Console.
 
 prepareScopes ()
 
 refreshToken ($refreshToken)
 Fetches a fresh OAuth 2.0 access token with the given refresh token.
 
 revokeToken ($token=null)
 Revoke an OAuth2 access token or refresh token.
 
 setAccessToken ($accessToken)
 Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl() or Google_Client\getAccessToken().
 
 setAccessType ($accessType)
 
 setApplicationName ($applicationName)
 Set the application name, this is included in the User-Agent HTTP header.
 
 setApprovalPrompt ($approvalPrompt)
 
 setAssertionCredentials (Google_Auth_AssertionCredentials $creds)
 
 setAuth (Google_Auth_Abstract $auth)
 Set the authenticator object.
 
 setAuthConfig ($json)
 Set the auth config from the JSON string provided.
 
 setAuthConfigFile ($file)
 Set the auth config from the JSON file in the path provided.
 
 setCache (Google_Cache_Abstract $cache)
 Set the Cache object.
 
 setClassConfig ($class, $config, $value=null)
 Set configuration specific to a given class.
 
 setClientId ($clientId)
 Set the OAuth 2.0 Client ID.
 
 setClientSecret ($clientSecret)
 Set the OAuth 2.0 Client Secret.
 
 setDefer ($defer)
 Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();.
 
 setDeveloperKey ($developerKey)
 Set the developer key to use, these are obtained through the API Console.
 
 setHostedDomain ($hd)
 Set the hd (hosted domain) parameter streamlines the login process for Google Apps hosted accounts.
 
 setIncludeGrantedScopes ($include)
 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.
 
 setIo (Google_IO_Abstract $io)
 Set the IO object.
 
 setLogger (Google_Logger_Abstract $logger)
 Set the Logger object.
 
 setLoginHint ($loginHint)
 Set the login hint, email address or sub id.
 
 setOpenidRealm ($realm)
 openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth 2.0.
 
 setPrompt ($prompt)
 Set the prompt hint.
 
 setRedirectUri ($redirectUri)
 Set the OAuth 2.0 Redirect URI.
 
 setRequestVisibleActions ($requestVisibleActions)
 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.
 
 setScopes ($scopes)
 Set the scopes to be requested.
 
 setState ($state)
 Set OAuth 2.0 "state" parameter to achieve per-request customization.
 
 setUseBatch ($useBatch)
 Declare whether batch calls should be used.
 
 shouldDefer ()
 Whether or not to return raw requests.
 
 verifyIdToken ($token=null)
 Verify an id_token.
 
 verifySignedJwt ($id_token, $cert_location, $audience, $issuer, $max_expiry=null)
 Verify a JWT that was signed with your own certificates.
 

Public Attributes

const LIBVER = "1.1.5"
 
const USER_AGENT_SUFFIX = "google-api-php-client/"
 

Protected Attributes

array $requestedScopes = array()
 $scopes
 
 $services = array()
 

Constructor & Destructor Documentation

◆ __construct()

Google_Client::__construct ( $config = null)

Construct the Google Client.

Parameters
$configGoogle_Config or string for the ini file to load

Member Function Documentation

◆ addScope()

Google_Client::addScope ( $scope_or_scopes)

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.

Parameters
$scope_or_scopesstring|array e.g. "profile"

◆ authenticate()

Google_Client::authenticate ( $code,
$crossClient = false )

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.

Parameters
$codestring code from accounts.google.com
$crossClientboolean, whether this is a cross-client authentication
Return values
stringtoken

◆ createAuthUrl()

Google_Client::createAuthUrl ( )

Construct the OAuth 2.0 authorization request URI.

Return values
string

◆ execute()

Google_Client::execute ( $request)

Helper method to execute deferred HTTP requests.

Parameters
$requestGoogle_Http_Request|Google_Http_Batch
Exceptions
Google_Exception
Return values
objectof the type of the expected class or array.

◆ getAccessToken()

Google_Client::getAccessToken ( )

Get the OAuth 2.0 access token.

Return values
string\$accessTokenJSON encoded string in the following format: {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer", "expires_in":3600,"id_token":"TOKEN", "created":1320790426}

◆ getApplicationName()

Google_Client::getApplicationName ( )
Return values
stringthe name of the application

◆ getAuth()

Google_Client::getAuth ( )
Return values
Google_Auth_AbstractAuthentication implementation

◆ getBasePath()

Google_Client::getBasePath ( )
Return values
stringthe base URL to use for calls to the APIs

◆ getCache()

Google_Client::getCache ( )
Return values
Google_Cache_AbstractCache implementation

◆ getClassConfig()

Google_Client::getClassConfig ( $class,
$key = null )

Retrieve custom configuration for a specific class.

Parameters
$classstring|object - class or instance of class to retrieve
$keystring optional - key to retrieve
Return values
array

◆ getIo()

Google_Client::getIo ( )
Return values
Google_IO_AbstractIO implementation

◆ getLibraryVersion()

Google_Client::getLibraryVersion ( )

Get a string containing the version of the library.

Return values
string

◆ getLogger()

Google_Client::getLogger ( )
Return values
Google_Logger_AbstractLogger implementation

◆ getRefreshToken()

Google_Client::getRefreshToken ( )

Get the OAuth 2.0 refresh token.

Return values
string\$refreshTokenrefresh token or null if not available

◆ getScopes()

Google_Client::getScopes ( )

Returns the list of scopes requested by the client.

Return values
arraythe list of scopes

◆ isAccessTokenExpired()

Google_Client::isAccessTokenExpired ( )

Returns if the access_token is expired.

Return values
boolReturns True if the access_token is expired.

◆ loadServiceAccountJson()

Google_Client::loadServiceAccountJson ( $jsonLocation,
$scopes )

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.

Parameters
string$jsonLocationFile location of the project-key.json.
array$scopesThe scopes to assert.
Return values
Google_Auth_AssertionCredentials.@

◆ prepareScopes()

Google_Client::prepareScopes ( )
Exceptions
Google_Auth_Exception
Return values
array@visible For Testing

◆ refreshToken()

Google_Client::refreshToken ( $refreshToken)

Fetches a fresh OAuth 2.0 access token with the given refresh token.

Parameters
string$refreshToken

◆ revokeToken()

Google_Client::revokeToken ( $token = null)

Revoke an OAuth2 access token or refresh token.

This method will revoke the current access token, if a token isn't provided.

Exceptions
Google_Auth_Exception
Parameters
string | null$tokenThe token (access token or a refresh token) that should be revoked.
Return values
booleanReturns True if the revocation was successful, otherwise False.

◆ setAccessToken()

Google_Client::setAccessToken ( $accessToken)

Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl() or Google_Client\getAccessToken().

Parameters
string$accessTokenJSON encoded string containing in the following format: {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer", "expires_in":3600, "id_token":"TOKEN", "created":1320790426}

◆ setAccessType()

Google_Client::setAccessType ( $accessType)
Parameters
string$accessTypePossible values for access_type include: "offline" to request offline access from the user. "online" to request online access from the user.

◆ setApplicationName()

Google_Client::setApplicationName ( $applicationName)

Set the application name, this is included in the User-Agent HTTP header.

Parameters
string$applicationName

◆ setApprovalPrompt()

Google_Client::setApprovalPrompt ( $approvalPrompt)
Parameters
string$approvalPromptPossible values for approval_prompt include: "force" to force the approval UI to appear. (This is the default value) "auto" to request auto-approval when possible.

◆ setAssertionCredentials()

Google_Client::setAssertionCredentials ( Google_Auth_AssertionCredentials $creds)

◆ setAuth()

Google_Client::setAuth ( Google_Auth_Abstract $auth)

Set the authenticator object.

Parameters
Google_Auth_Abstract$auth

◆ setAuthConfig()

Google_Client::setAuthConfig ( $json)

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.

Parameters
string$jsonthe configuration json
Exceptions
Google_Exception

◆ setAuthConfigFile()

Google_Client::setAuthConfigFile ( $file)

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.

Parameters
string$filethe file location of the client json

◆ setCache()

Google_Client::setCache ( Google_Cache_Abstract $cache)

Set the Cache object.

Parameters
Google_Cache_Abstract$cache

◆ setClassConfig()

Google_Client::setClassConfig ( $class,
$config,
$value = null )

Set configuration specific to a given class.

$config->setClassConfig('Google_Cache_File', array('directory' => '/tmp/cache'));

Parameters
$classstring|object - The class name for the configuration
$configstring key or an array of configuration values
$valuestring optional - if $config is a key, the value

◆ setClientId()

Google_Client::setClientId ( $clientId)

Set the OAuth 2.0 Client ID.

Parameters
string$clientId

◆ setClientSecret()

Google_Client::setClientSecret ( $clientSecret)

Set the OAuth 2.0 Client Secret.

Parameters
string$clientSecret

◆ setDefer()

Google_Client::setDefer ( $defer)

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

Parameters
boolean$deferTrue if calls should not be executed right away.

◆ setDeveloperKey()

Google_Client::setDeveloperKey ( $developerKey)

Set the developer key to use, these are obtained through the API Console.

See also
http://code.google.com/apis/console-help/#generatingdevkeys
Parameters
string$developerKey

◆ setHostedDomain()

Google_Client::setHostedDomain ( $hd)

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.

Parameters
$hdstring - the domain to use.

◆ setIncludeGrantedScopes()

Google_Client::setIncludeGrantedScopes ( $include)

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.

Parameters
$includeboolean - the URL-space to use.

◆ setIo()

Google_Client::setIo ( Google_IO_Abstract $io)

Set the IO object.

Parameters
Google_IO_Abstract$io

◆ setLogger()

Google_Client::setLogger ( Google_Logger_Abstract $logger)

Set the Logger object.

Parameters
Google_Logger_Abstract$logger

◆ setLoginHint()

Google_Client::setLoginHint ( $loginHint)

Set the login hint, email address or sub id.

Parameters
string$loginHint

◆ setOpenidRealm()

Google_Client::setOpenidRealm ( $realm)

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.

Parameters
$realmstring - the URL-space to use.

◆ setPrompt()

Google_Client::setPrompt ( $prompt)

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.

Parameters
$promptstring

◆ setRedirectUri()

Google_Client::setRedirectUri ( $redirectUri)

Set the OAuth 2.0 Redirect URI.

Parameters
string$redirectUri

◆ setRequestVisibleActions()

Google_Client::setRequestVisibleActions ( $requestVisibleActions)

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: @externalurl https://developers.google.com/+/api/moment-types

Parameters
array$requestVisibleActionsArray of app activity types

◆ setScopes()

Google_Client::setScopes ( $scopes)

Set the scopes to be requested.

Must be called before createAuthUrl(). Will remove any previously configured scopes.

Parameters
array$scopes,iearray('https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/moderator')

◆ setState()

Google_Client::setState ( $state)

Set OAuth 2.0 "state" parameter to achieve per-request customization.

See also
http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-3.1.2.2
Parameters
string$state

◆ setUseBatch()

Google_Client::setUseBatch ( $useBatch)

Declare whether batch calls should be used.

This may increase throughput by making multiple requests in one connection.

Parameters
boolean$useBatchTrue if the batch support should be enabled. Defaults to False.

◆ shouldDefer()

Google_Client::shouldDefer ( )

Whether or not to return raw requests.

Return values
boolean

◆ verifyIdToken()

Google_Client::verifyIdToken ( $token = null)

Verify an id_token.

This method will verify the current id_token, if one isn't provided.

Exceptions
Google_Auth_Exception
Parameters
string | null$tokenThe token (id_token) that should be verified.
Return values
Google_Auth_LoginTicketReturns an apiLoginTicket if the verification was successful.

◆ verifySignedJwt()

Google_Client::verifySignedJwt ( $id_token,
$cert_location,
$audience,
$issuer,
$max_expiry = null )

Verify a JWT that was signed with your own certificates.

Parameters
$id_tokenstring The JWT token
$cert_locationarray of certificates
$audiencestring the expected consumer of the token
$issuerstring the expected issuer, defaults to Google
[$max_expiry]the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
Return values
mixedtoken information if valid, false if not

The documentation for this class was generated from the following file: