forked from pelle/oauth-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first stab at moving the oauth signature verification part to a rack
filter
- Loading branch information
Showing
4 changed files
with
111 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
# leaving this empty | ||
require 'oauth' | ||
require 'oauth/signature/hmac/sha1' | ||
require 'oauth/rack/oauth_filter' | ||
require 'oauth/request_proxy/rack_request' | ||
require 'oauth/server' | ||
require 'oauth/controllers/application_controller_methods' | ||
|
||
|
||
module OAuth | ||
module Plugin | ||
class OAuthRailtie < Rails::Railtie | ||
initializer "oauth-plugin.configure_rails_initialization" do |app| | ||
app.middleware.insert_before ActionDispatch::Cookies, OAuth::Rack::OAuthFilter | ||
ActionController::Base.send :include, OAuth::Controllers::ApplicationControllerMethods | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "rack" | ||
require "rack/request" | ||
require "oauth/signature" | ||
module OAuth | ||
module Rack | ||
class OAuthFilter | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
request = ::Rack::Request.new(env) | ||
env["oauth_plugin"]=true | ||
if ClientApplication.verify_request(request) do |request_proxy| | ||
client_application = ClientApplication.find_by_key(request_proxy.consumer_key) | ||
env["oauth.client_application_candidate"] = client_application | ||
# Store this temporarily in client_application object for use in request token generation | ||
client_application.token_callback_url=request_proxy.oauth_callback if request_proxy.oauth_callback | ||
|
||
oauth_token = client_application.tokens.first(:conditions=>{:token => request_proxy.token}) | ||
if oauth_token.respond_to?(:provided_oauth_verifier=) | ||
oauth_token.provided_oauth_verifier=request_proxy.oauth_verifier | ||
end | ||
env["oauth.token_candidate"] = oauth_token | ||
# return the token secret and the consumer secret | ||
[(oauth_token.nil? ? nil : oauth_token.secret), (client_application.nil? ? nil : client_application.secret)] | ||
end | ||
env["oauth.token"] = env["oauth.token_candidate"] | ||
env["oauth.client_application"] = env["oauth.client_application_candidate"] | ||
# Rails.logger.info "oauth.token = #{env["oauth.token"].inspect}" | ||
end | ||
env["oauth.client_application_candidate"] = nil | ||
env["oauth.token_candidate"] = nil | ||
response = @app.call(env) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
require 'oauth' | ||
require 'oauth/signature/hmac/sha1' | ||
if Rails.version =~ /^3\./ | ||
require 'oauth/request_proxy/rack_request' | ||
else | ||
require 'oauth/request_proxy/action_controller_request' | ||
end | ||
require 'oauth/rack/oauth_filter' | ||
require 'oauth/server' | ||
require 'oauth/controllers/application_controller_methods' | ||
|
||
ActionController::Base.send :include, OAuth::Controllers::ApplicationControllerMethods | ||
if Rails.version =~ /^2\./ | ||
require 'oauth/request_proxy/action_controller_request' | ||
ActionController::Base.send :include, OAuth::Controllers::ApplicationControllerMethods | ||
end |