Drupal 8 Oauth2 向客户端添加授权类型 "password"
Drupal8 Oaut2 add a grant type "password" to client
我在 Drupal8 项目上工作并创建了 Rest API,一切正常,直到我想添加 Oauth2 当我尝试获取令牌时出现无效授权类型错误。
这是错误代码:
{
"error": "invalid_grant",
"message": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
"hint": "Check the configuration to see if the grant is enabled."
}
这是我调用的 url:
http://myserver/oauth/token?grant_type=password&client_id=6db9da8d-b831-4381-b279-381bc5a57e90&scope&username=webmasterrest&password=webmasterrest&client_secret=$S$EamACyfemGWic74kmkwUvphMmr9FL132KC297mI1GEkTKhyBJyAo
我添加了一个客户端,但我无法向该客户端添加授权类型 "password",有什么帮助吗?
添加Oauth 2认证
使用 Composer 安装模块:composer config repositories.drupal composer https://packages.drupal.org/8 && composer require drupal/simple_oauth:^2。您可以使用任何其他安装方法,只要您安装了 OAuth2 Server composer 包。
生成一对密钥来加密令牌。出于安全原因,将它们存储在文档根目录之外。
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout > public.key
将密钥路径保存在:/admin/config/people/simple_oauth。
转到 REST UI 并在您的资源中启用 oauth2 身份验证。
通过以下方式创建客户端应用程序:/admin/config/services/consumer/add。
通过向 /oauth/token 发出 POST 请求,使用您的凭据创建令牌。请参阅有关您的请求应包含哪些字段的文档
(未显示)权限设置为仅允许经过身份验证的用户通过 REST 查看节点。
在没有身份验证的情况下通过 REST 请求节点并观察它失败。
使用 header 授权通过 REST 请求节点:Bearer {YOUR_TOKEN} 并观察它是否成功。
来自this
注意:我使用 drupal/simple_oauth 版本 2.x 因为我在版本 3.x
中遇到异常
我在 Drupal8 项目上工作并创建了 Rest API,一切正常,直到我想添加 Oauth2 当我尝试获取令牌时出现无效授权类型错误。
这是错误代码:
{
"error": "invalid_grant",
"message": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
"hint": "Check the configuration to see if the grant is enabled."
}
这是我调用的 url:
http://myserver/oauth/token?grant_type=password&client_id=6db9da8d-b831-4381-b279-381bc5a57e90&scope&username=webmasterrest&password=webmasterrest&client_secret=$S$EamACyfemGWic74kmkwUvphMmr9FL132KC297mI1GEkTKhyBJyAo
我添加了一个客户端,但我无法向该客户端添加授权类型 "password",有什么帮助吗?
添加Oauth 2认证
使用 Composer 安装模块:composer config repositories.drupal composer https://packages.drupal.org/8 && composer require drupal/simple_oauth:^2。您可以使用任何其他安装方法,只要您安装了 OAuth2 Server composer 包。
生成一对密钥来加密令牌。出于安全原因,将它们存储在文档根目录之外。
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout > public.key
将密钥路径保存在:/admin/config/people/simple_oauth。
转到 REST UI 并在您的资源中启用 oauth2 身份验证。
通过以下方式创建客户端应用程序:/admin/config/services/consumer/add。
通过向 /oauth/token 发出 POST 请求,使用您的凭据创建令牌。请参阅有关您的请求应包含哪些字段的文档
(未显示)权限设置为仅允许经过身份验证的用户通过 REST 查看节点。
在没有身份验证的情况下通过 REST 请求节点并观察它失败。
使用 header 授权通过 REST 请求节点:Bearer {YOUR_TOKEN} 并观察它是否成功。
来自this
注意:我使用 drupal/simple_oauth 版本 2.x 因为我在版本 3.x
中遇到异常