league/oauth1-client
RFC 5849-compliant OAuth 1.0 client library for PHP (7.1+). Authenticate with OAuth 1 servers and make signed requests. Built-in providers include Twitter, Trello, Tumblr, Bitbucket, Magento, Uservoice, and Xing; easy to add more.
Start by installing the package via Composer: composer require league/oauth1-client. Then pick a built-in provider (e.g., League\OAuth1\Client\Server\Twitter) and instantiate it with your client credentials (identifier, secret) and a callback_uri. The core OAuth flow has three steps:
$server->authorize($temporaryCredentials).$server->getTokenCredentials(), passing in the stored temporary credentials plus oauth_token and oauth_verifier from the query string.$server->getUserDetails($tokenCredentials) for user info.expiration/scope, Twitter’s scope for x_auth_access_type). These are passed to the constructor and injected into authorization requests.temporary, token) uniformly via the CredentialsInterface. Store them in sessions, databases, or encrypted cookies—only the identifier and secret matter for requests.League\OAuth1\Client\Server\Server for unsupported providers. Implement only required methods (getTemporaryCredentialsUrl(), getAuthorizationUrl(), getTokenCredentialsUrl(), getUserDetails()). Define the resource owner details endpoint and return user info.setHttpClient() to inject a custom PSR-18 client or Guzzle instance (supports Guzzle 6+). This is essential in Laravel for integration with HttpClient or middleware.Crypt facade.league/oauth1-client’s getTemporaryCredentials(), getTokenCredentials(), and credential signing to craft signed HTTP requests manually or via League\OAuth1\Client\Signature\Signature with createAuthorizationHeader().session_write_close() before redirecting to prevent session lock—especially critical in Laravel apps using Horizon or queues. Omitting this can cause deadlocks in PHP-FPM.getIdentifier() and getSecret()—use those, not hardcoded property access.http://localhost:8080) affect signature base string generation. Version 1.8.2+ fixes this—ensure you’re on v1.8.2 or later if using non-standard ports.@return or constructor types assuming strict compatibility—use loose typing in your classes.TestResponse::seeInSession() or \PHPUnit\Framework\TestCase::assertArraySubset() to validate stored temporary credentials after redirection in feature tests.How can I help you explore Laravel packages today?