zoukankan      html  css  js  c++  java
  • 适用于 Laravel Passport 社交账户授权

    这个包可以让 Laravel Passport 支持通过已经安装的社交账户登录登录。

    安装

    可以通过Composer安装此软件包。

    composer require larva/laravel-passport-socialite -vv
    

    如何使用

    • https://your-site.com/oauth/token 发出 POST 请求, 就像您需要密码或刷新授权一样。
    • POST 正文应包含 grant_type = social
    • 该请求将被路由到您的 User::findForPassportSocialite() 函数, 在该函数中,您将自己确定是否应授予访问权限。
    • 如果成功,将返回一个 access_token 和 refresh_token 。

    请求

    $response = $http->post('http://your-app.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'social',
            'client_id' => 'client-id',
            'client_secret' => 'client-secret',
            'provider' => 'wechat-mobile', 
            'code' => 'codecodecodecodecode',
        ],
    ]);
    

    例子


    这是 User::findForPassportSocialite() 方法的样子……

    /**
     * Find user using social provider's user
     *
     * @param string $provider Provider name as requested from oauth e.g. facebook
     * @param LaravelSocialiteContractsUser $socialUser User of social provider
     *
     * @return User
     * @throws Exception
     */
    public function findForPassportSocialite($provider, LaravelSocialiteContractsUser $socialUser)
    {
        
    }
    

    在此示例中,该应用程序能够基于提交的JSON负载中的 provider** socialUser **属性 对用户进行身份验证。
    它将返回 null 或用户对象。 它还可能会引发异常,解释令牌为什么无效的原因。
    findForPassportSocialite捕获任何这些异常,并将它们转换为适当的OAuth异常类型。 如果请求有效负载上没有phone ,那么我们将返回null,这将返回 invalid_credentials 错误响应:

    {
      "error": "invalid_credentials",
      "message": "The user credentials were incorrect."
    }
    
  • 相关阅读:
    python模块
    Django基础
    Python __str__(self)和__unicode__(self)
    Redis基本操作
    测试面试宝典
    h5页面的测试方式
    selenium IDE的使用流程
    如何安装chrome扩展程序--selenium IDE
    Selenium 中 强制等待、显示等待、隐式等待的区别
    Selenium+Python 自动化 之八种元素定位方法
  • 原文地址:https://www.cnblogs.com/fyblzds/p/12780277.html
Copyright © 2011-2022 走看看