OAuth2 Authentication
Overview
$authConnector = new SpotifyAuthConnector;
// 1. Redirect the user to the authorization URL...
$authorizationUrl = $authConnector->getAuthorizationUrl($scopes, $state);
// 2. Handle the callback from the API provider and create an access token...
$authenticator = $authConnector->getAccessTokens($code, $state);
// 3. Authenticate your requests!
$request = new GetTracksRequest;
$request->authenticate($authenticator);
$request->send(); // π
// 4. Refresh your access tokens...
$newAuthenticator = $authConnector->refreshAccessTokens($authenticator);Prerequisites
Getting Setup
1. Add the AuthorizationCodeGrant trait to your connector
2. Configure the base endpoint
3. Configure the default OAuth config
Per-User/Tenant Config
Generating An Authorization URL
Optional State
Creating Access Tokens
Verifying State
Storing Authentication On Users
Authenticate Your Requests
Refreshing Access Tokens
Customising The Authenticator
Customising How The Authenticator Is Created
Per User/Tenant OAuth Config
Real-world example
Controller
Saloon Connector/Requests
Available Methods / API
Connector
OAuth2 Config Methods
Last updated