![]() ![]() ![]() You can use the avatar() method on the user object to retrieve the URL of the user's avatar. Laravel Socialite also provides a convenient way to retrieve the user's avatar. For example, to retrieve the user's email address from Facebook, modify your authentication request like this: return Socialite :: driver ( 'facebook' ) -> scopes ( ) -> redirect ( ) To retrieve additional information about the user such as their email, you can add scopes to your authentication request. Once you have authenticated the user, you will need to implement your own authorization logic to determine what the user is allowed to do within your application. Keep in mind that Laravel Socialite only provides authentication, not authorization. That's it! You can repeat steps 4 and 5 for each OAuth provider you want to support. For example: Route :: get ( '/auth/facebook', function ( ) ) In your Laravel application, create a route that will redirect the user to the OAuth provider's authentication page. env file, replacing the placeholders with your actual credentials: FACEBOOK_CLIENT_ID=your-facebook-client-idįACEBOOK_CLIENT_SECRET=your-facebook-client-secretįACEBOOK_REDIRECT_URI=your-facebook-redirect-uri This will typically involve registering your application with the provider and obtaining the necessary credentials (client ID, client secret, etc.).Ĭonfigure the provider credentials in your. Set up the OAuth application with your provider of choice. Install Laravel Socialite using Composer composer require laravel/socialite To use Laravel Socialite, follow these steps: It ships with support for authentication using Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket. * Obtain the user information from GitHub.Laravel Socialite is an optional package that provides a simple and convenient way to authenticate with OAuth providers. Overwrite app/Http/Controllers/Auth/AuthController.php with the contents of the AuthController.php template. 'redirect' => env( 'GITHUB_CALLBACK_URL'),Īfter setting up the Socialite provider and Alias we need to set up an AuthController and some routes. 'client_secret' => env( 'GITHUB_CLIENT_SECRET'), To do that open up config/services.php and add a github entry: return [ If you're running on localhost:8000 this will be We now need to tell Socialite about these configuration values. GITHUB_CALLBACK_URL=YOUR_GITHUB_CALLBACK_URL ![]() env file in your Laravel application and take the values from the GitHub application settings and put them into the. Go to your settings (top-right drop-down -> Settings)Įverybody needs to now do the following exercises.If you'd like to register your own application or you're going through this without an instructor then you'll need to create an application. Self Taught Workshop / Create your own GitHub App If your app isn't running from localhost:8000 then you'll need to Create your own GitHub App. If you're in an instructor-lead workshop and you are running your app from then they'll provide you with some credentials that you can use. In order to use GitHub social login your application needs to be registered with GitHub. Other aliases 'Socialite' => Laravel\Socialite\Facades\Socialite::class,įor more detailed instructions see the official Laravel Socialite docs Get GitHub Credentials Laravel\Socialite\SocialiteServiceProvider::class, Then add the provider to config/app.php: 'providers' => [ Run the following command from a terminal or console: composer require laravel/socialite Since GitHub is referred to in the Socialite documentation we're going to use it for our social login. This isn't a production grade solution, but it helps us get simple authentication added to our application in super-quick time. Instead, we're going to use social login using the Socialite package and simply store the authenticated user information in the Session. ![]() For that reason we're going to avoid adding a database dependency. So, we need some form of authentication resulting in an associated logged in user.įor each component we add to an application we increase its complexity - something we want to avoid in this workshop. To give an activity more context it's important to know who is triggering that activity. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |