![]() But, there may be times when you want to allow users to sign in to your apps using third-party services such as Twitter, GitHub and Google. * Obtain the user information from GitHub.In your Laravel applications, you would typically provide the functionality for your users to register and sign in using traditional email and password forms. Return Socialite::driver('github')->redirect() * Redirect the user to the GitHub authentication page. RoutesĪdd these routes to routes.php (you can make them anything you want, but this is the convention): Route::get('auth/github', let's fill out those controller methods: Controller methods Let's set up our routes and controller methods. env files: GITHUB_ID=client id from githubīoom. ![]() This lives in config/services.php, and as you can see, I've chosen to reference environment variables instead of pasting the values directly in: 'github' => [ Now, let's paste the authentication information in where Socialite can access it. Note: You can create a separate Application later for the production version of the site that has the production callback URL, or you can just adjust this once you go live-but that'll mean this authentication feature won't work locally anymore. , but you should set it to whatever the GitHub callback URL will be on your development environment. So, visit GitHub's New Application page, fill out the form, and grab your client ID and secret.įor now, I'm setting the callback URL to be: Once you complete it, you'll usually get a client ID and a client Secret, which we need to capture in order to configure Socialite correctly. The application will ask you questions like "What's the name of your application", "What's the callback URL", etc. If you're new to OAuth, you'll need to create an account and then an Application with each service provider. If you wanted, though, you could use one of the other options, or you could set up multiple authentication options.įirst, let's go to GitHub and set up a new Application. Create GitHub appįor this particular example, we'll be using GitHub as our authentication provider. Socialite is now hooked into your application and booting. To hook Socialite into your Laravel application, edit config/app.php and add the following line to the Service Providers array: Laravel\Socialite\SocialiteServiceProvider::class,Īnd add the following line to the Aliases array: 'Socialite' => Laravel\Socialite\Facades\Socialite::class, Install Socialite $ composer require laravel/socialite OK, so now you understand the basic flow, let's get started with Socialite. The consuming application takes that information and does something with it-in this case, marks the user as authenticated and lets them use the site.The consuming application ( ) uses the token to request a dump of information about the authenticating user from GitHub.Github) and GitHub redirects them back to the callback URL, along with a one-time use "token" that identifies them User signs into the service provider (e.g.User visits a page on the service's web site and carries with them information about the consuming web site (, which might have a GitHub Application ID of 12345) and a call back URL (, maybe).GitHub) or has a "Login with GitHub" button that directs them to the service. Login page either immediately directs them to the service (e.g.Authentication page directs them to login page. User visits page that requires authentication. ![]() The general flow for an OAuth application that's authenticating the way we will be here is: There's a little bit of knowledge about how OAuth works that'll help to get started. I'm working on a new little micro-SaaS that is purely dependent on GitHub in order to operate, so there's no reason to set up any user flow other than just GitHub. You can authenticate them for the purpose of connecting their pre-existing user account to a third-party service, but you can also use it as your primary login mechanism, which we'll be talking about here. Laravel's Socialite package makes it simple to authenticate your users to Facebook, Twitter, Google, LinkedIn, GitHub and Bitbucket.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |