首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Signet Oauth2基本身份验证不能使用Get Response api

Signet Oauth2基本身份验证不能使用Get Response api
EN

Stack Overflow用户
提问于 2018-04-09 21:43:08
回答 1查看 614关注 0票数 0

我正在尝试使用Signet::Oauth2::Client从getresponse.com获取访问令牌

代码语言:javascript
复制
client = Signet::OAuth2::Client.new(
  client_id: GET_RESPONSE_CLIENT_ID,
  client_secret: GET_RESPONSE_CLIENT_SECRET,
  token_credential_uri: 'https://api.getresponse.com/v3/token',
  redirect_uri: my_callback_uri,
  grant_type: 'authorization_code',
  code: the_code_i_got_from_get_response
)
response = client.fetch_access_token!

但是,Get Response始终返回以下内容:

代码语言:javascript
复制
{"error"=>"invalid_client", "error_description"=>"Client credentials were not found in the headers"}

我已经很容易地用curl完成了这个请求。它会成功返回令牌。

代码语言:javascript
复制
curl -v -u client_id:client_secret https://api.getresponse.com/v3/token -d "grant_type=authorization_code&code=abc123thisisthecode&redirect_uri=https://myserver.com/callback"

我已经尝试了一百万种方法,并阅读了客户源代码,但我没有发现自己做错了什么。我将继续阅读文档,但在此期间,我想我应该向stackoverflow的专业人士请教。有人知道答案吗?这里是接口文档https://apidocs.getresponse.com/v3/oauth2

EN

回答 1

Stack Overflow用户

发布于 2019-01-25 11:07:37

遇到了类似的问题。我遵循了下面的步骤,并为自己工作。

第1步加载从google开发人员控制台获得的凭据。

代码语言:javascript
复制
  client_secrets = Google::APIClient::ClientSecrets.load("#{Rails.root}/zenledger_ga_secrets.json")
  auth_client = client_secrets.to_authorization

  auth_client.update!(
    :scope => 'email profile https://www.googleapis.com/auth/analytics.readonly',
    :grant_type => "authoriation_code",
    :response_type => 'code',
    :redirect_uri => 'http://localhost:3001/admin/oauth2callback',
    :additional_parameters => {
      "access_type" => "offline",         # offline access
      "include_granted_scopes" => "true",  # incremental auth
    }
  )

步骤2.加载您的Signet客户端以获取访问所需API所需的访问令牌。

代码语言:javascript
复制
    @client = Signet::OAuth2::Client.new(
    :authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
    :token_credential_uri =>  'https://oauth2.googleapis.com/token',
    :client_id => ''xxxxxxxxxx',
    :client_secret => 'xxxxxxxxxx',
    :scope => 'email profile',
    :redirect_uri => 'http://localhost/admin/oauth2callback'
  )
  @client.code = auth_code
  @client.fetch_access_token!

备注auth_code是由谷歌在重定向URL中发送的。您可以在应用程序的oauth2callback url中以参数形式获取它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49734461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档