oauth2 在 Rails 5.2 中使用 Degreed API 失败

问题描述

我正在尝试从 Rails 5.2 应用连接到 Degreed API,它使用 OAuth 2.0 协议的客户端凭据流进行身份验证和授权,但没有成功。我尝试使用 oauth2 gem 和 HTTP::Net

我的尝试(安装了相关的 gem,环境变量很好 - 我的请求在 Postman 中工作):

require 'oauth2'
require 'uri'
require 'net/http'

class DegreedApiWrapper
  attr_reader :client,:net_client

  def self.client
    client = OAuth2::Client.new(
      ENV['DEGREED_CLIENT_ID'],ENV['DEGREED_CLIENT_SECRET'],site: 'https://api.eu.betatest.degreed.com/',scope: 'content:read,content:write,completions:read,completions:write',grant_type: 'client_credentials',auth_scheme: :basic_auth
    )
    token = client.client_credentials.get_token
    puts token
  end

  def self.net_client
    url = URI('https://api.eu.betatest.degreed.com/oauth/token')
    https = Net::HTTP.new(url.host,url.port)
    https.use_ssl = true
    request = Net::HTTP::Post.new(url.path,'Content-Type' => 'application/x-www-form-urlencoded')
    data = {
      grant_type: 'client_credentials',client_id: ENV['DEGREED_CLIENT_ID'],client_secret: ENV['DEGREED_CLIENT_SECRET']
    }
    request.body = data.to_json
    response = https.request(request)
    puts response
  end
end

我得到的错误

enter image description here

任何帮助将不胜感激。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)