【问题标题】:Signet Oauth2 Basic Auth not working with Get Response apiSignet Oauth2 Basic Auth 不适用于 Get Response api
【发布时间】:2018-09-18 22:35:59
【问题描述】:

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

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 总是返回这个:

{"error"=>"invalid_client", "error_description"=>"Client credentials were not found in the headers"}

我用 curl 轻松完成了这个请求。它使用令牌成功返回。

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 上向专业人士提问。有人知道答案吗?这是api文档https://apidocs.getresponse.com/v3/oauth2

【问题讨论】:

    标签: ruby-on-rails ruby oauth-2.0 google-oauth getresponse


    【解决方案1】:

    遇到了类似的问题。我按照以下步骤为我工作。

    Step.1 加载从谷歌开发者控制台获得的凭据。

      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 所需的访问令牌。

        @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 由 Google 在重定向 URL 中发送。您可以在应用程序的 oauth2callback url 中将它们作为参数获取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多