⚡️ Easiest way to implement Socialite for Laravel Jetstream.

Overview

Build Status Total Downloads Latest Stable Version License

Introduction

Larastream is a third-party package for Laravel Jetstream. It replaces the published authentication and profile scaffolding provided by Laravel Jetstream, with scaffolding that has support for Laravel Socialite.

If you are unfamiliar with Laravel Socialite, it is strongly advised that you take a look at the official documentation.


NOTE

Larastream, like Jetstream, should only be installed on NEW applications, installing Larastream into an existing application will break your applications functionality. It is strongly advised against installing this package within an existing applications.

Installation

Getting started with Larastream is a breeze. With a simple two-step process to get you on your way to creating the next big thing. Inspired by the simplicity of Jetstream's installation process, Larastream follows the same 'installation':

composer require tal7aouy/larastream

php artisan larastream:install

The larastream:install command will overwrite the Jetstream published files which are required for Larastream to work.

Note: If you don't have Laravel Jetstream installed, the above command will walk you through the steps required to install it.

Usage

Once Larastream is installed, it will publish a config file. In this config file, you can define whether or not the packages alterations should be shown, the middleware used to wrap the routes as well as the providers that you wish to use:



return [
    'middleware' => ['web'],
    'providers' => [
        \Tal7aouy\Larastream\Providers::github(),
        \Tal7aouy\Larastream\Providers::facebook(),
        \Tal7aouy\Larastream\Providers::google()
    ],
    'features' => [
        // \Tal7aouy\Larastream\Features::rememberSession(),
    ],
];

Once you’ve defined your providers, you will need to update your services.php config file and create client_id, client_secret and redirect keys for each provider:

'{provider}' => [
    'client_id' => env('{PROVIDER}_CLIENT_ID'),
    'client_secret' => env('{PROVIDER}_CLIENT_SECRET'),
    'redirect' => env('{PROVIDER}_REDIRECT'), // e.g. 'https://your-domain.com/oauth/{provider}/callback'
],

Generating the redirect.

In some cases, you may want to customise how Socialite handles the generation of the redirect to a provider. For example, you may wish to To do this, you may alter the GenerateRedirectForProvider action found in app/Actions/Larastream. For example, you may need to define scopes, the response type (e.g. implicit grant type), or any additional request info:

/**
 * Generates the redirect for a given provider.
 * 
 * @param  string  $provider
 * 
 * @return \Symfony\Component\HttpFoundation\RedirectResponse
 */
public function generate(string $provider)
{
    return Socialite::driver($provider)
        ->scopes(['*'])
        ->with(['response_type' => 'token'])
        ->redirect();
}

Resolving users

By default, Larastream will resolve user information from Socialite using the following logic:

Socialite::driver($provider)->user();

Returning an instance of \Laravel\Socialite\AbstractUser. However, you may wish to customise the way user resolution is done. For example, you may wish to use the stateless method available for some Socialite providers. Larastream makes this easy for you and publishes a ResolveSocialiteUser action to you applications app/Actions/Larastream directory. Simply customise this class with the logic required for your use-casee.

Handling Invalid State

To handle instances where Socialite throws an InvalidStateException a dedicated HandleInvalidState action is made available to you when you first install Larastream. You are free to modify or extend this action according to your needs.

Alternatively, you may write your own action to handle the exception. To do so, you'll need to implement Tal7aouy\Larastream\Contracts\HandlesInvalidState and update the following line in App\Providers\LarastreamServiceProvider

Larastream::handlesInvalidStateUsing(HandleInvalidState::class);

Create account on first login

This feature enables the capability to register a new user account (and team if the Jetstream feature is enabled) when a user attempts to authenticate via the '/login' route.

To turn on this feature add the following to config/larastream.php:

'features' => [
    Features::createAccountOnFirstLogin(),
],

Log in on registration

If a user has already registered with a particular email address, and the OAuth account they attempt to register with returns the same email, the provider will be linked to the existing user and they will be logged in.

To turn on this feature add the following to config/larastream.php:

'features' => [
    Features::loginOnRegistration(),
],

Remember Session

This feature passes the boolean value "remember" value to true when authenticating with Laravel Fortify

To turn on this feature add the following to config/larastream.php:

'features' => [
    Features::rememberSession(),
],

Handling Missing Emails

Some providers (such as GitHub), don't always return an email address when attempting to authenticate with them. In this case, Larastream will generate a random email address for you. This email will be in the format [email protected]. E.g. [email protected]

To turn on this feature add the following to config/larastream.php:

'features' => [
    Features::generateMissingEmails(),
],

Provider Avatars

This feature determines whether or not to pull in a users avatar / profile image from a provider.

To turn on this feature add the following to config/larastream.php:

'features' => [
    Features::providerAvatars(),
],

