Tomi
11 months ago

SSO with Socialite and Passport

Posted 11 months ago by Tomi

Hi every one,

So im working on a new project where we have to implement an Authentication Server, where the clients can login and then they get redirected to the original consumer Page.

I use Laravel Passport as an OAuth2 solution. I sett up a code grant Auth. Something like this:

Client web.php:

Route::get('/redirect', function () {

    $query = http_build_query([
        'client_id' => '1',
        'redirect_uri' => 'https://client-website.com/callback',
        'response_type' => 'code',
        'scope' => ''
    ]);
    return redirect('https://server-website.com/oauth/authorize?'.$query);
});


Route::get('/callback', function (Request $request) {

    $http = new GuzzleHttp\Client;
    $response = $http->post('https://server-website.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => '1',
            'client_secret' => 'tqkh59V6y2Tr2AxGn1IcCLV4awUt5reU7qop4rH0',
            'redirect_uri' => 'https://client-website..com/callback',
            'code' => request()->code,
        ],
    ]);
    return json_decode((string) $response->getBody(), true);
});

After this i get an access_token back. The tricky part is we also need an SSO implementation, and this is where it gets quit confusing for me. I recently read a different topic where it was brought up that Socialite could be used as an SSO.

If not did anyone else had a similar issue ? I got my token so how could i share it across all of my sites?

Please sign in or create an account to participate in this conversation.