Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
core\oauth2\api Class Reference

Static list of api methods for system oauth2 configuration. More...

Static Public Member Functions

static connect_system_account ($issuer, $returnurl)
 Perform the OAuth dance and get a refresh token.
 
static create_endpoint ($data)
 Take the data from the mform and create the endpoint.
 
static create_endpoints_for_standard_issuer ($type, $issuer)
 Create endpoints for standard issuers, based on the issuer created from submitted data.
 
static create_issuer ($data)
 Take the data from the mform and create the issuer.
 
static create_standard_issuer ($type, $baseurl=false)
 Create one of the standard issuers.
 
static create_user_field_mapping ($data)
 Take the data from the mform and create the user field mapping.
 
static delete_endpoint ($id)
 Delete an endpoint.
 
static delete_issuer ($id)
 Delete an identity issuer.
 
static delete_user_field_mapping ($id)
 Delete a user_field_mapping.
 
static disable_issuer ($id)
 Disable an identity issuer.
 
static enable_issuer ($id)
 Enable an identity issuer.
 
static get_all_issuers (bool $includeloginonly=false)
 List all the issuers, ordered by the sortorder field.
 
static get_endpoint ($id)
 Get a single endpoint by id.
 
static get_endpoints (issuer $issuer)
 Get the list of defined endpoints for this OAuth issuer.
 
static get_issuer ($id)
 Get a single issuer by id.
 
static get_system_account (issuer $issuer)
 Get the system account for an installed OAuth service.
 
static get_system_oauth_client (issuer $issuer)
 Get an authenticated oauth2 client using the system account.
 
static get_system_scopes_for_issuer ($issuer)
 Get the full list of system scopes required by an oauth issuer.
 
static get_user_field_mapping ($id)
 Get a single user field mapping by id.
 
static get_user_field_mappings (issuer $issuer)
 Get the list of defined mapping from OAuth user fields to moodle user fields.
 
static get_user_oauth_client (issuer $issuer, moodle_url $currenturl, $additionalscopes='', $autorefresh=false)
 Get an authenticated oauth2 client using the current user account.
 
static init_standard_issuer ($type)
 Initializes a record for one of the standard issuers to be displayed in the settings.
 
static move_down_issuer ($id)
 Reorder this identity issuer.
 
static move_up_issuer ($id)
 Reorder this identity issuer.
 
static update_endpoint ($data)
 Take the data from the mform and update the endpoint.
 
static update_issuer ($data)
 Take the data from the mform and update the issuer.
 
static update_user_field_mapping ($data)
 Take the data from the mform and update the user field mapping.
 

Static Protected Member Functions

static create_or_update_issuer ($data, bool $create)
 Take the data from the mform and create or update the issuer.
 
static get_client_classname (?string $type)
 Get the client classname for an issuer.
 
static get_service_classname (?string $type)
 Get the service classname for an issuer.
 
static guess_image ($issuer)
 Guess an image from the discovery URL.
 

Detailed Description

Static list of api methods for system oauth2 configuration.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ connect_system_account()

static core\oauth2\api::connect_system_account ( $issuer,
$returnurl )
static

Perform the OAuth dance and get a refresh token.

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

Parameters
core\oauth2\issuer$issuer
moodle_url$returnurlThe url to the current page (we will be redirected back here after authentication).
Return values
boolean

◆ create_endpoint()

static core\oauth2\api::create_endpoint ( $data)
static

Take the data from the mform and create the endpoint.

Parameters
stdClass$data
Return values
core\oauth2\endpoint

◆ create_endpoints_for_standard_issuer()

static core\oauth2\api::create_endpoints_for_standard_issuer ( $type,
$issuer )
static

Create endpoints for standard issuers, based on the issuer created from submitted data.

Parameters
string$typeOne of google, facebook, microsoft, nextcloud, imsobv2p1
issuer$issuerissuer the endpoints should be created for.
Return values
core\oauth2\issuer

◆ create_issuer()

static core\oauth2\api::create_issuer ( $data)
static

Take the data from the mform and create the issuer.

Parameters
stdClass$data
Return values
core\oauth2\issuer

◆ create_or_update_issuer()

static core\oauth2\api::create_or_update_issuer ( $data,
bool $create )
staticprotected

Take the data from the mform and create or update the issuer.

Parameters
stdClass$dataForm data for them issuer to be created/updated.
bool$createIf true, the issuer will be created; otherwise, it will be updated.
Return values
issuerThe created/updated issuer.

◆ create_standard_issuer()

static core\oauth2\api::create_standard_issuer ( $type,
$baseurl = false )
static

Create one of the standard issuers.

Parameters
string$typeOne of google, facebook, microsoft, MoodleNet, nextcloud or imsobv2p1
string | false$baseurlBaseurl (only required for nextcloud, imsobv2p1 and moodlenet)
Return values
core\oauth2\issuer

◆ create_user_field_mapping()

static core\oauth2\api::create_user_field_mapping ( $data)
static

Take the data from the mform and create the user field mapping.

Parameters
stdClass$data
Return values
core\oauth2\user_field_mapping

◆ delete_endpoint()

static core\oauth2\api::delete_endpoint ( $id)
static

Delete an endpoint.

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

Parameters
int$idThe id of the endpoint to delete.
Return values
boolean

◆ delete_issuer()

static core\oauth2\api::delete_issuer ( $id)
static

Delete an identity issuer.

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

Parameters
int$idThe id of the identity issuer to delete.
Return values
boolean

◆ delete_user_field_mapping()

static core\oauth2\api::delete_user_field_mapping ( $id)
static

