Created
May 2, 2014 17:14
-
-
Save birarda/b5a626a97982f0a2813c to your computer and use it in GitHub Desktop.
Patch to allow doorkeeper authorization with an existing access token
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
From e29f4f1b84d77185bc0f2b98caaecf4d6f76d676 Mon Sep 17 00:00:00 2001 | |
From: Stephen Birarda <commit@birarda.com> | |
Date: Fri, 2 May 2014 10:12:51 -0700 | |
Subject: [PATCH] patch to allow doorkeeper authorization with access_token | |
--- | |
app/views/doorkeeper/authorizations/new.html.erb | 2 ++ | |
config/initializers/doorkeeper.rb | 8 +++++++- | |
2 files changed, 9 insertions(+), 1 deletion(-) | |
diff --git a/app/views/doorkeeper/authorizations/new.html.erb b/app/views/doorkeeper/authorizations/new.html.erb | |
index 30a2000..2f4aa54 100644 | |
--- a/app/views/doorkeeper/authorizations/new.html.erb | |
+++ b/app/views/doorkeeper/authorizations/new.html.erb | |
@@ -21,6 +21,7 @@ | |
<%= hidden_field_tag :state, @pre_auth.state %> | |
<%= hidden_field_tag :response_type, @pre_auth.response_type %> | |
<%= hidden_field_tag :scope, @pre_auth.scope %> | |
+ <%= hidden_field_tag :access_token, params[:access_token] if params.has_key?(:access_token) %> | |
<%= submit_tag "Authorize", :class => "btn success" %> or | |
<% end %> | |
</div> | |
@@ -31,6 +32,7 @@ | |
<%= hidden_field_tag :state, @pre_auth.state %> | |
<%= hidden_field_tag :response_type, @pre_auth.response_type %> | |
<%= hidden_field_tag :scope, @pre_auth.scope %> | |
+ <%= hidden_field_tag :access_token, params[:access_token] if params.has_key?(:access_token) %> | |
<%= submit_tag "Deny", :class => "btn" %> | |
<% end %> | |
</div> | |
diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb | |
index 9ed877e..61b43da 100644 | |
--- a/config/initializers/doorkeeper.rb | |
+++ b/config/initializers/doorkeeper.rb | |
@@ -5,7 +5,13 @@ Doorkeeper.configure do | |
# This block will be called to check whether the resource owner is authenticated or not. | |
resource_owner_authenticator do | |
- current_user || warden.authenticate!(:scope => :user) | |
+ if !current_user.nil? | |
+ current_user | |
+ elsif defined?(doorkeeper_token) && !doorkeeper_token.nil? | |
+ User.find(doorkeeper_token.resource_owner_id) | |
+ else | |
+ warden.authenticate!(:scope => :user) | |
+ end | |
end | |
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below. | |
-- | |
1.8.5.2 (Apple Git-48) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment