Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Oauth1 Client Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Fetch temporary credentials (request token), store them in the session, and redirect the user to the provider’s authorization URL via $server->authorize($temporaryCredentials).
  2. On callback, retrieve token credentials (access token) using $server->getTokenCredentials(), passing in the stored temporary credentials plus oauth_token and oauth_verifier from the query string.
  3. Use the token credentials to call provider methods like $server->getUserDetails($tokenCredentials) for user info.
    First-time users should review the official examples directory for a working minimal integration.

Implementation Patterns

  • Provider-Specific Options: Leverage provider-specific options during server instantiation (e.g., Trello’s expiration/scope, Twitter’s scope for x_auth_access_type). These are passed to the constructor and injected into authorization requests.
  • Credential Abstraction: Treat all credential types (temporary, token) uniformly via the CredentialsInterface. Store them in sessions, databases, or encrypted cookies—only the identifier and secret matter for requests.
  • Custom Providers: Extend 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.
  • HTTP Client Replacement: Use 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.
  • Laravel Integration: Create a service provider that registers the OAuth server instance and stores credentials in the session. Avoid storing long-lived credentials in plaintext—encrypt before persistence using Laravel’s Crypt facade.
  • API Interaction: While not a full API wrapper, use league/oauth1-client’s getTemporaryCredentials(), getTokenCredentials(), and credential signing to craft signed HTTP requests manually or via League\OAuth1\Client\Signature\Signature with createAuthorizationHeader().

Gotchas and Tips

  • Callback URI Mismatch: Many providers (e.g., Twitter) enforce strict callback URL matching (scheme, host, path, port). Even minor deviations cause failures. Log the exact callback URL used in the session vs. what’s registered with the provider.
  • Session Handling: Always call 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.
  • Legacy Terminology Confusion: Don’t be confused by terms like “access token” vs. “token credentials.” All credential classes have getIdentifier() and getSecret()—use those, not hardcoded property access.
  • Signature Port Handling: Non-standard ports (e.g., 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.
  • PHP 8+ Compatibility: This library was last updated in 2021 but supports PHP 7.1–8.4 (v1.11.0 fixes PHP 8.4 deprecations). Avoid type-hinting @return or constructor types assuming strict compatibility—use loose typing in your classes.
  • No Built-in Token Refresh: OAuth 1 tokens do not expire (or expire very rarely), but providers may invalidate them. Always catch HTTP 401s and re-initiate the OAuth flow if token credentials become invalid.
  • Testing Tip: Use Laravel’s TestResponse::seeInSession() or \PHPUnit\Framework\TestCase::assertArraySubset() to validate stored temporary credentials after redirection in feature tests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport