Oauth2BasicAuthentication
in package
implements
AuthenticationMethodInterface
The <a href="https://tools.ietf.org/html/rfc6749">Oauth2 authentication</a> using a <a href="https://tools.ietf.org/html/rfc2617#section-2">Basic authentication</a> to get the access token.
Interfaces, Classes, Traits and Enums
- AuthenticationMethodInterface
- The authentication method interface.
Table of Contents
- $grantType : mixed
- $password : mixed
- $scope : mixed
- $token : mixed
- $tokenEndPointUrl : mixed
- $userid : mixed
- __construct() : mixed
- The Oauth2 authentication method using the Basic authorization header composed of a userid and a password.
- __set() : mixed
- The magic setter is overridden to insure immutability.
- authorizeRequest() : Request
- Adds the authorization header to the request with a valid token.
- getGrantType() : string
- getPassword() : string
- getScope() : string
- getToken() : ExpirableToken
- getTokenEndPointUrl() : string
- getUserid() : string
- getAccessToken() : mixed
- Sends a request for an access token.
- getTime() : int
- It is important to use the same method when setting the expiration time and checking if it is still valid.
- isRequestAuthorized() : bool
- isTokenStillValid() : bool
- Checks if the token is till valid at the time this method is called.
Properties
$grantType
private
mixed
$grantType
$password
private
mixed
$password
$scope
private
mixed
$scope
$token
private
mixed
$token
$tokenEndPointUrl
private
mixed
$tokenEndPointUrl
$userid
private
mixed
$userid
Methods
__construct()
The Oauth2 authentication method using the Basic authorization header composed of a userid and a password.
public
__construct(string $tokenEndPointUrl, string $userid, string $password[, string $scope = 'api' ][, string $grantType = 'client_credentials' ][, ExpirableToken $token = null ]) : mixed
Parameters
- $tokenEndPointUrl : string
- $userid : string
- $password : string
- $scope : string = 'api'
-
(default to "api")
- $grantType : string = 'client_credentials'
-
(default to "client_credentials")
- $token : ExpirableToken = null
-
(optional)
Return values
mixed —__set()
The magic setter is overridden to insure immutability.
public
__set( $name, $value) : mixed
Parameters
Return values
mixed —authorizeRequest()
Adds the authorization header to the request with a valid token.
public
authorizeRequest(HapiClient $hapiClient, Request $request) : Request
If we do not have a valid token yet, we send a request for one.
Parameters
- $hapiClient : HapiClient
-
The client used to send the request
- $request : Request
-
The request before it is sent
Tags
Return values
Request —the same Request with the authorization Headers
getGrantType()
public
getGrantType() : string
Return values
string —the grant_type parameter
getPassword()
public
getPassword() : string
Return values
string —the second part of the oauth2 authentication
getScope()
public
getScope() : string
Return values
string —the scope parameter
getToken()
public
getToken() : ExpirableToken
Return values
ExpirableToken —the last token used
getTokenEndPointUrl()
public
getTokenEndPointUrl() : string
Return values
string —the API server authentication end point
getUserid()
public
getUserid() : string
Return values
string —the first part of the oauth2 authentication
getAccessToken()
Sends a request for an access token.
private
getAccessToken(HapiClient $hapiClient) : mixed
Parameters
- $hapiClient : HapiClient
-
The client used to send the request
Tags
Return values
mixed —getTime()
It is important to use the same method when setting the expiration time and checking if it is still valid.
private
getTime() : int
Return values
int —The current time in seconds
isRequestAuthorized()
private
isRequestAuthorized(Request $request) : bool
Parameters
- $request : Request
-
The request before it is sent
Return values
bool —false if the request needs to be authorized
isTokenStillValid()
Checks if the token is till valid at the time this method is called.
private
isTokenStillValid() : bool