2011-08-03 8 views
2

web-server flow implementationで使用するためにRack OAuth-2 serverを私のsinatraアプリケーションに統合しようとしていますが、私はそれを動作させることができません:(私はoauthコントローララックOAuth-2サーバのWebサーバフロー

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 -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 

とちょうど私が応答として得た:

HTTP/1.1 400 Bad Request 

のContent-Type:text/plainの のContent-Length:20 接続:キープアライブ サーバー:薄い1.2.11コードネームバットたわごとクレイジーを

欠落リダイレクトURL

あなたは、任意のアイデアを持っていますか私は間違っているの?ありがとう!

答えて

2

あなたのカールリクエストの終わりには、次のとおりです。

-F redirect_uri=http://localhost:4567/oauth/showcode 

いますが、上記のコードでそのルートを定義していない、つまりどこです:

get "/oauth/showcode" do 

?そのため、「リダイレクトURLがありません」というエラーが表示されます。

関連する問題