OAuth class
Description
Class that makes an abstraction to the OAuth Authorization Flow in order to simplify to developers the implementation.
Class Constants
- HEADER: HTTP_Authorization_Header
- GET: URI_Query_Parameter
- BODY: Form-Encoded_Body_Parameter
- SAML2: urn:oasis:names:tc:SAML:2.0:assertion
- PAPI: urn:mace:rediris.es:papi
- HTML: HTML
- JSON: JSON
Class Variables
- String assertion_type: Type of the assertion (Defined by the constants PAPI or SAML2). By default PAPI.
- 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
- String error-type: Error type. Defined by the constants HTML or JSON. By default HTML.
- String as: Authorization Server URL.
- String rs: Resource Server URL.
- String request_type: Type of request that the Client makes to the Resource Server (Defined by the constants HEADER, GET or BODY).By default HEADER.
- String resource: The obtained resource.
- String grant_type: The access grant type included in the request. In this library the type is "assertion".
- String scope: Scope of the request.
- String conf: LoadConfig object.
Methods
OAuth __construct ([ $dir = ""])
Public OAuth Class Constructor.
- String dir: Directory where the client configuration is located.
Return an OAuth Object
PUBLIC doOAuthFlow($assertion): boolean
Function that gets the resource with an OAuth2 flow and stores it in the 'resource' parameter. (And it could be accesed by the method getResource)
Return a boolean: True if the flow went ok, false otherwise. The error description is stored in the 'error' parameter
- String assertion:String with the assertion provided (SAML2 or PAPI)
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.
PUBLIC getAs(): string
Returns the Authorization Server URL.
PUBLIC getAssertion_type(): string
Returns the type of the assertion. It could be PAPI or SAML2.
PUBLIC getClient_id(): string
Returns the Client Identificator.
PUBLIC getClient_secret(): string
Returns the Client Secret.
PUBLIC getDefault_scope(): string
Returns the default_scope.
PUBLIC getError(): string
Returns the error description.
PUBLIC getError_type(): string
Returns the error type.
PUBLIC getGrant_type(): string
Returns the grant_type.
PUBLIC getRequest_type(): string
Returns the request type.
PUBLIC getResource(): string
Returns the resource.
PUBLIC getRs(): string
Returns the resource server URL.
PUBLIC getScope(): string
Returns the scope.
PUBLIC returnError($oauth): string
Function that given an OAuthClient object, formats the obtained error depending on the selected type in the OAuth class: If it is HTML returns an html with the message inside of the div element:
<div class="error"> $error_msg <div>If it is JSON returns a json element with the following format:
{"error":"error_description"}
- OAuthClient oauth: OAuthClient object.
PUBLIC returnResource($oauth): string
Function that given an OAuthClient object, formats the corresponding response depending on the scope of the request. Returns a String with the formatted response.
- OAuthClient oauth: OAuthClient object.
PUBLIC setAs($url_as): void
Sets the Authorization Server URL
- String url_as: URL of the OAuth authorization server.
PUBLIC setBODYResourceRequest(): void
Sets the resource request type to a POST request.
PUBLIC setGETResourceRequest(): void
Sets the resource request type to a GET request.
PUBLIC setGrant_type($grant_type): void
Sets the grant_type with the parameter $grant_type.The access grant type must be one of "authorization-code", "basic-credentials", "assertion", "refresh-token", or "none".
- String grant_type: Grant type
PUBLIC setHEADERResourceRequest(): void
Sets the resource request type to a Authorization HEADER request.
PUBLIC setHTMLErrorResponse(): void
Set the error response type (error_type parameter) to HTML
PUBLIC setJSONErrorResponse(): void
Sets the error response type (error_type parameter) to JSON
PUBLIC setPAPIAssertionType(): void
Sets the assertion_type parameter to PAPI
PUBLIC setRs($url_rs): void
Sets the Resource Server URL.
- String url_rs: URL of the OAuth resource server.
PUBLIC setSAML2AssertionType(): void
Sets the assertion_type parameter to SAML2
PUBLIC setScope($scope): void
Sets the scope with the $scope parameter
- String scope: URI of the scope of the resource.