PHP Класс 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.
Наследование: extends Gdn_Plugin
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$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

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

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

api() защищенный Метод

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).
Результат mixed | type.

assetModel_styleCss_handler() публичный Метод

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

authorizeUri() публичный Метод

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.
Результат string Endpoint of the provider.

base_beforeSignInButton_handler() публичный Метод

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

base_connectData_handler() публичный Метод

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

entryController_overrideSignIn_handler() публичный Метод

Redirect to provider's signin page if this is the default behaviour.
public entryController_overrideSignIn_handler ( $sender, $args ) : mixed | boolean
Результат mixed | boolean Return null if not configured.

entryController_signIn_handler() публичный Метод

Inject sign-in button into the sign in page.
public entryController_signIn_handler ( $sender, $args ) : mixed | boolean
Результат mixed | boolean Return null if not configured

entryEndpoint() публичный Метод

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() публичный Метод

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() публичный Метод

Valid options are ConnectTimeout, Timeout, Content-Type and Authorization-Header-Message.
public getAccessTokenRequestOptions ( ) : array
Результат array

getProfile() публичный Метод

Get profile data from authentication provider through API.
public getProfile ( ) : array
Результат array User profile from provider.

getProfileRequestOptions() публичный Метод

Valid options are ConnectTimeout, Timeout, Content-Type and Authorization-Header-Message.
public getProfileRequestOptions ( ) : array
Результат array

getProviderKey() публичный Метод

Get provider key.
public getProviderKey ( ) : string
Результат string Provider key.

getSettingsFormFields() защищенный Метод

Allow child class to over-ride or add form fields to settings.
protected getSettingsFormFields ( ) : array
Результат array Form fields to appear in settings dashboard.

isConfigured() публичный Метод

Check if there is enough data to connect to an authentication provider.
public isConfigured ( ) : boolean
Результат boolean True if there is a secret and a client_id, false if not.

isConnected() публичный Метод

Check if an access token has been returned from the provider server.
public isConnected ( ) : boolean
Результат boolean True of there is an accessToken, fals if there is not.

isDefault() публичный Метод

Check authentication provider table to see if this is the default method for logging in.
public isDefault ( ) : boolean
Результат boolean Return the value of the IsDefault row of GDN_UserAuthenticationProvider .

log() публичный Метод

public log ( $message, $data )

provider() публичный Метод

Return all the information saved in provider table.
public provider ( ) : array
Результат array Stored provider data (secret, client_id, etc.).

requestAccessToken() публичный Метод

Request access token from provider.
public requestAccessToken ( string $code ) : mixed
$code string code returned from initial handshake with provider.
Результат mixed Result of the API call to the provider, usually JSON.

requireVal() публичный Метод

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.
Результат mixed Extracted value from array.

setAccessToken() публичный Метод

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

setAuthorizeUriParams() публичный Метод

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

setGetProfileParams() публичный Метод

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

setProviderKey() публичный Метод

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() публичный Метод

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

setScope() публичный Метод

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

settingsEndpoint() публичный Метод

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

setup() публичный Метод

Setup
public setup ( )

signInButton() публичный Метод

Create signup button specific to this plugin.
public signInButton ( string $type = 'button' ) : string
$type string Either button or icon to be output.
Результат string Resulting HTML element (button).

structure() публичный Метод

Create the structure in the database.
public structure ( )

translateProfileResults() публичный Метод

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.
Результат array Profile array transformed by child class or as is.

Описание свойств

$accessToken защищенное свойство

token provider by authenticator
protected $accessToken

$authorizeUriParams защищенное свойство

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

$defaultContentType защищенное свойство

content type for API calls
protected $defaultContentType

$profileRequestParams защищенное свойство

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

$provider защищенное свойство

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

$providerKey защищенное свойство

key for GDN_UserAuthenticationProvider table
protected $providerKey

$requestAccessTokenParams защищенное свойство

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

$scope защищенное свойство

passing scope to authenticator
protected $scope

$settingsView защищенное свойство

protected $settingsView