Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
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() | |
Google_Client::__construct | ( | $config = null | ) |
Construct the Google Client.
$config | Google_Config or string for the ini file to load |
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.
$scope_or_scopes | string|array e.g. "profile" |
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.
$code | string code from accounts.google.com |
$crossClient | boolean, whether this is a cross-client authentication |
string | token |
Google_Client::createAuthUrl | ( | ) |
Construct the OAuth 2.0 authorization request URI.
string |
Google_Client::execute | ( | $request | ) |
Helper method to execute deferred HTTP requests.
$request | Google_Http_Request|Google_Http_Batch |
Google_Exception |
object | of the type of the expected class or array. |
Google_Client::getAccessToken | ( | ) |
Get the OAuth 2.0 access token.
string\$accessToken | JSON encoded string in the following format: {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer", "expires_in":3600,"id_token":"TOKEN", "created":1320790426} |
Google_Client::getApplicationName | ( | ) |
string | the name of the application |
Google_Client::getAuth | ( | ) |
Google_Auth_Abstract | Authentication implementation |
Google_Client::getBasePath | ( | ) |
string | the base URL to use for calls to the APIs |
Google_Client::getCache | ( | ) |
Google_Cache_Abstract | Cache implementation |
Google_Client::getClassConfig | ( | $class, | |
$key = null ) |
Retrieve custom configuration for a specific class.
$class | string|object - class or instance of class to retrieve |
$key | string optional - key to retrieve |
array |
Google_Client::getIo | ( | ) |
Google_IO_Abstract | IO implementation |
Google_Client::getLibraryVersion | ( | ) |
Get a string containing the version of the library.
string |
Google_Client::getLogger | ( | ) |
Google_Logger_Abstract | Logger implementation |
Google_Client::getRefreshToken | ( | ) |
Get the OAuth 2.0 refresh token.
string\$refreshToken | refresh token or null if not available |
Google_Client::getScopes | ( | ) |
Returns the list of scopes requested by the client.
array | the list of scopes |
Google_Client::isAccessTokenExpired | ( | ) |
Returns if the access_token is expired.
bool | Returns True if the access_token is expired. |
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.
string | $jsonLocation | File location of the project-key.json. |
array | $scopes | The scopes to assert. |
Google_Auth_AssertionCredentials. | @ |
Google_Client::prepareScopes | ( | ) |
Google_Auth_Exception |
array | @visible For Testing |
Google_Client::refreshToken | ( | $refreshToken | ) |
Fetches a fresh OAuth 2.0 access token with the given refresh token.
string | $refreshToken |
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.
Google_Auth_Exception |
string | null | $token | The token (access token or a refresh token) that should be revoked. |
boolean | Returns True if the revocation was successful, otherwise False. |
Google_Client::setAccessToken | ( | $accessToken | ) |
Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl() or Google_Client\getAccessToken().
string | $accessToken | JSON encoded string containing in the following format: {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer", "expires_in":3600, "id_token":"TOKEN", "created":1320790426} |
Google_Client::setAccessType | ( | $accessType | ) |
string | $accessType | Possible values for access_type include: "offline" to request offline access from the user. "online" to request online access from the user. |
Google_Client::setApplicationName | ( | $applicationName | ) |
Set the application name, this is included in the User-Agent HTTP header.
string | $applicationName |
Google_Client::setApprovalPrompt | ( | $approvalPrompt | ) |
string | $approvalPrompt | Possible 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. |
Google_Client::setAssertionCredentials | ( | Google_Auth_AssertionCredentials | $creds | ) |
$creds | Google_Auth_AssertionCredentials |
Google_Client::setAuth | ( | Google_Auth_Abstract | $auth | ) |
Set the authenticator object.
Google_Auth_Abstract | $auth |
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.
string | $json | the configuration json |
Google_Exception |
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.
string | $file | the file location of the client json |
Google_Client::setCache | ( | Google_Cache_Abstract | $cache | ) |
Set the Cache object.
Google_Cache_Abstract | $cache |
Google_Client::setClassConfig | ( | $class, | |
$config, | |||
$value = null ) |
Set configuration specific to a given class.
$config->setClassConfig('Google_Cache_File', array('directory' => '/tmp/cache'));
$class | string|object - The class name for the configuration |
$config | string key or an array of configuration values |
$value | string optional - if $config is a key, the value |
Google_Client::setClientId | ( | $clientId | ) |
Set the OAuth 2.0 Client ID.
string | $clientId |
Google_Client::setClientSecret | ( | $clientSecret | ) |
Set the OAuth 2.0 Client Secret.
string | $clientSecret |
Google_Client::setDefer | ( | $defer | ) |
Declare whether making API calls should make the call immediately, or return a request which can be called with ->execute();.
boolean | $defer | True if calls should not be executed right away. |
Google_Client::setDeveloperKey | ( | $developerKey | ) |
Set the developer key to use, these are obtained through the API Console.
string | $developerKey |
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.
$hd | string - the domain to use. |
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.
$include | boolean - the URL-space to use. |
Google_Client::setIo | ( | Google_IO_Abstract | $io | ) |
Set the IO object.
Google_IO_Abstract | $io |
Google_Client::setLogger | ( | Google_Logger_Abstract | $logger | ) |
Set the Logger object.
Google_Logger_Abstract | $logger |
Google_Client::setLoginHint | ( | $loginHint | ) |
Set the login hint, email address or sub id.
string | $loginHint |
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.
$realm | string - the URL-space to use. |
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.
$prompt | string |
Google_Client::setRedirectUri | ( | $redirectUri | ) |
Set the OAuth 2.0 Redirect URI.
string | $redirectUri |
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
array | $requestVisibleActions | Array of app activity types |
Google_Client::setScopes | ( | $scopes | ) |
Set the scopes to be requested.
Must be called before createAuthUrl(). Will remove any previously configured scopes.
array | $scopes,ie | array('https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/moderator') |
Google_Client::setState | ( | $state | ) |
Set OAuth 2.0 "state" parameter to achieve per-request customization.
string | $state |
Google_Client::setUseBatch | ( | $useBatch | ) |
Declare whether batch calls should be used.
This may increase throughput by making multiple requests in one connection.
boolean | $useBatch | True if the batch support should be enabled. Defaults to False. |
Google_Client::shouldDefer | ( | ) |
Whether or not to return raw requests.
boolean |
Google_Client::verifyIdToken | ( | $token = null | ) |
Verify an id_token.
This method will verify the current id_token, if one isn't provided.
Google_Auth_Exception |
string | null | $token | The token (id_token) that should be verified. |
Google_Auth_LoginTicket | Returns an apiLoginTicket if the verification was successful. |
Google_Client::verifySignedJwt | ( | $id_token, | |
$cert_location, | |||
$audience, | |||
$issuer, | |||
$max_expiry = null ) |
Verify a JWT that was signed with your own certificates.
$id_token | string The JWT token |
$cert_location | array of certificates |
$audience | string the expected consumer of the token |
$issuer | string the expected issuer, defaults to Google |
[$max_expiry] | the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS |
mixed | token information if valid, false if not |