Socialite Providers

If you wish to use the community driven socialiteproviders package with Larastream, you may do so by following their documentation on installing the package into a Laravel project. There are a few configuration steps you will need to go through first.

To implement a custom provider, you will need to create an SVG icon file (e.g. twitter-icon.blade.php or TwitterIcon.vue) to be used in the authentication cards and the account management panel.

You will then need to alter the appropriate published components with your new icons and provider condition:

  • Connected Account component
  • Larastream Providers component

Note: Some providers will not return a token in the callback response. As such, you will need to modify the 2022_03_05_000000_create_connected_accounts_table.php migration to allow the token field to accept NULL values

Changelog

Check out the CHANGELOG in this repository for all the recent changes.

License

Larastream is open-sourced software licensed under the MIT license.

You might also like...
Handle roles and permissions in your Laravel application

Laratrust (Laravel Package) Version Compatibility Laravel Laratrust 8.x 6.x 7.x 6.x 6.x 6.x 5.6.x - 5.8.x 5.2 5.3.x - 5.5.x 5.1 5.0.x - 5.2.x 4.0. Ins

Role-based Permissions for Laravel 5

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Roles & Permissions for Laravel 8 / 7 / 6 / 5

Defender Defender is an Access Control List (ACL) Solution for Laravel 5 / 6 / 7 (single auth). (Not compatible with multi-auth) With security and usa

Laravel wrapper around OAuth 1 & OAuth 2 libraries.

Introduction Laravel Socialite provides an expressive, fluent interface to OAuth authentication with Facebook, Twitter, Google, LinkedIn, GitHub, GitL

PHP package built for Laravel 5.* to easily handle a user email verification and validate the email

jrean/laravel-user-verification is a PHP package built for Laravel 5.* & 6.* & 7.* & 8.* to easily handle a user verification and validate the e-mail.

LDAP Authentication & Management for Laravel

👋 Hey there! Looking for something even easier to use for LDAP integration in your Laravel applications? 🎉 Introducing LdapRecord 🎉 LdapRecord is t

Limit access to your Laravel applications by using invite codes

Doorman Doorman provides a way to limit access to your Laravel applications by using invite codes. Invite Codes: Can be tied to a specific email addre

Declarative style of authorization and validation in laravel.
Declarative style of authorization and validation in laravel.

Laravel Hey Man Readability Counts. In fact, Readability is the primary value of your code !!! 🎀 Heyman continues where the other role-permission pac

Set up Laravel Auth guards using Eloquent in seconds

Nightguard Set up Auth guards using Eloquent in seconds. Introduction Laravel guards provide a super convenient way of authorizing different areas of

Releases(v1.0.1)
Owner
M'HAMMED TALHAOUY
Full-stack developer, specialising in @laravel ,@vuejs ,@tailwindcss
M'HAMMED TALHAOUY
The easiest and most intuitive way to add access management to your Filament Resource Models through `spatie/laravel-permission`

Filament Shield The easiest and most intuitive way to add access management to your Filament Resource Models (more coming soon ?? ) One Plugin to rule

Bezhan Salleh 329 Jan 2, 2023
A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package

laravel-social A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package. I

Sergi Tur Badenas 42 Nov 29, 2022
A Collection of Providers for Laravel Socialite

A Collection of Providers for Laravel Socialite Documentation Full documentation for using these providers can be found at the Documentation. Contribu

Socialite Providers 402 Jan 6, 2023
Hej! is a simple authentication boilerplate for Socialite.

Hej! - a Socialite authentication flow implementation Hej! is a simple authentication flow implementation for Socialite. Out-of-the-box, Hej! can help

Renoki Co. 111 Oct 29, 2022
Creamos un inicio de sesión desde Facebook para nuestra aplicación web utilizando la librería de Socialite

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Carlos Villatoro 2 May 23, 2022
This is a simple laravel authentication built with livewire jetstream.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Emmanuel Dada 1 Feb 4, 2022
An OAuth 2.0 bridge for Laravel and Lumen [DEPRECATED FOR LARAVEL 5.3+]

OAuth 2.0 Server for Laravel (deprecated for Laravel 5.3+) Note: This package is no longer maintaned for Laravel 5.3+ since Laravel now features the P

Luca Degasperi 2.4k Jan 6, 2023
A Simple method to create laravel authentication for an existing laravel project.

Laravel Simple Auth A Simple method to create laravel authentication for an existing laravel project. Indroduction Why I created this kind of package?

Dasun Tharanga 10 Dec 14, 2021
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
🔐 JSON Web Token Authentication for Laravel & Lumen

Documentation Documentation for 1.* here For version 0.5.* See the WIKI for documentation. Supported by Auth0 If you want to easily add secure authent

Sean Tymon 10.7k Dec 31, 2022