Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

(no description)

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

Defines 1 class


Class: Google_Auth_OAuth2  - X-Ref

Authentication class that deals with the OAuth 2 web-server authentication flow

__construct(Google_Client $client)   X-Ref
Instantiates the class, but does not initiate the login flow, leaving it
to the discretion of the caller.


authenticatedRequest(Google_Http_Request $request)   X-Ref
Perform an authenticated / signed apiHttpRequest.
This function takes the apiHttpRequest, calls apiAuth->sign on it
(which can modify the request in what ever way fits the auth mechanism)
and then calls apiCurlIO::makeRequest on the signed request

return: Google_Http_Request The resulting HTTP response including the
param: Google_Http_Request $request

authenticate($code, $crossClient = false)   X-Ref

return: string
param: string $code
param: boolean $crossClient

createAuthUrl($scope)   X-Ref
Create a URL to obtain user authorization.
The authorization endpoint allows the user to first
authenticate, and then grant/deny the access request.

return: string
param: string $scope The scope is expressed as a list of space-delimited strings.

setAccessToken($token)   X-Ref

param: string $token

getAccessToken()   X-Ref
No description

getRefreshToken()   X-Ref
No description

setState($state)   X-Ref
No description

setAssertionCredentials(Google_Auth_AssertionCredentials $creds)   X-Ref
No description

sign(Google_Http_Request $request)   X-Ref
Include an accessToken in a given apiHttpRequest.

return: Google_Http_Request
param: Google_Http_Request $request

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

return: void
param: string $refreshToken

refreshTokenWithAssertion($assertionCredentials = null)   X-Ref
Fetches a fresh access token with a given assertion token.

return: void
param: Google_Auth_AssertionCredentials $assertionCredentials optional.

refreshTokenRequest($params)   X-Ref
No description

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.

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

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

return: bool Returns True if the access_token is expired.

getFederatedSignOnCerts()   X-Ref
No description

retrieveCertsFromLocation($url)   X-Ref
Retrieve and cache a certificates file.

return: array certificates
param: $url string location

verifyIdToken($id_token = null, $audience = null)   X-Ref
Verifies an id token and returns the authenticated apiLoginTicket.
Throws an exception if the id token is not valid.
The audience parameter can be used to control which id tokens are
accepted.  By default, the id token must have been issued to this OAuth2 client.

return: Google_Auth_LoginTicket
param: $id_token
param: $audience

verifySignedJwtWithCerts($jwt,$certs,$required_audience,$issuer = null,$max_expiry = null)   X-Ref
Verifies the id token, returns the verified token contents.

return: mixed token information if valid, false if not
param: $jwt string the token
param: $certs array of certificates
param: $required_audience string the expected consumer of the token
param: [$issuer] the expected issues, defaults to Google
param: [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS

maybeAddParam($params, $name)   X-Ref
Add a parameter to the auth params if not empty string.