Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adapting OAuth to mongoid - rough

  • Loading branch information...
commit a6ad0544b4b8fec1197fa9b2cf75bf0c6a9d438a 1 parent 912c346
@rosic rosic authored
View
8 app/controllers/oauth_controller.rb
@@ -20,4 +20,12 @@ class OauthController < ApplicationController
# end
# end
+ def current_user
+ User.first
+ end
+
+ def login_required
+
+ end
+
end
View
10 app/models/client_application.rb
@@ -32,6 +32,15 @@ class ClientApplication
attr_accessor :token_callback_url
+ def self.find_by_key!(key)
+ app = ClientApplication.where(:key => key)
+ if app
+ app.first
+ else
+ Raise "Application not found"
+ end
+ end
+
def self.find_token(token_key)
token = OauthToken.where(:token => token_key)
if token && token.authorized?
@@ -71,3 +80,4 @@ def generate_keys
self.secret = OAuth::Helper.generate_key(40)[0,40]
end
end
+
View
19 app/models/oauth2_verifier.rb
@@ -2,14 +2,23 @@ class Oauth2Verifier < OauthToken
validates_presence_of :user
attr_accessor :state
- def exchange!(params={})
- OauthToken.transaction do
- token = Oauth2Token.create! :user=>user,:client_application=>client_application, :scope => scope
- invalidate!
- token
+ def self.find_by_token(token_key)
+ token = Oauth2Verifier.where(:token => token_key)
+ if token
+ token.first
+ else
+ nil
end
end
+ def exchange!(params={})
+ #OauthToken.transaction do
+ token = Oauth2Token.create! :user=>user,:client_application=>client_application, :scope => scope
+ invalidate!
+ token
+ #end
+ end
+
def code
token
end
View
1  app/models/oauth_token.rb
@@ -12,6 +12,7 @@ class OauthToken
field :authorized_at, :type => Time
field :invalidated_at, :type => Time
field :valid_to, :type => Time
+ field :expires_at, :type => Time
index :token, :unique => true
View
1  app/views/layouts/application.html.haml
@@ -18,5 +18,6 @@
%li{:class => (:active if params[:controller] == "custom_fields")}= link_to "Custom fields", custom_fields_path
%li{:class => (:active if params[:controller] == "work_item_types")}= link_to "Work item types", work_item_types_path
%li{:class => (:active if params[:controller] == "work_items")}= link_to "Work items", work_items_path
+ %li{:class => (:active if params[:controller] == "oauth_clients")}= link_to "OAuth Clients", oauth_clients_path
.container= yield
View
2  app/views/oauth_clients/index.html.haml
@@ -11,7 +11,7 @@
%th Issued
%th &nbsp;
- @tokens.each do |token|
- - content_tag_for :tr, token do
+ %tr
%td= link_to token.client_application.name, token.client_application.url
%td= token.authorized_at
%td
View
1  config/routes.rb
@@ -12,6 +12,7 @@
match '/oauth/authorize', :to => 'oauth#authorize', :as => :authorize
match '/oauth', :to => 'oauth#index', :as => :oauth
+ match '/oauth/revoke', :to => 'oauth#revoke', :as => :oauth
# The priority is based upon order of creation:
# first created -> highest priority.
Please sign in to comment.
Something went wrong with that request. Please try again.