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.

Class: api  - X-Ref

Static list of api methods for system oauth2 configuration.

init_google()   X-Ref
Build a google ready OAuth 2 service.

return: \core\oauth2\issuer

create_endpoints_for_google($issuer)   X-Ref
Create endpoints for google issuers.

param: issuer $issuer issuer the endpoints should be created for.
return: mixed

init_facebook()   X-Ref
Build a facebook ready OAuth 2 service.

return: \core\oauth2\issuer

create_endpoints_for_facebook($issuer)   X-Ref
Create endpoints for facebook issuers.

param: issuer $issuer issuer the endpoints should be created for.
return: mixed

init_microsoft()   X-Ref
Build a microsoft ready OAuth 2 service.

return: \core\oauth2\issuer

create_endpoints_for_microsoft($issuer)   X-Ref
Create endpoints for microsoft issuers.

param: issuer $issuer issuer the endpoints should be created for.
return: mixed

init_nextcloud()   X-Ref
Build a nextcloud ready OAuth 2 service.

return: \core\oauth2\issuer

create_endpoints_for_nextcloud($issuer)   X-Ref
Create endpoints for nextcloud issuers.

param: issuer $issuer issuer the endpoints should be created for.
return: mixed

init_standard_issuer($type)   X-Ref
Initializes a record for one of the standard issuers to be displayed in the settings.
The issuer is not yet created in the database.

param: string $type One of google, facebook, microsoft, nextcloud
return: \core\oauth2\issuer

create_endpoints_for_standard_issuer($type, $issuer)   X-Ref
Create endpoints for standard issuers, based on the issuer created from submitted data.

param: string $type One of google, facebook, microsoft, nextcloud
param: issuer $issuer issuer the endpoints should be created for.
return: \core\oauth2\issuer

create_standard_issuer($type, $baseurl = false)   X-Ref
Create one of the standard issuers.

param: string $type One of google, facebook, microsoft, or nextcloud
param: string|false $baseurl Baseurl (only required for nextcloud)
return: \core\oauth2\issuer

get_all_issuers()   X-Ref
List all the issuers, ordered by the sortorder field

return: \core\oauth2\issuer[]

get_issuer($id)   X-Ref
Get a single issuer by id.

param: int $id
return: \core\oauth2\issuer

get_endpoint($id)   X-Ref
Get a single endpoint by id.

param: int $id
return: \core\oauth2\endpoint

get_user_field_mapping($id)   X-Ref
Get a single user field mapping by id.

param: int $id
return: \core\oauth2\user_field_mapping

get_system_account(issuer $issuer)   X-Ref
Get the system account for an installed OAuth service.
Never ever ever expose this to a webservice because it contains the refresh token which grants API access.

param: \core\oauth2\issuer $issuer
return: system_account|false

get_system_scopes_for_issuer($issuer)   X-Ref
Get the full list of system scopes required by an oauth issuer.
This includes the list required for login as well as any scopes injected by the oauth2_system_scopes callback in plugins.

param: \core\oauth2\issuer $issuer
return: string

get_system_oauth_client(issuer $issuer)   X-Ref
Get an authenticated oauth2 client using the system account.
This call uses the refresh token to get an access token.

param: \core\oauth2\issuer $issuer
return: \core\oauth2\client|false An authenticated client (or false if the token could not be upgraded)

get_user_oauth_client(issuer $issuer, moodle_url $currenturl, $additionalscopes = '')   X-Ref
Get an authenticated oauth2 client using the current user account.
This call does the redirect dance back to the current page after authentication.

param: \core\oauth2\issuer $issuer The desired OAuth issuer
param: moodle_url $currenturl The url to the current page.
param: string $additionalscopes The additional scopes required for authorization.
return: \core\oauth2\client

get_endpoints(issuer $issuer)   X-Ref
Get the list of defined endpoints for this OAuth issuer

param: \core\oauth2\issuer $issuer The desired OAuth issuer
return: \core\oauth2\endpoint[]

get_user_field_mappings(issuer $issuer)   X-Ref
Get the list of defined mapping from OAuth user fields to moodle user fields.

param: \core\oauth2\issuer $issuer The desired OAuth issuer
return: \core\oauth2\user_field_mapping[]

guess_image($issuer)   X-Ref
Guess an image from the discovery URL.

param: \core\oauth2\issuer $issuer The desired OAuth issuer

discover_endpoints($issuer)   X-Ref
If the discovery endpoint exists for this issuer, try and determine the list of valid endpoints.

param: issuer $issuer
return: int The number of discovered services.

update_issuer($data)   X-Ref
Take the data from the mform and update the issuer.

param: stdClass $data
return: \core\oauth2\issuer

create_issuer($data)   X-Ref
Take the data from the mform and create the issuer.

param: stdClass $data
return: \core\oauth2\issuer

update_endpoint($data)   X-Ref
Take the data from the mform and update the endpoint.

param: stdClass $data
return: \core\oauth2\endpoint

create_endpoint($data)   X-Ref
Take the data from the mform and create the endpoint.

param: stdClass $data
return: \core\oauth2\endpoint

update_user_field_mapping($data)   X-Ref
Take the data from the mform and update the user field mapping.

param: stdClass $data
return: \core\oauth2\user_field_mapping

create_user_field_mapping($data)   X-Ref
Take the data from the mform and create the user field mapping.

param: stdClass $data
return: \core\oauth2\user_field_mapping

move_up_issuer($id)   X-Ref
Reorder this identity issuer.

Requires moodle/site:config capability at the system context.

param: int $id The id of the identity issuer to move.
return: boolean

move_down_issuer($id)   X-Ref
Reorder this identity issuer.

Requires moodle/site:config capability at the system context.

param: int $id The id of the identity issuer to move.
return: boolean

disable_issuer($id)   X-Ref
Disable an identity issuer.

Requires moodle/site:config capability at the system context.

param: int $id The id of the identity issuer to disable.
return: boolean

enable_issuer($id)   X-Ref
Enable an identity issuer.

Requires moodle/site:config capability at the system context.

param: int $id The id of the identity issuer to enable.
return: boolean

delete_issuer($id)   X-Ref
Delete an identity issuer.

Requires moodle/site:config capability at the system context.

param: int $id The id of the identity issuer to delete.
return: boolean

delete_endpoint($id)   X-Ref
Delete an endpoint.

Requires moodle/site:config capability at the system context.

param: int $id The id of the endpoint to delete.
return: boolean

delete_user_field_mapping($id)   X-Ref
Delete a user_field_mapping.

Requires moodle/site:config capability at the system context.

param: int $id The id of the user_field_mapping to delete.
return: boolean

connect_system_account($issuer, $returnurl)   X-Ref
Perform the OAuth dance and get a refresh token.

Requires moodle/site:config capability at the system context.

param: \core\oauth2\issuer $issuer
param: moodle_url $returnurl The url to the current page (we will be redirected back here after authentication).
return: boolean