New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

hanbz/passport-client

Laravel wrapper around passport client OAuth2 libraries.
12,345 1
Install
composer require hanbz/passport-client
Latest Version:v1.0.1
PHP:^7.2|^8.0
Laravel:6 · 7 · 8
License:MIT
Last Updated:Nov 13, 2020
Links: GitHub  ·  Packagist
Maintainer: hanbzsky

Laravel passport client

Total Downloads Latest Stable Version License

Introduction

Fork from Laravel Socialite to build a Laravel passport client library to OAuth2.0 authentication with Laravel port.

Install

$ composer require hanbz/passport-client

add the config at .env

CLIENT_ID=oauth_client
CLIENT_SECRET=oauth_secert
REDIRECT=your_callback_url
OAUTH_DOMAIN=your_oauth_server

add this section at config/service.php

    'passport' => [
        'client_id' => env('CLIENT_ID'),
        'client_secret' => env('CLIENT_SECRET'),
        'redirect' => env('REDIRECT'),
        'domain' => env('OAUTH_DOMAIN')
    ]

Usage

Use the package by Facades name PassportClient. The driver name is passport. It includes two functions redirect and user.

The redirect function will redirect user to the oauth server.

web.php
use App\Http\Controllers\Auth\OAuthController;
use hanbz\PassportClient\Facades\PassportClient;

Route::get('oauth/login', fn() => PassportClient::driver('passport')->redirect())->name('oauth.login');
Route::get('oauth/callback', [OAuthController::class, 'OAuthCallback']);

The user function will return the user info.

AuthController.php
use App\Models\User;
use hanbz\PassportClient\Facades\PassportClient;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;

    public function OAuthCallback()
    {
        $oauth_user = PassportClient::driver('passport')->user();

        $user = User::where('email', $oauth_user->getEmail())->first();

        if (is_null($user)) {
            $name = $oauth_user->getName();
            $email = $oauth_user->getEmail();
            $password = Str::random(8);
            $user = User::create(compact('name', 'email', 'password'));
        }

        Auth::login($user);

        return redirect()->intended('dashboard');
    }

Contributing

Thank you for considering contributing to Laravel passport client!

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

License

Laravel passport client is open-sourced software licensed under the MIT license.

Related Packages

imamnc/efihub-client

Laravel client for EFIHUB Integration Service

1,922 0
salla/ouath2-merchant

Salla OAuth 2.0 Client Provider for The PHP League OAuth2-Client

139,819 26
someline/rest-api-client

An elegant and smart Rest API Client with OAuth2 authentication support. Build f...

13,527 8
14four/oauth2-basecamp

Basecamp OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1,659 3

Version History

Version Released PHP Laravel License
v1.0.1 ^7.2|^8.0 ^6.0|^7.0|^8.0 MIT
v1.0.0 ^7.2|^8.0 ^6.0|^7.0|^8.0 MIT