Download the PHP package radweb/oauth-token-encoding without Composer
On this page you can find all versions of the php package radweb/oauth-token-encoding. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download radweb/oauth-token-encoding
More information about radweb/oauth-token-encoding
Files in radweb/oauth-token-encoding
Package oauth-token-encoding
Short Description Alternate Encoding for OAuth 2 Token Responses
License MIT
Informations about the package oauth-token-encoding
OAuth 2 Token Encoder
The OAuth 2 spec specifies token responses should be JSON. However XML users will be XML users so there's a draft spec extension which defines how OAuth responses should look in XML and Form Encoded formats:
https://tools.ietf.org/html/draft-richer-oauth-xml-01
Installation
Usage
There's a basic Radweb\OAuthTokenEncoding\OAuthTokenEncoder
class which when given an Accept
header and an array representing an OAuth token, will respond with the correct Content-Type
header and the correctly encoded OAuth token.
There's also adaptors for common libraries which will respond with a correct Response object:
OAuthTokenIlluminateAdaptor
for LaravelOAuthTokenSymfonyAdaptor
for SymfonyOAuthTokenPsrAdaptor
for any PSR-7 compatible libraries (although uses theZend\Diactoros
package as the implementation for the PSR-7 response)
Finally, if you're using the League\OAuth2\Server
package, there's a compatible LeagueOAuthExceptionFormatter
class for formatting exceptions from that library. If you're using it with Laravel, there's also LaravelOAuthExceptionHandlingMiddleware
for doing that automatically.
Basic Usage
With League's OAuth 2 Server
The format returned by League\OAuth2\Server\AuthorizationServer
's issueAccessToken
method can be passed through to the encoder.
With Laravel / Lumen
Given an Illuminate\Http\Request
object, the adaptor will check the Accept
header of the request for application/json
, application/xml
or application/x-www-form-urlencoded
. If none are found, it assumes JSON.
The response will contain the correctly encoded body, the correct Content-Type
header and the Cache-Control: no-store
header.
With Laravel OAuth 2 Server
The format returned by League\OAuth2\Server\AuthorizationServer
's issueAccessToken
method can be passed through to the encoder.
With PSR-7
To construct a response, the
zendframework/zend-diactoros
package is required.
Given a PSR-7 request, the adaptor will check the Accept
header of the request for application/json
, application/xml
or application/x-www-form-urlencoded
. If none are found, it assumes JSON.
The response will contain the correctly encoded body, the correct Content-Type
header and the Cache-Control: no-store
header.
Errors
If you're using Laravel OAuth 2 Server you can use the LaravelOAuthExceptionHandlingMiddleware
instead of the one provided in that package.