rwandabuild/murugo_api_auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rwandabuild/murugo_api_auth

Composer 安装命令:

composer require rwandabuild/murugo_api_auth

包简介

Package that will use Murugo auth to all 3rd party laravel projects with only API structure

README 文档

README

Issues Stars Total Downloads

Package that will be used for Murugo auth to all 3rd party laravel projects with only API structure

Follow the following steps to get started:

1. Install package by running the following command

composer require rwandabuild/murugo_api_auth

2. Include the following variables in config services file

    'murugo' => [
        'client_id' => env('MURUGO_CLIENT_ID'),
        'client_secret' => env('MURUGO_CLIENT_SECRET'),
        'redirect' => env('APP_REDIRECT_URL', 'YOUR LOGIN REDIRECT URL'),
        'murugo_url' => env('MURUGO_URL', 'MURUGO_URL'),
        'murugo_app_key' => env('MURUGO_APP_KEY'),
    ],

3. Dont forget to publish your migration by running the following command, when you want to upgrade

php artisan vendor:publish

4. Use the following migration

php artisan migrate

5. Add method to redirect user to murugo

   use RwandaBuild\MurugoAuth\Facades\MurugoAuth;


    public function redirectToMurugo()
    {
        return MurugoAuth::redirect();
    }

6. Add a callback method to be used after the redirection

   use RwandaBuild\MurugoAuth\Facades\MurugoAuth;


    public function murugoCallback()
    { 
        $murugoUser = MurugoAuth::user()
    }

7. Package also comes with this following method

    /**
     * This one is used by client(mobile) to authenticate murugo users on their 3rd party servers
     */
   use RwandaBuild\MurugoAuth\Facades\MurugoAuth;
   $tokens = [
               'access_token' => 'murugo_user_access_token'],
              'refresh_token' => 'murugo_user_refresh_token',
              'expires_in' => integer
   ],
   $murugoUser = MurugoAuth::userFromToken($tokens);

8. Add relationship between User and Murugo User models

  • Add a Trait built in the package already that makes relationship between User model and Murugo user model
    use RwandaBuild\MurugoAuth\Traits\MurugoAuthHelper;
    class User extends Authenticatable
    {
      use MurugoAuthHelper;
    }
  • To access the murugo user when you already have user model like the following:
    $user = User::find(1);
    // access the relationship
    $murugoUser = $user->murugoUser;
  • When you have a murugo user model and you need to the related user, you can do it in the following way:
$murugoUser = MurugoAuth::user();
// accessing the related user
$user = $murugoUser->user;

NOTES: By default package is using App\User model or App\Models|user for making relationship between your user and murugo user model

9. At this step this is how you refresh tokens

First you should know that the Murugo user model keeps the access_token refresh_token and the token_expires_at , now in case you may need to refresh the token of an existing, just do it in the following way:

$user = User::find(2);

// refreshing murugo user token

$murugoUser = MurugoAuth::refreshToken($user->murugoUser);

By Default package will add the following api routes in your laravel project

  • api/murugo-auth >>> This route will be used to get response sent from murugo and save in your laravel project database
  • api/authenticate-user >>>This route will authenticate user by checking uuid of user and by checking if token is still valid and if true return user object
  • api/logout >>> This route will logout user on murugo server

Follow RwandaBuild bellow and contact us

统计信息

  • 总下载量: 3.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固