Giter VIP home page Giter VIP logo

laravel-socialite-ekm's Introduction

Laravel-Socialite-EKM

EKM OAuth2 Provider for Laravel Socialite

Packagist Software License StyleCI

This package allows you to use Laravel Socialite using EKM.

Installation

You can install the package via composer:

composer require mrstebo/laravel-socialite-ekm

Note: if you use Laravel 5.5+ you can skip service provider registration, because it should be auto discovered.

Then you should register service provider in your config/app.php file:

'providers' => [
    // Other service providers
    
    Mrstebo\LaravelSocialiteEkm\Provider::class,

]

You will also need to add credentials for the OAuth application that you can get using your EKM Partners account. They should be placed in your config/services.php file. You may copy the example configuration below to get started:

'ekm' => [
    'client_id' => env('EKM_CLIENT_ID'),
    'client_secret' => env('EKM_CLIENT_SECRET'),
    'redirect' => env('EKM_REDIRECT'),
],

Basic usage

So now, you are ready to authenticate users! You will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication. We will access Socialite using the Socialite facade:

<?php

namespace App\Http\Controllers\Auth;

use Socialite;

class AuthController extends Controller
{
    /**
     * Redirect the user to the EKM authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('ekm')->redirect();
    }

    /**
     * Obtain the user information from EKM.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('ekm')->user();

        // $user->token;
    }
}

Of course, you will need to define routes to your controller methods:

Route::get('auth/ekm', 'Auth\AuthController@redirectToProvider');
Route::get('auth/ekm/callback', 'Auth\AuthController@handleProviderCallback');

The redirect method takes care of sending the user to the OAuth provider, while the user method will read the incoming request and retrieve the user's information from the provider.

EKM OAuth2 does not support scopes on request, all scopes are configured in OAuth application settings.

Retrieving user details

Once you have a user instance, you can grab a few more details about the user:

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

// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // may not always be provided
$expiresIn = $user->expiresIn;

// EKM Specific Providers
$username = $user->user['sub'];
$serverId = $user->user['server_id'];

laravel-socialite-ekm's People

Contributors

mrstebo avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.