All Projects → coderello → Laravel Passport Social Grant

coderello / Laravel Passport Social Grant

Licence: mit
🔒 API authentication via social networks for your Laravel application

Projects that are alternatives of or similar to Laravel Passport Social Grant

Laravel Janitor
🔑 Easily add login proxy to your Laravel API
Stars: ✭ 54 (-61.97%)
Mutual labels:  laravel, passport
Vkbot
Простой разговорный бот на PHP
Stars: ✭ 88 (-38.03%)
Mutual labels:  social, network
Reactnativelaravellogin
Sample App for login using laravel 5.5 React Native and Redux
Stars: ✭ 75 (-47.18%)
Mutual labels:  laravel, passport
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+319.72%)
Mutual labels:  social, laravel
Passport Social Grant
Stars: ✭ 114 (-19.72%)
Mutual labels:  laravel, passport
Laravel template with vue
laravel5.5和vue.js结合的前后端分离项目模板,后端使用了laravel的LTS版本(5.5),前端使用了流行的vue-element-template项目。作为程序的起点,可以直接以此为基础来进行业务扩展。模板内容包括基础的用户管理和权限管理、日志管理、集成第三方登录,整合laravel-echo-server 实现了websocket 做到了消息的实时推送,并在此基础上,实现了聊天室和客服功能。权限管理包括后端Token认证和前端vue.js的动态权限,解决了前后端完整分离的情况下,vue.js的认证与权限相关的痛点,已在本人的多个项目中集成使用。
Stars: ✭ 763 (+437.32%)
Mutual labels:  laravel, passport
Poetryclub Backend
基于 laravel + vue.js 的诗词小筑网站后台页面与后端代码
Stars: ✭ 87 (-38.73%)
Mutual labels:  laravel, passport
Librenms
Community-based GPL-licensed network monitoring system
Stars: ✭ 2,567 (+1707.75%)
Mutual labels:  laravel, network
Laravel Social Network
Laravel 5.4 - location-based social network
Stars: ✭ 114 (-19.72%)
Mutual labels:  social, laravel
Laravel Tenancy Passport Demo
Laravel demo with Passport and Tenancy
Stars: ✭ 107 (-24.65%)
Mutual labels:  laravel, passport
hej
Hej! is a simple authentication boilerplate for Socialite.
Stars: ✭ 111 (-21.83%)
Mutual labels:  social, passport
Reddit Detective
Play detective on Reddit: Discover political disinformation campaigns, secret influencers and more
Stars: ✭ 129 (-9.15%)
Mutual labels:  social, network
Monica
Personal CRM. Remember everything about your friends, family and business relationships.
Stars: ✭ 15,499 (+10814.79%)
Mutual labels:  social, laravel
Angular5.2 Laravel5.6
Angular 5.2 and Laravel 5.6 Authentication and CRUD
Stars: ✭ 17 (-88.03%)
Mutual labels:  laravel, passport
Plus
💝The Plus (ThinkSNS+) is a powerful, easy-to-develop social system built with Laravel.
Stars: ✭ 2,148 (+1412.68%)
Mutual labels:  social, laravel
Voten
The code that powers voten.co
Stars: ✭ 1,215 (+755.63%)
Mutual labels:  social, laravel
Larapush
artisan push - Deploy your codebase into your web server with one Laravel artisan command and no SSH needed!
Stars: ✭ 150 (+5.63%)
Mutual labels:  laravel, passport
Roastapp
Laravel学院 Roast 应用源码
Stars: ✭ 164 (+15.49%)
Mutual labels:  laravel, passport
Brightid
Reference mobile app for BrightID
Stars: ✭ 101 (-28.87%)
Mutual labels:  social, network
Laravel Passport Android
Laravel + Passport for an Android App
Stars: ✭ 116 (-18.31%)
Mutual labels:  laravel, passport

Laravel Passport Social Grant

Packagist GitHub tag License Downloads tests

This package adds a social grant for your OAuth2 server. It can be useful if have an API and want to provide the ability for your users to login/register through social networks.

As a result you will be able to exchange access_token, issued by the OAuth2 server of any social provider, to access_token and refresh_token issued by your own OAuth2 server. You will receive this access_token and return the user instance that corresponds to it on your own.

Installation

You can install this package via composer using this command:

composer require coderello/laravel-passport-social-grant

The package will automatically register itself.

Configuring

As the first step, you need to implement SocialUserResolverInterface:

<?php

namespace App\Resolvers;

use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Socialite\Facades\Socialite;

class SocialUserResolver implements SocialUserResolverInterface
{
    /**
     * Resolve user by provider credentials.
     *
     * @param string $provider
     * @param string $accessToken
     *
     * @return Authenticatable|null
     */
    public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable
    {
        // Return the user that corresponds to provided credentials.
        // If the credentials are invalid, then return NULL.
    }
}

The next step is to bind SocialUserResolverInterface to your implementation.

You can do it by adding the appropriate key-value pair to $bindings property in AppServiceProvider:

<?php

namespace App\Providers;

use App\Resolvers\SocialUserResolver;
use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * All of the container bindings that should be registered.
     *
     * @var array
     */
    public $bindings = [
        SocialUserResolverInterface::class => SocialUserResolver::class,
    ];
}

You are done!

Usage

Example of usage with axios:

axios.post('/oauth/token', {
    grant_type: 'social', // static 'social' value
    client_id: clientId, // client id
    client_secret: clientSecret, // client secret
    provider: providerName, // name of provider (e.g., 'facebook', 'google' etc.)
    access_token: providerAccessToken, // access token issued by specified provider
  })
  .then((response) => {
    const {
      access_token: accessToken,
      expires_in: expiresIn,
      refresh_token: refreshToken,
    } = response.data;

    // success logic
  })
  .catch((error) => {
    const {
      message,
      hint,
    } = error.response.data;

    // error logic
  });

Example of usage with guzzle:

<?php

use GuzzleHttp\Client;
use Illuminate\Support\Arr;

$http = new Client;

$response = $http->post($domain . '/oauth/token', [
    RequestOptions::FORM_PARAMS => [
        'grant_type' => 'social', // static 'social' value
        'client_id' => $clientId, // client id
        'client_secret' => $clientSecret, // client secret
        'provider' => $providerName, // name of provider (e.g., 'facebook', 'google' etc.)
        'access_token' => $providerAccessToken, // access token issued by specified provider
    ],
    RequestOptions::HTTP_ERRORS => false,
]);
$data = json_decode($response->getBody()->getContents(), true);

if ($response->getStatusCode() === Response::HTTP_OK) {
    $accessToken = Arr::get($data, 'access_token');
    $expiresIn = Arr::get($data, 'expires_in');
    $refreshToken = Arr::get($data, 'refresh_token');

    // success logic
} else {
    $message = Arr::get($data, 'message');
    $hint = Arr::get($data, 'hint');

    // error logic
}

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

Created by Illia Sakovich

Maintained by Ankur Kumar

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].