Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Configurable OAuth2 client class.

Author: Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
Copyright: 2020 Tung Thai
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 351 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 badges/classes/oauth2/badge_backpack_oauth2.php

Defines 1 class

client:: (11 methods):
  __construct()
  get_login_url()
  code_challenge()
  code_verifier()
  base64url_encode()
  callback_url()
  is_logged_in()
  upgrade_token()
  store_token()
  get_stored_token()
  get_scopes()


Class: client  - X-Ref

Configurable OAuth2 client to request authorization and store token. Use the PKCE method to verifier authorization.

__construct(\core\oauth2\issuer $issuer, $returnurl = '', $additionalscopes = '',$backpack = null)   X-Ref
client constructor.

param: issuer $issuer oauth2 service.
param: string $returnurl return url after login
param: string $additionalscopes the scopes has been granted
param: null $backpack backpack object.

get_login_url()   X-Ref
Get login url.

return: moodle_url

code_challenge()   X-Ref
Generate code challenge.

return: string

code_verifier()   X-Ref
Get code verifier.

return: bool

base64url_encode($plaintext)   X-Ref
Generate base64url encode.

param: string $plaintext text to convert.
return: string

callback_url()   X-Ref
Callback url where the request is returned to.

return: moodle_url url of callback

is_logged_in()   X-Ref
Check and refresh token to keep login on backpack site.

return: bool

upgrade_token($code, $granttype = 'authorization_code')   X-Ref
Request new token.

param: string $code code verify from Auth site.
param: string $granttype grant type.
return: bool

store_token($token)   X-Ref
Store a token to verify for send request.

param: null|stdClass $token

get_stored_token()   X-Ref
Get token of current user.

return: stdClass|null token object

get_scopes()   X-Ref
Get scopes granted.

return: null|string