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.

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.

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

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.

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

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