嗨,我正在尝试使用oauth 2将我的应用程序连接到本地API。
授权请求成功,并返回我的回调地址上的代码,以发出访问令牌请求。
这是我的回调代码:
def client
OAuth2::Client.new(KEY, SECRET, site: SITE, authorize_url: '/oauth2/auth', token_url: 'http://localhost:8080/oauth2/token')
end
get '/auth/callback' do
access_token = client.auth_code.get_token(params[:code], "redirect_uri" => redirect_uri)
access_token = session[:access_token] = access_token.token
@access_token = access_token
end
在get_token函数中,我检查了我的连接配置(正确):
1.9.3 (#<OAuth2::Client:0x007fb255183e18>):0 > connection
=> #<Faraday::Connection:0x007fb2551817f8
@parallel_manager=nil,
@headers={"User-Agent"=>"Faraday v0.9.0"},
@params={}, @options=#<Faraday::RequestOptions (empty)>,
@ssl=#<Faraday::SSLOptions (empty)>,
@default_parallel_manager=nil,
@builder=#<Faraday::RackBuilder:0x007fb255188760
@handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp, Faraday::Response::Logger]>,
@url_prefix=#<URI::HTTP:0x007fb255187b08 URL:http://localhost:3000/>,
@proxy=#<Faraday::ProxyOptions uri=#<URI::HTTP:0x007fb255186b68 URL:http://proxy_url:port>, user="me", password=« MyPassword">>
1.9.3 (#<OAuth2::Client:0x007fb255183e18>):0 > url
=> "http://localhost:8080/oauth2/token »
1.9.3 (#<OAuth2::Client:0x007f9bdb94cce8>):0 > verb
=> :post
1.9.3 (#<OAuth2::Client:0x007f9bdb94cce8>):0 > opts
=> {
:body => {
"client_id" => "Test",
"client_secret" => "test_secret",
"code" => "d3c4661b11ea5e2752852db72e1ce100f2f1804d",
"grant_type" => "authorization_code",
"redirect_uri" => "http://localhost:4567/auth/callback"
},
:headers => {
"Content-Type" => "application/x-www-form-urlencoded"
},
:parse => nil,
:raise_errors => true
}
来自请求的调试信息:
I, [2014-08-20T12:01:19.450941 #12792] INFO -- : post http://localhost:8080/oauth2/token
D, [2014-08-20T12:01:19.451040 #12792] DEBUG -- request: User-Agent: "Faraday v0.9.0"
Content-Type: "application/x-www-form-urlencoded"
I, [2014-08-20T12:01:19.451203 #12792] INFO -- Status: 401
D, [2014-08-20T12:01:19.451258 #12792] DEBUG -- response: cache-control: "no-cache"
pragma: "no-cache"
www-authenticate: "NTLM, BASIC realm=\"OUR_DOMAIN_NAME\""
content-type: "text/html; charset=utf-8"
proxy-connection: "close"
set-cookie: "BCSI-CS-925062b0249dae29=2; Path=/"
connection: "close"
content-length: "706"
x-rbt-optimized-by: "riv-olo (RiOS 8.5.1) IK"
OAuth2::Error - Nice page from my proxy telling me that Iâm not authentified on the domain
当我使用授权代码向POSTMAN REST客户端发出POST请求时,一切都很好,API会返回一个access_token。
我不明白为什么请求会通过代理,因为我的所有应用程序和API都在我的本地主机上。
有人能告诉我为什么使用我的本地应用程序追加此错误吗?
谢谢