php - 使用 phpleague/oauth2-server 使用刷新 token 创建一个全新的访问 token

标签 php laravel-5 oauth-2.0 restful-authentication thephpleague

我在思考 oAuth 2.0 时遇到了一些问题。特别是thephpleague/oauth2-server实现。

我设法设置一个端点来使用密码授予类型创建访问 token 。也就是说,当有人执行 POST/auth 时,他们会得到以下答案:

{
    "access_token": "hleVw03Fx4hVsaCqEmFqcXeks0hsDTkNSxMN17NR",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "GD8kT7JfGULhUKSTSBsF7AO6NaIXrqPS0dlyQjTm"
}

我现在想做的是当access_token过期时生成一个新的 token 。我知道我应该使用 refresh_token 来请求一个全新的 token 。但是,我没有找到任何可以开始的文档。

最佳答案

您可以使用刷新授予类型来获取新的访问 token 。这是规范中描述的标准化流程:https://www.rfc-editor.org/rfc/rfc6749#section-6 。对 token 端点的请求示例(取自规范)如下所示:

POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA

在这种情况下,客户端使用其 client_idclient_secret 通过基本身份验证对 token 端点进行自身身份验证。在命令行 cURL 中,它看起来像:

curl -u "${CLIENT_ID}:${CLIENT_SECRET}" -d "grant_type=refresh_token&refresh_token=${REFRESH_TOKEN}"

关于php - 使用 phpleague/oauth2-server 使用刷新 token 创建一个全新的访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29682205/

相关文章:

php - 如何从大于可用 RAM 的 xml 文件中删除 xml 元素/节点?

php - 1064 预约 Pro 出错

php - 如何在 Laravel 5 中删除 session

php - 在 Laravel Blade 中写 @php @endphp 而不是 <?php ?> 有什么意义?

php - Laravel 5.5 急切加载抛出错误 - 试图获取非对象的属性

javascript - Facebook Web Login 的示例代码返回错误?

PHP - 多个不同的数据库依赖注入(inject)类

php - 编码 php postgres json_encode

java - 使用 OAuth2 SSO 在 spring-boot 应用程序中禁用 CSRF

ios - 轨道 API : Authenticate users from native mobile apps using username/password or facebook token