我在思考 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_id
和 client_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/