- How do I install Laravel Socialite for OAuth authentication in my Laravel 10/11/12/13 app?
- Run `composer require laravel/socialite` to install the package. No additional steps are needed for core functionality. Ensure your Laravel app uses PHP 8.1+ and follows the [official installation guide](https://laravel.com/docs/socialite#installation) for provider-specific setup.
- Which OAuth providers are supported out of the box in Laravel Socialite?
- The core package supports GitHub, Google, Facebook, GitLab, LinkedIn, Slack, Twitch, Bitbucket, and X (Twitter). For other providers like Auth0, Okta, or niche platforms, use the community-driven [SocialiteProviders](https://socialiteproviders.com/) package.
- How do I configure Google OAuth with Laravel Socialite?
- Add your Google OAuth credentials to `.env` under `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`. Then, use the `GoogleProvider` in your controller: `$user = Socialite::driver('google')->user()`. Follow the [Google provider docs](https://laravel.com/docs/socialite#google) for scopes and redirect URIs.
- Does Laravel Socialite support OAuth 1.0 (e.g., legacy Twitter/X API) or only OAuth 2.0?
- Socialite supports both OAuth 1.0 (via `league/oauth1-client`) and OAuth 2.0. Twitter/X now uses OAuth 2.0, so update your configuration to use the `TwitterProvider` (or `XProvider` in newer versions). OAuth 1.0 is deprecated for most providers.
- How can I test Laravel Socialite without hitting real OAuth endpoints?
- Use the built-in `FakeProvider` for unit/integration tests. Mock responses with `$provider->setResponse($response)` or use `Socialite::fake()` in your tests. This works seamlessly with PHPUnit and Pest. See the [testing docs](https://laravel.com/docs/socialite#testing) for examples.
- What’s the best way to store OAuth tokens (access/refresh) in production?
- Store tokens in your database (e.g., `users` table) or encrypted session storage. Avoid plaintext `.env` files. Use Laravel’s `encrypt()` helper for sensitive data. For distributed systems, consider Redis or a dedicated cache layer. Refresh tokens should be revoked and cleaned up periodically.
- How do I handle failed OAuth logins (e.g., revoked tokens, rate limits) in Laravel Socialite?
- Wrap Socialite calls in a `try-catch` block to handle exceptions like `InvalidStateException` or `MissingTokenException`. Implement a fallback flow (e.g., redirect to a manual login form) or use the `scopes()` method to request minimal required permissions. Monitor provider APIs for changes.
- Can I use Laravel Socialite with Laravel Fortify or Jetstream for authentication?
- Yes. Socialite integrates seamlessly with Fortify/Jetstream. Use the `Socialite::driver()->user()` data to create or update users in your `User` model. For Fortify, extend the `CreateNewUser` or `UpdateUser` actions to handle social logins. See the [Fortify docs](https://laravel.com/docs/fortify#customizing) for customization.
- Is Laravel Socialite compatible with multi-tenant Laravel apps (e.g., using Stan or Tenancy)?
- Socialite itself is tenant-agnostic, but you’ll need to manage OAuth credentials per tenant. Store tenant-specific keys in a `tenants` table or use a package like `spatie/laravel-tenant-middleware`. Ensure session storage (e.g., Redis) is shared across tenants if using distributed sessions.
- What are the alternatives to Laravel Socialite for OAuth in Laravel?
- Alternatives include `php-social-auth/socialiteproviders` (community-driven, more providers), `knuckleswtf/socialite` (extended features), or rolling your own with `league/oauth2-client`. Socialite is preferred for its Laravel-native integration, simplicity, and official support. Evaluate based on provider needs and maintenance.