Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Configurable oauth2 client class.

Copyright: 2017 Damyon Wiese
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 359 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: client  - X-Ref

Configurable oauth2 client class. URLs come from DB and access tokens from either DB (system accounts) or session (users').

__construct(issuer $issuer, $returnurl, $scopesrequired, $system = false)   X-Ref
Constructor.

param: issuer $issuer
param: moodle_url|null $returnurl
param: string $scopesrequired
param: boolean $system

auth_url()   X-Ref
Returns the auth url for OAuth 2.0 request

return: string the auth url

get_issuer()   X-Ref
Get the oauth2 issuer for this client.

return: \core\oauth2\issuer Issuer

get_additional_login_parameters()   X-Ref
Override to append additional params to a authentication request.

return: array (name value pairs).

get_login_scopes()   X-Ref
Override to change the scopes requested with an authentiction request.

return: string

token_url()   X-Ref
Returns the token url for OAuth 2.0 request

We are overriding the parent function so we get this from the configured endpoint.

return: string the auth url

get_tokenname()   X-Ref
We want a unique key for each issuer / and a different key for system vs user oauth.

return: string The unique key for the session value.

store_token($token)   X-Ref
Store a token between requests. Uses session named by get_tokenname for user account tokens
and a database record for system account tokens.

param: stdClass|null $token token object to store or null to clear

get_stored_token()   X-Ref
Retrieve a stored token from session (user accounts) or database (system accounts).

return: stdClass|null token object

get_userinfo_mapping()   X-Ref
Get a list of the mapping user fields in an associative array.

return: array

upgrade_refresh_token(system_account $systemaccount)   X-Ref
Upgrade a refresh token from oauth 2.0 to an access token

param: \core\oauth2\system_account $systemaccount
return: boolean true if token is upgraded succesfully

get_userinfo()   X-Ref
Fetch the user info from the user info endpoint and map all
the fields back into moodle fields.

return: array|false Moodle user fields for the logged in user (or false if request failed)