Skip to content

Commit

Permalink
adding ouath2 client support via devise-oauth2-providable fork that w…
Browse files Browse the repository at this point in the history
…orks with mongoid. Adding mitre openid server param to the UI
  • Loading branch information
rdingwell committed Feb 24, 2012
1 parent e81adf1 commit bbd7eb3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gem "capistrano"
gem 'heroku'
gem "nokogiri"
gem 'devise'
gem 'devise_oauth2_providable', :git => 'https://github.com/rdingwell/devise_oauth2_providable.git',:branch => "master"

gem 'omniauth'
gem 'omniauth-openid'
gem 'kaminari'
Expand Down
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ GIT
nokogiri (~> 1.4.7)
uuid (~> 2.3.4)

GIT
remote: https://github.com/rdingwell/devise_oauth2_providable.git
revision: 8ede1009ef9edbc8994eb6521293a68aee7e9b71
branch: master
specs:
devise_oauth2_providable (1.0.5)
devise (>= 1.4.3)
rack-oauth2 (~> 0.11.0)
rails (>= 3.1.0)

GIT
remote: https://github.com/rdingwell/ruby-openid.git
revision: cc6fa401242190344935fb12a824fa39043cffc7
Expand Down Expand Up @@ -50,6 +60,7 @@ GEM
addressable (2.2.6)
ansi (1.4.2)
arel (3.0.0)
attr_required (0.0.5)
bcrypt-ruby (3.0.1)
bson (1.5.2)
bson_ext (1.5.2)
Expand Down Expand Up @@ -108,6 +119,7 @@ GEM
term-ansicolor (~> 1.0.5)
highline (1.6.11)
hike (1.2.1)
httpclient (2.2.4)
i18n (0.6.0)
journey (1.0.1)
jquery-rails (2.0.0)
Expand Down Expand Up @@ -164,6 +176,13 @@ GEM
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
rack-oauth2 (0.11.0)
activesupport (>= 2.3)
attr_required (>= 0.0.3)
httpclient (>= 2.2.0.2)
i18n
json (>= 1.4.3)
rack (>= 1.1)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
Expand Down Expand Up @@ -238,6 +257,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
cover_me
devise
devise_oauth2_providable!
factory_girl_rails
feedzirra
health-data-standards!
Expand Down
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class User
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :trackable, :validatable,
:oauth2_providable, :oauth2_password_grantable, :oauth2_refresh_token_grantable,
:oauth2_authorization_code_grantable

field :name
# validates_presence_of :name
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</a>
</td>
<td>
<a href="#" class="auth_provider">
<a href="#" onclick="window.location='/auth/open_id?openid_url=id.mitre.org'" class="auth_provider">
<%= image_tag "mitre_open_id.png", :class => "tag", :alt => "MITRE Open ID" %>
</a>
</td>
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

match '/auth/:provider/callback' => 'authentications#create'
devise_for :users, :controllers => {:registrations => 'registrations'}

mount Devise::Oauth2Providable::Engine => '/oauth2'
resources :authentications

# The priority is based upon order of creation:
Expand Down Expand Up @@ -39,6 +39,10 @@

root :to => "records#index"

#mount the oauth2 devise provider



# Sample resource route with options:
# resources :products do
# member do
Expand Down
1 change: 1 addition & 0 deletions lib/section_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class SectionRegistry
include Singleton

attr_reader :extensions
def initialize
@extensions = []
end
Expand Down
7 changes: 7 additions & 0 deletions test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
u.password_confirmation 'password'
u.sequence(:name) { |n| "testuser#{n}"}
end


factory :client, :class => 'Devise::Oauth2Providable::Client' do |f|
f.name 'test'
f.website 'http://localhost'
f.redirect_uri 'http://localhost:3000'
end

end
27 changes: 27 additions & 0 deletions test/integration/devise_oauth2_provider_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'test_helper'

# This is just some simple testing to see that devise is configured with the OAUTH2 provider
# We are not testing the entirty of the provider, we are counting on the tests for that to cover that
# it works. We are only testing here that it is configured
class DeviseOauth2ProviderTest < ActionController::TestCase
include Devise::TestHelpers
setup do
Devise::Oauth2Providable::Client.destroy_all
@controller = Devise::Oauth2Providable::AuthorizationsController.new
@record = FactoryGirl.create(:record, :with_lab_results)
@user = FactoryGirl.create(:user)
@client = FactoryGirl.create(:client)
sign_in @user
end

test "Should Redirect to client URL without an auth token " do

get :new, :client_id => @client.cidentifier, :redirect_uri => @client.redirect_uri, :response_type => 'code', :use_route => 'devise_oauth2_providable'
assert_response :success
end

test "Should return error with bad redirect utl " do
get :new, :client_id => @client.cidentifier, :redirect_uri => "#{@client.redirect_uri}/t", :response_type => 'code', :use_route => 'devise_oauth2_providable'
assert_response 400, "Should respond with error message if redirect does not match uri"
end
end

0 comments on commit bbd7eb3

Please sign in to comment.