Rack OAuth-2サーバーをsinatraアプリケーションに統合して、 Webサーバーフローの実装で使用しようとしていますが、機能させることができません:(。oauthコントローラーの次のコード
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 を使用して認証コードを取得しようとします。
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 Connection: keep-alive Server: thin 1.2.11 コードネーム Bat-Shit Crazy
リダイレクト URL がありません
私が間違っていることについて何か考えがありますか?ありがとう!