PHP Class EAuthServiceBase

Inheritance: extends CComponent, implements IAuthService
Show file Open project: nodge/yii-eauth Class Usage Examples

Protected Properties

Property Type Description
$attributes authorization attributes.
$authenticated whether user was successfuly authenticated.
$jsArguments arguments for the jQuery.eauth() javascript function.
$name the service name.
$title the service title to display in views.
$type the service type (e.g. OpenID, OAuth).

Public Methods

Method Description
__get ( string $name ) : mixed PHP getter magic method.
__isset ( string $name ) : boolean Checks if a attribute value is null.
authenticate ( ) : boolean Authenticate the user.
cancel ( $url = null ) Redirect to the {@link cancelUrl} or simply close the popup window.
getAttribute ( string $key, mixed $default = null ) : mixed Returns the authorization attribute value.
getAttributes ( ) : array Returns the array that contains all available authorization attributes.
getCancelUrl ( ) : string Returns the redirect url after unsuccessful authorization (e.g. user canceled).
getComponent ( ) : EAuth Returns the {@link EAuth} application component.
getId ( ) : mixed Returns the user unique id.
getIsAuthenticated ( ) : boolean Whether user was successfuly authenticated.
getItem ( ) : stdClass Returns the object with a human-readable representation of the current authorization.
getItemAttributes ( ) : array Returns the array that contains all available authorization attributes.
getJsArguments ( ) : array Returns arguments for the jQuery.eauth() javascript function.
getRedirectUrl ( ) : string Returns the redirect url after successful authorization.
getServiceName ( ) : string Returns service name(id).
getServiceTitle ( ) : string Returns service title.
getServiceType ( ) : string Returns service type (e.g. OpenID, OAuth).
hasAttribute ( string $key ) : boolean Whether the authorization attribute exists.
init ( EAuth $component, array $options = [] ) Initialize the component.
redirect ( string $url = null, array $params = [] ) Redirect to the url. If url is null, {@link redirectUrl} will be used.
setCancelUrl ( $url ) Sets redirect url after unsuccessful authorization (e.g. user canceled).
setComponent ( EAuth $component ) Sets {@link EAuth} application component
setRedirectUrl ( $url ) Sets redirect url after successful authorization.

Protected Methods

Method Description
_fetchAttributes ( ) Fetch attributes array.
fetchAttributes ( ) : boolean Fetch attributes array.
fetchJsonError ( stdClass $json ) : array Returns the error info from json.
getState ( string $key, mixed $defaultValue = null ) : mixed Returns the value of a variable that is stored in eauth session.
getStateKeyPrefix ( ) : string
hasState ( string $key ) : boolean Returns a value indicating whether there is a state of the specified name.
initRequest ( string $url, array $options = [] ) : cURL Initializes a new session and return a cURL handle.
makeRequest ( string $url, array $options = [], boolean $parseJson = true ) : stdClass Makes the curl request to the url.
parseJson ( string $response ) : object Parse response from {@link makeRequest} in json format and check OAuth errors.
setState ( string $key, mixed $value, mixed $defaultValue = null ) Stores a variable in eauth session.

Method Details

__get() public method

This method is overridden so that service attributes can be accessed like properties.
See also: getAttribute
public __get ( string $name ) : mixed
$name string property name.
return mixed property value.

__isset() public method

This method overrides the parent implementation by checking if the attribute is null or not.
public __isset ( string $name ) : boolean
$name string the attribute name.
return boolean whether the attribute value is null.

_fetchAttributes() protected method

This function is internally used to handle fetched state.
protected _fetchAttributes ( )

authenticate() public method

Authenticate the user.
public authenticate ( ) : boolean
return boolean whether user was successfuly authenticated.

cancel() public method

Redirect to the {@link cancelUrl} or simply close the popup window.
public cancel ( $url = null )

fetchAttributes() protected method

Fetch attributes array.
protected fetchAttributes ( ) : boolean
return boolean whether the attributes was successfully fetched.

fetchJsonError() protected method

Returns the error info from json.
protected fetchJsonError ( stdClass $json ) : array
$json stdClass the json response.
return array the error array with 2 keys: code and message. Should be null if no errors.

getAttribute() public method

Returns the authorization attribute value.
public getAttribute ( string $key, mixed $default = null ) : mixed
$key string the attribute name.
$default mixed the default value.
return mixed the attribute value.

getAttributes() public method

Returns the array that contains all available authorization attributes.
public getAttributes ( ) : array
return array the attributes.

getCancelUrl() public method

