Author - StudySection Post Views - 293 views
socialite

Laravel Socialite

Introduction

Laravel Socialite manages the cost of an expressive, familiar interface to OAuth validation with Facebook, Twitter, Google, LinkedIn, GitHub, GitLab, and Bitbucket. It handles nearly all of the boilerplate social authentication code you’re dreading writing.

Installation

composer require laravel/socialite

Configuration

Earlier than using Socialite, you will also want to add credentials for the OAuth services your software utilizes. Those credentials need to be placed for your config/offerings.personal home page configuration document and should use the important thing Facebook, Twitter, LinkedIn, Google, Github, GitLab, or Bitbucket, depending on the vendors your software calls for.

for example:
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => 'http://your-callback-url',
],

Routing

Subsequent, you’re ready to authenticate customers! you’ll want two routes: one for redirecting the user to the OAuth issuer, and any other for receiving the callback from the company after authentication. we can get entry to Socialite the use of the Socialite facade:

<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Facades\Socialite;
class LoginController extends Controller
{
/**
* Redirect the user to the GitHub authentication page.
*
* @return \Illuminate\Http\Response
*/
public function redirectToProvider()
{
return Socialite::driver('github')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* @return \Illuminate\Http\Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('github')->user();

// $user->token;
}
}

The redirect approach looks after sending the user to the OAuth issuer, while the user approach will study the incoming request and retrieve the person’s information from the company.
you will want to define routes for your controller methods:
use App\Http\Controllers\Auth\LoginController;
Route::get('login/github', [LoginController::class, 'redirectToProvider']);
Route::get('login/github/callback', [LoginController::class, 'handleProviderCallback']);

Retrieving User Details

Once you have got a person example, you could grab a few greater details about the user:

$user = Socialite::driver('github')->user();
// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // not always provided
$expiresIn = $user->expiresIn;
// OAuth One Providers
$token = $user->token; //to get user token
$tokenSecret = $user->tokenSecret; //to get user token secret
// All Providers
$user->getId(); //to get user id
$user->getNickname(); //to get user nickname
$user->getName(); //to get user name
$user->getEmail(); //to get user email
$user->getAvatar(); //to get user avatar

Retrieving User Details From A Token (OAuth2)
If you have already got a legitimate get right of entry to a token for a person, you could retrieve their information the use of the userFromToken approach:

$user = Socialite::driver('github')->userFromToken($token);

Retrieving User Details From A Token And Secret (OAuth1)
If you have already got a valid pair of token / mystery for a person, you may retrieve their info using the userFromTokenAndSecret method:
$user = Socialite::driver('twitter')->userFromTokenAndSecret($token, $secret);

People having good knowledge of Financial accounting can get an accounting certification from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial Accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri