PHP code example of recca0120 / laravelpassport-provider

1. Go to this page and download the library: Download recca0120/laravelpassport-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

recca0120 / laravelpassport-provider example snippets


'providers' => [
    // a whole bunch of providers
    // remove 'Laravel\Socialite\SocialiteServiceProvider',
    \SocialiteProviders\Manager\ServiceProvider::class, // add
];

/**
 * The event handler mappings for the application.
 *
 * @var array
 */
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // add your listeners (aka providers) here
        'SocialiteProviders\LaravelPassport\LaravelPassportExtendSocialite@handle',
    ],
];

'laravelpassport' => [
    'host' => env('SERVICE_LARAVELPASSPORT_HOST'),
    'client_id' => env('SERVICE_LARAVELPASSPORT_CLIENT_ID'),
    'client_secret' => env('SERVICE_LARAVELPASSPORT_CLIENT_SECRET'),
    'redirect' => env('SERVICE_LARAVELPASSPORT_REDIRECT'),

    // optional
    'authorize_uri' => 'oauth/authorize', // if your authorize_uri isn't same, you can change it
    'token_uri' => 'oauth/token', // if your token_uri isn't same, you can change it
    'userinfo_uri' => 'api/user', // if your userinfo_uri isn't same, you can change it
    'userinfo_key' => '', // if your userinfo response is like {"data": {"id" => "xxx", "email" => "[email protected]"}} you can set userinfo_key 'userinfo_info' => 'data'
]

return Socialite::with('laravelpassport')->redirect();

// to turn off stateless
return Socialite::with('laravelpassport')->stateless(false)->redirect();

// to use stateless
return Socialite::with('laravelpassport')->stateless()->redirect();

$clientId = "secret";
$clientSecret = "secret";
$redirectUrl = "http://yourdomain.com/api/redirect";
$additionalProviderConfig = ['site' => 'meta.stackoverflow.com'];
$config = new \SocialiteProviders\Manager\Config($clientId, $clientSecret, $redirectUrl, $additionalProviderConfig);
return Socialite::with('laravelpassport')->setConfig($config)->redirect();

$user = Socialite::driver('laravelpassport')->user();
$accessTokenResponseBody = $user->accessTokenResponseBody;