Delete a user_field_mapping.

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

Parameters
int$idThe id of the user_field_mapping to delete.
Return values
boolean

◆ disable_issuer()

static core\oauth2\api::disable_issuer ( $id)
static

Disable an identity issuer.

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

Parameters
int$idThe id of the identity issuer to disable.
Return values
boolean

◆ enable_issuer()

static core\oauth2\api::enable_issuer ( $id)
static

Enable an identity issuer.

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

Parameters
int$idThe id of the identity issuer to enable.
Return values
boolean

◆ get_all_issuers()

static core\oauth2\api::get_all_issuers ( bool $includeloginonly = false)
static

List all the issuers, ordered by the sortorder field.

Parameters
bool$includeloginonlyalso include issuers that are configured to be shown only on login page, By default false, in this case the method returns all issuers that can be used in services
Return values
core\oauth2\issuer[]

◆ get_client_classname()

static core\oauth2\api::get_client_classname ( ?string $type)
staticprotected

Get the client classname for an issuer.

Parameters
string$typeThe OAuth issuer type (google, facebook...).
Return values
stringThe classname for the custom client or core client class if the class for the defined type doesn't exist or null type is defined.

◆ get_endpoint()

static core\oauth2\api::get_endpoint ( $id)
static

Get a single endpoint by id.

Parameters
int$id
Return values
core\oauth2\endpoint

◆ get_endpoints()

static core\oauth2\api::get_endpoints ( issuer $issuer)
static

Get the list of defined endpoints for this OAuth issuer.

Parameters
core\oauth2\issuer$issuerThe desired OAuth issuer
Return values
core\oauth2\endpoint[]

◆ get_issuer()

static core\oauth2\api::get_issuer ( $id)
static

Get a single issuer by id.

Parameters
int$id
Return values
core\oauth2\issuer

◆ get_service_classname()

static core\oauth2\api::get_service_classname ( ?string $type)
staticprotected

Get the service classname for an issuer.

Parameters
string$typeThe OAuth issuer type (google, facebook...).
Return values
stringThe classname for this issuer or "Custom" service class if the class for the defined type doesn't exist or null type is defined.

◆ get_system_account()

static core\oauth2\api::get_system_account ( issuer $issuer)
static

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.

Parameters
core\oauth2\issuer$issuer
Return values
system_account|false

◆ get_system_oauth_client()

static core\oauth2\api::get_system_oauth_client ( issuer $issuer)
static

Get an authenticated oauth2 client using the system account.

This call uses the refresh token to get an access token.

Parameters
core\oauth2\issuer$issuer
Return values
core\oauth2\client|falseAn authenticated client (or false if the token could not be upgraded)
Exceptions
moodle_exceptionRequest for token upgrade failed for technical reasons

◆ get_system_scopes_for_issuer()

static core\oauth2\api::get_system_scopes_for_issuer ( $issuer)
static

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.

Parameters
core\oauth2\issuer$issuer
Return values
string

◆ get_user_field_mapping()

static core\oauth2\api::get_user_field_mapping ( $id)
static

Get a single user field mapping by id.

Parameters
int$id
Return values
core\oauth2\user_field_mapping

◆ get_user_field_mappings()

static core\oauth2\api::get_user_field_mappings ( issuer $issuer)
static

Get the list of defined mapping from OAuth user fields to moodle user fields.

Parameters
core\oauth2\issuer$issuerThe desired OAuth issuer
Return values
core\oauth2\user_field_mapping[]

◆ get_user_oauth_client()

static core\oauth2\api::get_user_oauth_client ( issuer $issuer,
moodle_url $currenturl,
$additionalscopes = '',
$autorefresh = false )
static

Get an authenticated oauth2 client using the current user account.

This call does the redirect dance back to the current page after authentication.

Parameters
core\oauth2\issuer$issuerThe desired OAuth issuer
moodle_url$currenturlThe url to the current page.
string$additionalscopesThe additional scopes required for authorization.
bool$autorefreshShould the client support the use of refresh tokens to persist access across sessions.
Return values
core\oauth2\client

◆ guess_image()

static core\oauth2\api::guess_image ( $issuer)
staticprotected

Guess an image from the discovery URL.

Parameters
core\oauth2\issuer$issuerThe desired OAuth issuer

◆ init_standard_issuer()

static core\oauth2\api::init_standard_issuer ( $type)
static

Initializes a record for one of the standard issuers to be displayed in the settings.

The issuer is not yet created in the database.

Parameters
string$typeOne of google, facebook, microsoft, nextcloud, imsobv2p1
Return values
core\oauth2\issuer

◆ move_down_issuer()

static core\oauth2\api::move_down_issuer ( $id)
static

Reorder this identity issuer.

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

Parameters
int$idThe id of the identity issuer to move.
Return values
boolean

◆ move_up_issuer()

static core\oauth2\api::move_up_issuer ( $id)
static

Reorder this identity issuer.

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

Parameters
int$idThe id of the identity issuer to move.
Return values
boolean

◆ update_endpoint()

static core\oauth2\api::update_endpoint ( $data)
static

Take the data from the mform and update the endpoint.

Parameters
stdClass$data
Return values
core\oauth2\endpoint

◆ update_issuer()

static core\oauth2\api::update_issuer ( $data)
static

Take the data from the mform and update the issuer.

Parameters
stdClass$data
Return values
core\oauth2\issuer

◆ update_user_field_mapping()

static core\oauth2\api::update_user_field_mapping ( $data)
static

Take the data from the mform and update the user field mapping.

Parameters
stdClass$data
Return values
core\oauth2\user_field_mapping

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