OAuthClient class


Description

Class with the OAuth Client Application logic.

Class Constants

  • HEADER: HTTP_Authorization_Header
  • GET: URI_Query_Parameter
  • BODY: Form-Encoded_Body_Parameter

Class Variables

  • String access_token: Access Token generated by the Authorization Server
  • String client_id: Client Identification
  • String client_secret: Client Shared Secret
  • Boolean debug_active: If TRUE, the debug is active, inactive otherwise.
  • String error: Error code-name
  • Integer expires_in: Lifetime of the access token. 3600s by default.
  • String request_type: Type of request that the Client makes to the Resource Server (Defined by the constants HEADER, GET or BODY).
  • String resource: The obtained resource.
  • String scope-ret: Scope parameter returned by the Authorization Server.

Methods

PUBLIC OAuthClient __construct($clientid, $clientsecret, [ $debug = false])

OAuthClient class Constructor

  • String clientid: Client Identification
  • String clientsecret: Client Shared Secret.
  • Boolean debug: If TRUE actives the debug. FALSE by default./li>

Return an OAuthClient Object

PRIVATE cleanHeader($string): string

Auxiliar function that clean the server response header.

Returns the cleaned response.

  • String string: Header.

PRIVATE doAccessTokenRequest($as, $scope, $assertion, $assertion_type, [$grant_type = "assertion"]): Boolean

Function that mades theaccess token request to the AS.

Returns TRUE if the request obtained an Access Token, FALSE otherwise.

  • String as: The Authorization Server URL
  • String scope: The scope of the access request.
  • String assertion The assertion
  • String assertion_type: The format of the assertion as defined by the authorization server.
  • String grant_type: The access grant type included in the request.

PRIVATE doATRequest($as, $request): Boolean

Makes the HTTP POST CURL connection to request the access token from the authorization server.

Stores the access token in the protected param 'access_token'. If an error occurs, it stores the error in the protected param 'error'.

Returns True if the Auth server response has an access token

  • String as: The Authorization Server URL
  • Array request: The request data

PRIVATE doBodyResRequest($rs, $request): Boolean

Makes connection to request the resource with a Form-Encoded Body Parameter.

When including the access token in the HTTP request entity-body, the client adds the access token to the request body using the "oauth_token" parameter. The entity-body can include other request-specific parameters, in which case, the "oauth_token" parameters SHOULD be appended following the request-specific parameters, properly separated by an "&".

Returns TRUE if the request obtained the resource, FALSE otherwise.

  • String rs: The Resource Server URL
  • Array request: The request data

PRIVATE doGetResRequest($rs, $request): Boolean

Makes connection to request the resource with a URI Query Parameter.

When including the access token in the HTTP request uri, the client adds the access token to the request URI query component as defined by [RFC3986] using the "oauth_token" parameter. The HTTP request URI query can include other request-specific parameters, in which case, the "oauth_token" parameters SHOULD be appended following the request-specific parameters, properly separated by an "&".

Returns TRUE if the request obtained the resource, FALSE otherwise.

  • String rs: The Resource Server URL
  • Array request: The request data

PRIVATE doHeaderResRequest($rs, $request): Boolean

Makes connection to request the resource with an Authorization Request Header Field.

The "Authorization" request header field is used by clients to make authenticated token requests. The client uses the "token" attribute to include the access token in the request.

Returns TRUE if the request obtained the resource, FALSE otherwise.

  • String rs: The Resource Server URL
  • Array request: The request data

PRIVATE doResourceRequest($rs, $request_type, $request): Boolean

Function that makes the resource request to the Resource server.

Returns TRUE if the request obtained the resource, FALSE otherwise.

  • String rs: The Resource Server URL
  • Array request: The request data
  • String request_type: The request type. It could be GET, BODY, or HEADER.

PRIVATE error($string): void

Function that shows the errors in the error_log if $debug_active is TRUE.

  • String string: String showed in the error_log.

PRIVATE generateATRequest($scope, $assertion, $assertion_type, $grant_type): Array

Generates an access token request.

Returns the request Array.

  • String scope: The scope of the access request.
  • String assertion The assertion
  • String assertion_type: The format of the assertion as defined by the authorization server.
  • String grant_type: The access grant type included in the request.

PRIVATE generateResourceRequest($extra): Array

Generates the array of the resource request.

Returns the parameters of the request.

  • Array extra Array with extra parameters.

PUBLIC getAccess_token(): String

Returns the obtained access token.

PUBLIC getExpires_in(): Integer

Returns the lifetime of the token.

PUBLIC getHTMLError(): String

Returns the error in HTML format.

PUBLIC getJSONError(): String

Returns the error in JSON format.

PUBLIC getResource(): string

Returns the resource.

PRIVATE isntHTTPS($url): Boolean

Function that checks if and url is https or http

Returns TRUE if it is http, FALSE if it is https.

  • String url:URL to check.

PRIVATE processAuthServerResponse($info, $output): Boolean

Manages the Auth server response.

Returns TRUE if the Auth server response has an access token, FALSE otherwise.

  • Array info:Info of the CURL response.
  • String output:Output of the CURL response.

PRIVATE processResServerResponse($info, $output): Boolean

Manages the resource server response.

Returns TRUE if the Auth server response has a resource, FALSE otherwise.

  • Array info:Info of the CURL response.
  • String output:Output of the CURL response.

PUBLIC requestResource($rs, $request_type, [$extra = null])): Boolean

Function that manages the request to the resource server.

Returns TRUE if the request obtained the resource, FALSE otherwise.

  • String rs: The Resource Server URL
  • Array extra: Extra parameters added in case of necessity. Initialized by default to null.
  • String request_type: The request type. It could be GET, BODY, or HEADER.