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
显示文件 Open project: vanilla/vanilla

Protected Properties

Property 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

Public Methods

Method 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.

Protected Methods

Method 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 method

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 method

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

api() protected method

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).
return mixed | type.

assetModel_styleCss_handler() public method

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

authorizeUri() public method

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.
return string Endpoint of the provider.

base_beforeSignInButton_handler() public method

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

base_connectData_handler() public method

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

entryController_overrideSignIn_handler() public method

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

entryController_signIn_handler() public method

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

entryEndpoint() public method

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 method

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 method

Valid options are ConnectTimeout, Timeout, Content-Type and Authorization-Header-Message.

getProfile() public method

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

getProfileRequestOptions() public method

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

getProviderKey() public method

Get provider key.
public getProviderKey ( ) : string
return string Provider key.

getSettingsFormFields() protected method

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

isConfigured() public method

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

isConnected() public method

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

isDefault() public method

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

log() public method

public log ( $message, $data )

provider() public method

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

requestAccessToken() public method

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

requireVal() public method

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.
return mixed Extracted value from array.

setAccessToken() public method

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

setAuthorizeUriParams() public method

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

setGetProfileParams() public method

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

setProviderKey() public method

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 method

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

setScope() public method

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

settingsEndpoint() public method

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

setup() public method

Setup
public setup ( )

signInButton() public method

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

structure() public method

Create the structure in the database.
public structure ( )

translateProfileResults() public method

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.
return 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