PHP Class Gdn_OAuth2, vanilla

Base class to be extended by any plugin that wants to use Oauth2 protocol for SSO. WARNING This is a base class for the purposes of being extended by other plugins. It is not to be instantiated on its own. For most OAuth2 SSO needs the generic plugins/OAuth2/class.Oauth2.plugin.php should be adequate. If not, create a plugin that extends this class, Gdn_OAuth2, and overwrite any of its methods of constants.
Inheritance: extends Gdn_Plugin
Afficher le fichier Open project: vanilla/vanilla

Protected Properties

Свойство Type Description
$accessToken token provider by authenticator
$authorizeUriParams optional additional get parameters to be passed in the authorize_uri
$defaultContentType content type for API calls
$profileRequestParams optional additional get params to be passed in the request for profile
$provider stored information to connect with provider (secret, etc.)
$providerKey key for GDN_UserAuthenticationProvider table
$requestAccessTokenParams optional additional post parameters to be passed in the accessToken request
$scope passing scope to authenticator
$settingsView

Méthodes publiques

Méthode Description
__construct ( string $providerKey, boolean | string $accessToken = false ) Set up OAuth2 access properties.
accessToken ( boolean | string $newValue = false ) : boolean | string | null Renew or return access token.
assetModel_styleCss_handler ( $sender, $args ) Insert css file for generic styling of signin button/icon.
authorizeUri ( array $state = [] ) : string Create the URI that can return an authorization.
base_beforeSignInButton_handler ( $sender, $args ) Inject a sign-in icon into the ME menu.
base_connectData_handler ( $sender, $args ) Inject into the process of the base connection.
entryController_overrideSignIn_handler ( $sender, $args ) : mixed | boolean Redirect to provider's signin page if this is the default behaviour.
entryController_signIn_handler ( $sender, $args ) : mixed | boolean Inject sign-in button into the sign in page.
entryEndpoint ( $sender, $code, $state ) Create a controller to handle entry request.
gdn_pluginManager_afterStart_handler ( $sender ) Register a call back function so that multiple plugins can use it as an entry point on SSO.
getAccessTokenRequestOptions ( ) : array Allow child classes to pass different options to the Token request API call.
getProfile ( ) : array Get profile data from authentication provider through API.
getProfileRequestOptions ( ) : array Allow child classes to pass different options to the Profile request API call.
getProviderKey ( ) : string Get provider key.
isConfigured ( ) : boolean Check if there is enough data to connect to an authentication provider.
isConnected ( ) : boolean Check if an access token has been returned from the provider server.
isDefault ( ) : boolean Check authentication provider table to see if this is the default method for logging in.
log ( $message, $data )
provider ( ) : array Return all the information saved in provider table.
requestAccessToken ( string $code ) : mixed Request access token from provider.
requireVal ( string $key, array $arr, string $context = null ) : mixed Extract values from arrays.
setAccessToken ( string $accessToken ) Set access token received from provider.
setAuthorizeUriParams ( $params ) Set additional params to be added to the get string in the AuthorizeUri string.
setGetProfileParams ( $params ) Set additional params to be added to the get string in the getProfile request.
setProviderKey ( string $providerKey ) Set provider key used to access settings stored in GDN_UserAuthenticationProvider.
setRequestAccessTokenParams ( $params ) Set additional params to be added to the post array in the accessToken request.
setScope ( $scope ) Set scope to be passed to provider.
settingsEndpoint ( $sender, $args ) Create a controller to deal with plugin settings in dashboard.
setup ( ) Setup
signInButton ( string $type = 'button' ) : string Create signup button specific to this plugin.
structure ( ) Create the structure in the database.
translateProfileResults ( array $rawProfile = [] ) : array Allow the admin to input the keys that their service uses to send data.

Méthodes protégées

Méthode Description
api ( $uri, string $method = 'GET', array $params = [], array $options = [] ) : mixed | type. Generic API uses ProxyRequest class to fetch data from remote endpoints.
getSettingsFormFields ( ) : array Allow child class to over-ride or add form fields to settings.

Method Details

__construct() public méthode

Set up OAuth2 access properties.
public __construct ( string $providerKey, boolean | string $accessToken = false )
$providerKey string Fixed key set in child class.
$accessToken boolean | string Provided by the authentication provider.

accessToken() public méthode

Renew or return access token.
public accessToken ( boolean | string $newValue = false ) : boolean | string | null
$newValue boolean | string Pass existing token if it exists.
Résultat boolean | string | null String if there is an accessToken passed or found in session, false or null if not.

api() protected méthode

Generic API uses ProxyRequest class to fetch data from remote endpoints.
protected api ( $uri, string $method = 'GET', array $params = [], array $options = [] ) : mixed | type.
$uri Endpoint on provider's server.
$method string HTTP method required by provider.
$params array Query string.
$options array Configuration options for the request (e.g. Content-Type).
Résultat mixed | type.

assetModel_styleCss_handler() public méthode

Insert css file for generic styling of signin button/icon.
public assetModel_styleCss_handler ( $sender, $args )

authorizeUri() public méthode

Create the URI that can return an authorization.
public authorizeUri ( array $state = [] ) : string
$state array Optionally provide an array of variables to be sent to the provider.
Résultat string Endpoint of the provider.

base_beforeSignInButton_handler() public méthode

Inject a sign-in icon into the ME menu.
public base_beforeSignInButton_handler ( $sender, $args )

