红宝石的OAuth2.0:客户端凭据类型有支持的客户端身份验证方法(Ruby OAuth2.0: c

2019-10-29 09:01发布

我使用的OAuth2宝石,用于制造client_credential认证。 我的代码如下,

require 'oauth2'
client = OAuth2::Client.new("my_client_id", "my_client_secret", :site => "my_site_url", :token_url => "oauth2/token")
client.client_credentials.get_token

当我执行上面的代码块,其与下面的错误响应,

OAuth2::Error (invalid_client: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method))
{
  "error":"invalid_client","error_description":"Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method)",
  "error_hint":"The OAuth 2.0 Client supports client authentication method "client_secret_basic", but method "client_secret_post" was requested. 
  You must configure the OAuth 2.0 client's "token_endpoint_auth_method" value to accept "client_secret_post".","status_code":401}

我检查了使用“网/ HTTP”库,我的client_idclient_secrets是有效的和工作。

我看到的唯一问题是与验证方法如在上述消息的暗示说,

The OAuth 2.0 Client supports client authentication method "client_secret_basic", but method "client_secret_post" was requested. You must configure the OAuth 2.0 client's "token_endpoint_auth_method" value to accept "client_secret_post"

我想知道的是什么?

  1. 怎样OAuth2宝石决定使用client_secret_post VS client_secret_basic? 我的意思是我怎么能在创业板的OAuth2要求client_secret_basic?
  2. 如果没有上述那么,我应该如何指定token_endpoint_auth_method到Accpet头client_secret_post?

Answer 1:

好了,终于我清除这些点。

  1. OAuth2用户宝石确实对OAuth的服务器请求与--token_endpoint_auth_method设置为“client_secret_post”。

  2. 虽然注册使用OAuth服务器的客户端,我们将不得不token_endpoint_auth_method设置为“client_secret_post”,所以它会成功。

在我来说,我是用水润,所以我用下面的命令来创建一个客户端:

hydra clients create --endpoint <OAuth server url> --id CLIENT_ID --secret CLIENT_SECRET \
--token-endpoint-auth-method 'client_secret_post' -g client_credentials

现在,使用这些CLIENT_ID和CLIENT_SECRET用的oauth2作品。

不过还是有一点是清楚-我可以在token_endpoint_auth_method组的请求使用的oauth2宝石client_secret_basic。



文章来源: Ruby OAuth2.0: client credential type has unsupported client authentication method