首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >机架OAuth-2服务器中的Web服务器流

机架OAuth-2服务器中的Web服务器流
EN

Stack Overflow用户
提问于 2011-08-04 04:52:07
回答 1查看 1K关注 0票数 2

我正在尝试将Rack OAuth-2 server集成到我的sinatra应用程序中,以便在web-server flow implementation中使用它,但我无法使其工作:(。我在oauth控制器中使用了以下代码

代码语言:javascript
复制
require "rack/oauth2/sinatra"
module RestKit
  module Network
    class OAuth2 < Sinatra::Base
       use Rack::Logger
        set :sessions, true
        set :show_exceptions, true

        ENV["DB"] = "test"
    DATABASE = Mongo::Connection.new[ENV["DB"]]

    register Rack::OAuth2::Sinatra
    oauth.authenticator = lambda do |username, password|
     "Batman" if username == "cowbell" && password == "more"       end
    oauth.host = "localhost"
    oauth.database = DATABASE


    # 3. Obtaining End-User Authorization

     before "/oauth/*" do
       halt oauth.deny! if oauth.scope.include?("time-travel") # Only Superman can do that
     end

     get "/oauth/authorize" do
       "client: #{oauth.client.display_name}\nscope: #{oauth.scope.join(", ")}\nauthorization: #{oauth.authorization}"
     end

     post "/oauth/grant" do
       oauth.grant! "Batman"
     end

     post "/oauth/deny" do
       oauth.deny!
     end


     # 5. Accessing a Protected Resource

     before { @user = oauth.identity if oauth.authenticated? }


     oauth_required "/user"

     get "/user" do
       @user
     end

     get "/list_tokens" do
       oauth.list_access_tokens("Batman").map(&:token).join(" ")
     end
   end            
  end
end

然后我尝试使用curl从终端获取授权码:

代码语言:javascript
复制
curl -i http://localhost:4567/oauth/authorize   -F response_type=code   -F client_id=[the ID]   -F client_secret=[the secret] -F redirect_uri=http://localhost:4567/oauth/showcode

我得到的回应是:

代码语言:javascript
复制
HTTP/1.1 400 Bad Request

Content-Type: text/plain Content-Length: 20连接: keep-alive服务器:瘦1.2.11代号蝙蝠-狗屎疯狂

缺少重定向URL

你知道我做错了什么吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 16:07:33

curl请求的结尾是:

代码语言:javascript
复制
-F redirect_uri=http://localhost:4567/oauth/showcode

但是您还没有在上面的代码中定义该路由,即其中:

代码语言:javascript
复制
get "/oauth/showcode" do

?这就是为什么错误是“缺少重定向URL”的原因。

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

https://stackoverflow.com/questions/6933137

复制
相关文章

相似问题

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