base_connectData_handler() public méthode

Inject into the process of the base connection.
public base_connectData_handler ( $sender, $args )

entryController_overrideSignIn_handler() public méthode

Redirect to provider's signin page if this is the default behaviour.
public entryController_overrideSignIn_handler ( $sender, $args ) : mixed | boolean
Résultat mixed | boolean Return null if not configured.

entryController_signIn_handler() public méthode

Inject sign-in button into the sign in page.
public entryController_signIn_handler ( $sender, $args ) : mixed | boolean
Résultat mixed | boolean Return null if not configured

entryEndpoint() public méthode

Create a controller to handle entry request.
public entryEndpoint ( $sender, $code, $state )
$code string Retrieved from the response of the authentication provider, used to fetch an authentication token.
$state string Values passed by us and returned in the response of the authentication provider.

gdn_pluginManager_afterStart_handler() public méthode

This endpoint is executed on /entry/[provider] and is used as the redirect after making an initial request to log in to an authentication provider.
public gdn_pluginManager_afterStart_handler ( $sender )
$sender

getAccessTokenRequestOptions() public méthode

Valid options are ConnectTimeout, Timeout, Content-Type and Authorization-Header-Message.
public getAccessTokenRequestOptions ( ) : array
Résultat array

getProfile() public méthode

Get profile data from authentication provider through API.
public getProfile ( ) : array
Résultat array User profile from provider.

getProfileRequestOptions() public méthode

Valid options are ConnectTimeout, Timeout, Content-Type and Authorization-Header-Message.
public getProfileRequestOptions ( ) : array
Résultat array

getProviderKey() public méthode

Get provider key.
public getProviderKey ( ) : string
Résultat string Provider key.

getSettingsFormFields() protected méthode

Allow child class to over-ride or add form fields to settings.
protected getSettingsFormFields ( ) : array
Résultat array Form fields to appear in settings dashboard.

isConfigured() public méthode

Check if there is enough data to connect to an authentication provider.
public isConfigured ( ) : boolean
Résultat boolean True if there is a secret and a client_id, false if not.

isConnected() public méthode

Check if an access token has been returned from the provider server.
public isConnected ( ) : boolean
Résultat boolean True of there is an accessToken, fals if there is not.

isDefault() public méthode

Check authentication provider table to see if this is the default method for logging in.
public isDefault ( ) : boolean
Résultat boolean Return the value of the IsDefault row of GDN_UserAuthenticationProvider .

log() public méthode

public log ( $message, $data )

provider() public méthode

Return all the information saved in provider table.
public provider ( ) : array
Résultat array Stored provider data (secret, client_id, etc.).

requestAccessToken() public méthode

Request access token from provider.
public requestAccessToken ( string $code ) : mixed
$code string code returned from initial handshake with provider.
Résultat mixed Result of the API call to the provider, usually JSON.

requireVal() public méthode

Extract values from arrays.
public requireVal ( string $key, array $arr, string $context = null ) : mixed
$key string Needle.
$arr array Haystack.
$context string Context to make error messages clearer.
Résultat mixed Extracted value from array.

setAccessToken() public méthode

Set access token received from provider.
public setAccessToken ( string $accessToken )
$accessToken string Retrieved from provider to authenticate communication.

setAuthorizeUriParams() public méthode

Set additional params to be added to the get string in the AuthorizeUri string.
public setAuthorizeUriParams ( $params )

setGetProfileParams() public méthode

Set additional params to be added to the get string in the getProfile request.
public setGetProfileParams ( $params )

setProviderKey() public méthode

Set provider key used to access settings stored in GDN_UserAuthenticationProvider.
public setProviderKey ( string $providerKey )
$providerKey string Key to retrieve provider data hardcoded into child class.

setRequestAccessTokenParams() public méthode

Set additional params to be added to the post array in the accessToken request.
public setRequestAccessTokenParams ( $params )

setScope() public méthode

Set scope to be passed to provider.
public setScope ( $scope )

settingsEndpoint() public méthode

Create a controller to deal with plugin settings in dashboard.
public settingsEndpoint ( $sender, $args )

setup() public méthode

Setup
public setup ( )

signInButton() public méthode

Create signup button specific to this plugin.
public signInButton ( string $type = 'button' ) : string
$type string Either button or icon to be output.
Résultat string Resulting HTML element (button).

structure() public méthode

Create the structure in the database.
public structure ( )

translateProfileResults() public méthode

Allow the admin to input the keys that their service uses to send data.
public translateProfileResults ( array $rawProfile = [] ) : array
$rawProfile array profile as it is returned from the provider.
Résultat array Profile array transformed by child class or as is.

Property Details

$accessToken protected_oe property

token provider by authenticator
protected $accessToken

$authorizeUriParams protected_oe property

optional additional get parameters to be passed in the authorize_uri
protected $authorizeUriParams

$defaultContentType protected_oe property

content type for API calls
protected $defaultContentType

$profileRequestParams protected_oe property

optional additional get params to be passed in the request for profile
protected $profileRequestParams

$provider protected_oe property

stored information to connect with provider (secret, etc.)
protected $provider

$providerKey protected_oe property

key for GDN_UserAuthenticationProvider table
protected $providerKey

$requestAccessTokenParams protected_oe property

optional additional post parameters to be passed in the accessToken request
protected $requestAccessTokenParams

$scope protected_oe property

passing scope to authenticator
protected $scope

$settingsView protected_oe property

protected $settingsView