Returns the redirect url after unsuccessful authorization (e.g. user canceled).
public getCancelUrl ( ) : string
return string the redirect url after unsuccessful authorization (e.g. user canceled).

getComponent() public method

Returns the {@link EAuth} application component.
public getComponent ( ) : EAuth
return EAuth the {@link EAuth} application component.

getId() public method

Returns the user unique id.
public getId ( ) : mixed
return mixed the user id.

getIsAuthenticated() public method

Whether user was successfuly authenticated.
public getIsAuthenticated ( ) : boolean
return boolean whether user was successfuly authenticated.

getItem() public method

Returns the object with a human-readable representation of the current authorization.
public getItem ( ) : stdClass
return stdClass the object.

getItemAttributes() public method

Returns the array that contains all available authorization attributes.
Deprecation: because getAttributes is more semantic.
public getItemAttributes ( ) : array
return array the attributes.

getJsArguments() public method

Returns arguments for the jQuery.eauth() javascript function.
public getJsArguments ( ) : array
return array the arguments for the jQuery.eauth() javascript function.

getRedirectUrl() public method

Returns the redirect url after successful authorization.
public getRedirectUrl ( ) : string
return string the redirect url after successful authorization.

getServiceName() public method

Returns service name(id).
public getServiceName ( ) : string
return string the service name(id).

getServiceTitle() public method

Returns service title.
public getServiceTitle ( ) : string
return string the service title.

getServiceType() public method

Returns service type (e.g. OpenID, OAuth).
public getServiceType ( ) : string
return string the service type (e.g. OpenID, OAuth).

getState() protected method

Returns the value of a variable that is stored in eauth session.
See also: setState
protected getState ( string $key, mixed $defaultValue = null ) : mixed
$key string variable name.
$defaultValue mixed default value.
return mixed the value of the variable. If it doesn't exist in the session, the provided default value will be returned.

getStateKeyPrefix() protected method

protected getStateKeyPrefix ( ) : string
return string a prefix for the name of the session variables storing eauth session data.

hasAttribute() public method

Whether the authorization attribute exists.
public hasAttribute ( string $key ) : boolean
$key string the attribute name.
return boolean true if attribute exists, false otherwise.

hasState() protected method

Returns a value indicating whether there is a state of the specified name.
protected hasState ( string $key ) : boolean
$key string state name.
return boolean whether there is a state of the specified name.

init() public method

Sets the default {@link redirectUrl} and {@link cancelUrl}.
public init ( EAuth $component, array $options = [] )
$component EAuth the component instance.
$options array properties initialization.

initRequest() protected method

Initializes a new session and return a cURL handle.
protected initRequest ( string $url, array $options = [] ) : cURL
$url string url to request.
$options array HTTP request options. Keys: query, data, referer.
return cURL handle.

makeRequest() protected method

Makes the curl request to the url.
protected makeRequest ( string $url, array $options = [], boolean $parseJson = true ) : stdClass
$url string url to request.
$options array HTTP request options. Keys: query, data, referer.
$parseJson boolean Whether to parse response in json format.
return stdClass the response.

parseJson() protected method

Parse response from {@link makeRequest} in json format and check OAuth errors.
protected parseJson ( string $response ) : object
$response string Json string.
return object result.

redirect() public method

Redirect to the url. If url is null, {@link redirectUrl} will be used.
public redirect ( string $url = null, array $params = [] )
$url string url to redirect.
$params array

setCancelUrl() public method

Sets redirect url after unsuccessful authorization (e.g. user canceled).
public setCancelUrl ( $url )

setComponent() public method

Sets {@link EAuth} application component
public setComponent ( EAuth $component )
$component EAuth the application auth component.

setRedirectUrl() public method

Sets redirect url after successful authorization.
public setRedirectUrl ( $url )

setState() protected method

Stores a variable in eauth session.
See also: getState
protected setState ( string $key, mixed $value, mixed $defaultValue = null )
$key string variable name.
$value mixed variable value.
$defaultValue mixed default value. If $value===$defaultValue, the variable will be removed from the session.

Property Details

$attributes protected property

authorization attributes.
See also: getAttribute
See also: getItem
protected $attributes

$authenticated protected property

whether user was successfuly authenticated.
See also: getIsAuthenticated
protected $authenticated

$jsArguments protected property

arguments for the jQuery.eauth() javascript function.
protected $jsArguments

$name protected property

the service name.
protected $name

$title protected property

the service title to display in views.
protected $title

$type protected property

the service type (e.g. OpenID, OAuth).
protected $type