matt-allan/passport-socialite

This package is abandoned and no longer maintained. No replacement package was suggested.

A socialite driver for Passport

0.4.0 2021-04-30 21:51 UTC

This package is auto-updated.

Last update: 2021-11-30 23:14:57 UTC


README

Packagist License Latest Stable Version

A Laravel Socialite driver for authenticating with Laravel Passport OAuth servers.

Installation

This package can be installed using Composer. The Socialite package will also be installed if it is not already installed.

composer require matt-allan/passport-socialite

Configuration

Before using this driver, you will need to add credentials for the Passport server. These credentials should be placed in your config/services.php configuration file, and should use the key passport. For example:

'passport' => [
    'client_id' => env('PASSPORT_CLIENT_ID'),
    'client_secret' => env('PASSPORT_CLIENT_SECRET'),
    'url' => env('PASSPORT_URL'),
    'redirect' => env('PASSPORT_REDIRECT'),
],

Usage

The Passport driver works identically to the other Socialite drivers. All of the methods mentioned in the official documentation are available.

You can access the passport driver using the Socialite facade:

<?php

namespace App\Http\Controllers\Auth;

use Socialite;

class LoginController extends Controller
{
    /**
     * Redirect the user to the Passport server's authentication page.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('passport')->redirect();
    }

    /**
     * Obtain the user information from the Passport server.
     *
     * @return \Illuminate\Http\Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('passport')->user();

        // $user->token;
    }
}

The current user's details will be retrieved from the default api/user route.

In addition to the standard Socialite methods a refresh method is available to easily refresh expired tokens. The refresh method accepts a refresh token and returns an updated User with new access and refresh tokens if the token is refreshed successfully.

$user = Socialite::driver('passport')->refresh($refreshToken);

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.