PHP Class BaiduOAuth2, thinksns

Author: zhujianting([email protected])
Show file Open project: medz/thinksns-4 Class Usage Examples

Public Properties

Property Type Description
$BD_OAUTH2_ENDPOINTS Endpoints for Baidu OAuth2.0.

Protected Properties

Property Type Description
$clientId
$clientSecret
$redirectUri

Public Methods

Method Description
__construct ( string $clientId, string $clientSecret ) Constructor
getAccessTokenByAuthorizationCode ( string $code ) : array | false Get access token ifno by authorization code.
getAccessTokenByClientCredentials ( string $scope = '' ) : array | false Get access token info by client credentials.
getAccessTokenByDeveloperCredentials ( string $accessKey, string $secretKey ) : array | false Get access token info by developer credentials
getAccessTokenByRefreshToken ( string $refreshToken, string $scope = '' ) : array | false Refresh access token by refresh token.
getAuthorizeUrl ( string $responseType = 'code', string $scope = '', string $state = '', string $display = 'popup' ) : string Get baidu oauth2's authorization granting url.
getLogoutUrl ( string $accessToken, string $next = '' ) : String Get a Logout URL suitable for use with redirects.
getRedirectUri ( ) : string Get the redirect uri for the app.
makeAccessTokenRequest ( array $params ) : mixed Make an oauth access token request
setRedirectUri ( $redirectUri ) : BaiduOAuth2 Set the redirect uri for the app.

Method Details

__construct() public method

Constructor
public __construct ( string $clientId, string $clientSecret )
$clientId string Client_id of the baidu thirdparty app or access_key of the developer.
$clientSecret string Client_secret of the baidu thirdparty app or secret_key of the developer.

getAccessTokenByAuthorizationCode() public method

Get access token ifno by authorization code.
public getAccessTokenByAuthorizationCode ( string $code ) : array | false
$code string Authorization code
return array | false returns access token info if success, or false if failed

getAccessTokenByClientCredentials() public method

Get access token info by client credentials.
public getAccessTokenByClientCredentials ( string $scope = '' ) : array | false
$scope string Extend permissions delimited by blank space
return array | false returns access token info if success, or false if failed.

getAccessTokenByDeveloperCredentials() public method

Get access token info by developer credentials
public getAccessTokenByDeveloperCredentials ( string $accessKey, string $secretKey ) : array | false
$accessKey string Access key you got from baidu cloud platform
$secretKey string Secret key you got from baidu cloud platform
return array | false Returns access token info if success, or false if failed

getAccessTokenByRefreshToken() public method

Refresh access token by refresh token.
public getAccessTokenByRefreshToken ( string $refreshToken, string $scope = '' ) : array | false
$refreshToken string The refresh token
$scope string Extend permissions delimited by blank space
return array | false returns access token info if success, or false if failed.

getAuthorizeUrl() public method

Get baidu oauth2's authorization granting url.
public getAuthorizeUrl ( string $responseType = 'code', string $scope = '', string $state = '', string $display = 'popup' ) : string
$responseType string Response type, 'code' or 'token'
$scope string blank space separated list of requested extended perms
$state string state parameter
$display string Authorization page style, 'page', 'popup', 'touch' or 'mobile'
return string Page url for authorization granting

getLogoutUrl() public method

Get a Logout URL suitable for use with redirects.
public getLogoutUrl ( string $accessToken, string $next = '' ) : String
$accessToken string Access token for current user
$next string Url to go to after a successful logout
return String The URL for the logout flow

getRedirectUri() public method

Get the redirect uri for the app.
public getRedirectUri ( ) : string
return string

makeAccessTokenRequest() public method

The parameters: - client_id: The client identifier, just use api key - response_type: 'token' or 'code' - redirect_uri: the url to go to after a successful login - scope: The scope of the access request expressed as a list of space-delimited, case sensitive strings. - state: An opaque value used by the client to maintain state between the request and callback. - display: login page style, 'page', 'popup', 'touch' or 'mobile'
public makeAccessTokenRequest ( array $params ) : mixed
$params array oauth request parameters
return mixed returns access token info if success, or false if failed

setRedirectUri() public method

Set the redirect uri for the app.
public setRedirectUri ( $redirectUri ) : BaiduOAuth2
$redirectUri Where to redirect after user authorization.
return BaiduOAuth2

Property Details

$BD_OAUTH2_ENDPOINTS public static property

Endpoints for Baidu OAuth2.0.
public static $BD_OAUTH2_ENDPOINTS

$clientId protected property

protected $clientId

$clientSecret protected property

protected $clientSecret

$redirectUri protected property

protected $redirectUri