devise_oauth2_providable 0.3.8 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +33 -2
  2. data/README.md +23 -11
  3. data/Rakefile +8 -1
  4. data/app/controllers/devise/oauth2_providable/authorizations_controller.rb +59 -0
  5. data/app/controllers/{oauth2 → devise/oauth2_providable}/tokens_controller.rb +1 -1
  6. data/app/models/{access_token.rb → devise/oauth2_providable/access_token.rb} +1 -1
  7. data/app/models/{authorization_code.rb → devise/oauth2_providable/authorization_code.rb} +1 -1
  8. data/app/models/{client.rb → devise/oauth2_providable/client.rb} +2 -1
  9. data/app/models/{refresh_token.rb → devise/oauth2_providable/refresh_token.rb} +1 -1
  10. data/app/views/{oauth2 → devise/oauth2_providable}/authorizations/_form.html.erb +1 -1
  11. data/app/views/{oauth2 → devise/oauth2_providable}/authorizations/error.html.erb +0 -0
  12. data/app/views/devise/oauth2_providable/authorizations/new.html.erb +4 -0
  13. data/config/routes.rb +6 -6
  14. data/db/migrate/20111014160714_create_devise_oauth2_providable_schema.rb +55 -0
  15. data/devise_oauth2_providable.gemspec +7 -4
  16. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/engine.rb +2 -1
  17. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/models/oauth2_authorization_code_grantable.rb +0 -0
  18. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/models/oauth2_password_grantable.rb +0 -0
  19. data/lib/devise/oauth2_providable/models/oauth2_providable.rb +13 -0
  20. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/models/oauth2_refresh_token_grantable.rb +0 -0
  21. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/strategies/oauth2_authorization_code_grant_type_strategy.rb +2 -2
  22. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/strategies/oauth2_grant_type_strategy.rb +2 -2
  23. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/strategies/oauth2_password_grant_type_strategy.rb +1 -1
  24. data/lib/{devise_oauth2_providable/strategy.rb → devise/oauth2_providable/strategies/oauth2_providable_strategy.rb} +1 -1
  25. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/strategies/oauth2_refresh_token_grant_type_strategy.rb +1 -1
  26. data/lib/{devise_oauth2_providable → devise/oauth2_providable}/version.rb +1 -1
  27. data/lib/devise_oauth2_providable.rb +16 -14
  28. data/script/rails +6 -0
  29. data/spec/{rails_app/spec/controllers → controllers}/protected_controller_spec.rb +3 -3
  30. data/spec/{rails_app → dummy}/Rakefile +2 -2
  31. data/spec/dummy/app/assets/javascripts/application.js +7 -0
  32. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  33. data/spec/{rails_app → dummy}/app/controllers/application_controller.rb +0 -0
  34. data/spec/{rails_app → dummy}/app/controllers/protected_controller.rb +0 -0
  35. data/spec/{rails_app → dummy}/app/helpers/application_helper.rb +0 -0
  36. data/spec/{rails_app/lib/tasks → dummy/app/mailers}/.gitkeep +0 -0
  37. data/spec/{rails_app/public/javascripts → dummy/app/models}/.gitkeep +0 -0
  38. data/spec/{rails_app → dummy}/app/models/user.rb +0 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  40. data/spec/{rails_app → dummy}/config/application.rb +10 -7
  41. data/spec/dummy/config/boot.rb +10 -0
  42. data/spec/{rails_app → dummy}/config/database.yml +3 -0
  43. data/spec/{rails_app → dummy}/config/environment.rb +1 -1
  44. data/spec/{rails_app → dummy}/config/environments/development.rb +8 -4
  45. data/spec/{rails_app → dummy}/config/environments/production.rb +24 -13
  46. data/spec/{rails_app → dummy}/config/environments/test.rb +6 -2
  47. data/spec/{rails_app → dummy}/config/initializers/backtrace_silencers.rb +0 -0
  48. data/spec/{rails_app → dummy}/config/initializers/devise.rb +29 -17
  49. data/spec/{rails_app → dummy}/config/initializers/inflections.rb +0 -0
  50. data/spec/{rails_app → dummy}/config/initializers/mime_types.rb +0 -0
  51. data/spec/{rails_app → dummy}/config/initializers/secret_token.rb +1 -1
  52. data/spec/{rails_app → dummy}/config/initializers/session_store.rb +2 -2
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/spec/{rails_app → dummy}/config/locales/devise.en.yml +8 -0
  55. data/spec/{rails_app → dummy}/config/locales/en.yml +1 -1
  56. data/spec/dummy/config/routes.rb +7 -0
  57. data/spec/{rails_app → dummy}/config.ru +1 -1
  58. data/spec/{rails_app/db/migrate/20110511210926_create_users.rb → dummy/db/migrate/20111014142838_create_users.rb} +1 -7
  59. data/spec/dummy/db/migrate/20111014161437_create_devise_oauth2_providable_schema.rb +55 -0
  60. data/spec/dummy/db/schema.rb +78 -0
  61. data/spec/{rails_app/public/stylesheets → dummy/lib/assets}/.gitkeep +0 -0
  62. data/spec/{rails_app/vendor/plugins → dummy/log}/.gitkeep +0 -0
  63. data/spec/{rails_app → dummy}/public/404.html +0 -0
  64. data/spec/{rails_app → dummy}/public/422.html +0 -0
  65. data/spec/{rails_app → dummy}/public/500.html +0 -0
  66. data/spec/{rails_app → dummy}/public/favicon.ico +0 -0
  67. data/spec/{rails_app → dummy}/script/rails +0 -0
  68. data/spec/{rails_app/spec/integration → integration}/oauth2_authorization_token_grant_type_strategy_spec.rb +7 -7
  69. data/spec/{rails_app/spec/integration → integration}/oauth2_password_grant_type_strategy_spec.rb +6 -6
  70. data/spec/{rails_app/spec/integration → integration}/oauth2_refresh_token_grant_type_strategy_spec.rb +6 -6
  71. data/spec/{devise_oauth2_providable_spec.rb → lib/devise_oauth2_providable_spec.rb} +0 -0
  72. data/spec/{rails_app/spec/models → models}/access_token_spec.rb +7 -5
  73. data/spec/{rails_app/spec/models → models}/authorization_code_spec.rb +3 -3
  74. data/spec/{rails_app/spec/models → models}/client_spec.rb +5 -2
  75. data/spec/{rails_app/spec/models → models}/refresh_token_spec.rb +5 -3
  76. data/spec/models/user_spec.rb +6 -0
  77. data/spec/{rails_app/spec/routing → routing}/authorizations_routing_spec.rb +1 -1
  78. data/spec/{rails_app/spec/routing → routing}/tokens_routing_spec.rb +1 -1
  79. data/spec/spec_helper.rb +14 -20
  80. data/spec/support/match_json.rb +6 -0
  81. metadata +204 -162
  82. data/app/controllers/oauth2/authorizations_controller.rb +0 -55
  83. data/app/views/oauth2/authorizations/new.html.erb +0 -5
  84. data/lib/devise_oauth2_providable/model.rb +0 -13
  85. data/lib/devise_oauth2_providable/schema.rb +0 -61
  86. data/spec/rails_app/.gitignore +0 -4
  87. data/spec/rails_app/.rspec +0 -2
  88. data/spec/rails_app/Gemfile +0 -36
  89. data/spec/rails_app/README +0 -256
  90. data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
  91. data/spec/rails_app/config/boot.rb +0 -6
  92. data/spec/rails_app/config/routes.rb +0 -61
  93. data/spec/rails_app/db/migrate/20110511210818_create_oauth2_schema.rb +0 -8
  94. data/spec/rails_app/db/schema.rb +0 -79
  95. data/spec/rails_app/db/seeds.rb +0 -7
  96. data/spec/rails_app/doc/README_FOR_APP +0 -2
  97. data/spec/rails_app/public/images/rails.png +0 -0
  98. data/spec/rails_app/public/index.html +0 -239
  99. data/spec/rails_app/public/javascripts/application.js +0 -0
  100. data/spec/rails_app/public/robots.txt +0 -5
  101. data/spec/rails_app/spec/models/user_spec.rb +0 -8
  102. data/spec/rails_app/spec/spec_helper.rb +0 -36
data/.gitignore CHANGED
@@ -1,4 +1,35 @@
1
- *.gem
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
2
12
  .bundle
3
13
  Gemfile.lock
4
- pkg/*
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # test files
19
+ test/*.log
20
+ test/*.sqlite3
21
+
22
+ # For vim:
23
+ *.swp
24
+
25
+ # For MacOS:
26
+ .DS_Store
27
+
28
+ # git files
29
+ *.orig
30
+
31
+ # rails files
32
+ tmp
33
+ log
34
+ *.log
35
+ *.sqlite3
data/README.md CHANGED
@@ -3,35 +3,47 @@
3
3
  Rails3 engine that brings OAuth2 Provider support to your application.
4
4
 
5
5
  Current OAuth2 Specification Draft:
6
- http://tools.ietf.org/html/draft-ietf-oauth-v2-15
6
+ http://tools.ietf.org/html/draft-ietf-oauth-v2-22
7
7
 
8
8
  ## Features
9
9
 
10
- * integrates OAuth2 authentication with Devise authenthentication stack
10
+ * integrate OAuth2 authentication with Devise authenthentication stack
11
11
  * one-stop-shop includes all Models, Controllers and Views to get up and
12
12
  running quickly
13
13
  * All server requests support authentication via bearer token included in
14
14
  the request. http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-04
15
+ * customizable mount point for oauth2 routes (ex: /oauth2 vs /oauth)
15
16
 
16
17
 
18
+ ## Requirements
19
+
20
+ * Devise authentication library
21
+ * Rails 3.1 or higher
22
+
17
23
  ## Installation
18
24
 
25
+ #### Install gem
19
26
  ```ruby
20
- # Bundler Gemfile
27
+ # Gemfile
21
28
  gem 'devise_oauth2_providable'
22
29
  ```
23
30
 
31
+ #### Migrate database for Oauth2 models
32
+ ```
33
+ $ rake devise_oauth2_providable:install:migrations
34
+ $ rake db:migrate
35
+ ```
36
+
37
+ #### Add Oauth2 Routes
24
38
  ```ruby
25
- # create new Rails migration
26
- class CreateOauth2Schema < ActiveRecord::Migration
27
- def self.up
28
- Devise::Oauth2Providable::Schema.up(self)
29
- end
30
- def self.down
31
- Devise::Oauth2Providable::Schema.down(self)
32
- end
39
+ # config/routes.rb
40
+ Rails.application.routes.draw do
41
+ # oauth routes can be mounted to any path (ex: /oauth2 or /oauth)
42
+ mount Devise::Oauth2Providable::Engine => '/oauth2'
33
43
  end
34
44
  ```
45
+
46
+ #### Configure User for supported Oauth2 flows
35
47
  ```ruby
36
48
  class User
37
49
  # NOTE: include :database_authenticatable configuration
data/Rakefile CHANGED
@@ -1,7 +1,14 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+ load 'rails/tasks/engine.rake'
11
+
4
12
  require 'rspec/core/rake_task'
5
13
  RSpec::Core::RakeTask.new('spec')
6
14
  task :default => :spec
7
-
@@ -0,0 +1,59 @@
1
+ module Devise
2
+ module Oauth2Providable
3
+ class AuthorizationsController < ApplicationController
4
+ before_filter :authenticate_user!
5
+
6
+ rescue_from Rack::OAuth2::Server::Authorize::BadRequest do |e|
7
+ @error = e
8
+ render :error, :status => e.status
9
+ end
10
+
11
+ def new
12
+ respond *authorize_endpoint.call(request.env)
13
+ end
14
+
15
+ def create
16
+ respond *authorize_endpoint(:allow_approval).call(request.env)
17
+ end
18
+
19
+ private
20
+
21
+ def respond(status, header, response)
22
+ ["WWW-Authenticate"].each do |key|
23
+ headers[key] = header[key] if header[key].present?
24
+ end
25
+ if response.redirect?
26
+ redirect_to header['Location']
27
+ else
28
+ render :new
29
+ end
30
+ end
31
+
32
+ def authorize_endpoint(allow_approval = false)
33
+ Rack::OAuth2::Server::Authorize.new do |req, res|
34
+ @client = Client.find_by_identifier(req.client_id) || req.bad_request!
35
+ res.redirect_uri = @redirect_uri = req.verify_redirect_uri!(@client.redirect_uri)
36
+ if allow_approval
37
+ if params[:approve].present?
38
+ case req.response_type
39
+ when :code
40
+ authorization_code = current_user.authorization_codes.create(:client => @client, :redirect_uri => @redirect_uri)
41
+ res.code = authorization_code.token
42
+ when :token
43
+ access_token = current_user.access_tokens.create(:client => @client).token
44
+ bearer_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => access_token)
45
+ res.access_token = bearer_token
46
+ res.uid = current_user.id
47
+ end
48
+ res.approve!
49
+ else
50
+ req.access_denied!
51
+ end
52
+ else
53
+ @response_type = req.response_type
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,4 +1,4 @@
1
- class Oauth2::TokensController < ApplicationController
1
+ class Devise::Oauth2Providable::TokensController < ApplicationController
2
2
  before_filter :authenticate_user!
3
3
 
4
4
  def create
@@ -1,6 +1,6 @@
1
1
  require 'expirable_token'
2
2
 
3
- class AccessToken < ActiveRecord::Base
3
+ class Devise::Oauth2Providable::AccessToken < ActiveRecord::Base
4
4
  include ExpirableToken
5
5
  self.default_lifetime = 15.minutes
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'expirable_token'
2
2
 
3
- class AuthorizationCode < ActiveRecord::Base
3
+ class Devise::Oauth2Providable::AuthorizationCode < ActiveRecord::Base
4
4
  include ExpirableToken
5
5
  def access_token
6
6
  @access_token ||= expired! && user.access_tokens.create(:client => client)
@@ -1,6 +1,7 @@
1
- class Client < ActiveRecord::Base
1
+ class Devise::Oauth2Providable::Client < ActiveRecord::Base
2
2
  has_many :access_tokens
3
3
  has_many :refresh_tokens
4
+ has_many :authorization_codes
4
5
 
5
6
  before_validation :init_identifier, :on => :create, :unless => :identifier?
6
7
  before_validation :init_secret, :on => :create, :unless => :secret?
@@ -1,6 +1,6 @@
1
1
  require 'expirable_token'
2
2
 
3
- class RefreshToken < ActiveRecord::Base
3
+ class Devise::Oauth2Providable::RefreshToken < ActiveRecord::Base
4
4
  include ExpirableToken
5
5
  self.default_lifetime = 1.month
6
6
  has_many :access_tokens
@@ -1,4 +1,4 @@
1
- <%= form_tag oauth2_authorizations_path, :class => action do %>
1
+ <%= form_tag authorizations_path, :class => action do %>
2
2
  <%= hidden_field_tag :client_id, client.identifier %>
3
3
  <%= hidden_field_tag :response_type, response_type %>
4
4
  <%= hidden_field_tag :redirect_uri, redirect_uri %>
@@ -0,0 +1,4 @@
1
+ <h2><%= link_to @client.name, @client.website %> is requesting permission to access your resources.</h2>
2
+
3
+ <%= render 'devise/oauth2_providable/authorizations/form', :client => @client, :response_type => @response_type, :redirect_uri => @redirect_uri, :action => :approve %>
4
+ <%= render 'devise/oauth2_providable/authorizations/form', :client => @client, :response_type => @response_type, :redirect_uri => @redirect_uri, :action => :deny %>
data/config/routes.rb CHANGED
@@ -1,7 +1,7 @@
1
- Rails.application.routes.draw do
2
- scope '/oauth2', :as => 'oauth2' do
3
- resources :authorizations, :controller => 'oauth2/authorizations', :only => :create
4
- match 'authorize' => 'oauth2/authorizations#new'
5
- resource :token, :controller => 'oauth2/tokens', :only => :create
6
- end
1
+ Devise::Oauth2Providable::Engine.routes.draw do
2
+ root :to => "authorizations#new"
3
+
4
+ resources :authorizations, :only => :create
5
+ match 'authorize' => 'authorizations#new'
6
+ resource :token, :only => :create
7
7
  end
@@ -0,0 +1,55 @@
1
+ class CreateDeviseOauth2ProvidableSchema < ActiveRecord::Migration
2
+ def change
3
+ create_table :oauth2_clients do |t|
4
+ t.string :name
5
+ t.string :redirect_uri
6
+ t.string :website
7
+ t.string :identifier
8
+ t.string :secret
9
+ t.timestamps
10
+ end
11
+ change_table :oauth2_clients do |t|
12
+ t.index :identifier, :unique => true
13
+ end
14
+
15
+ create_table :oauth2_access_tokens do |t|
16
+ t.belongs_to :user, :client, :refresh_token
17
+ t.string :token
18
+ t.datetime :expires_at
19
+ t.timestamps
20
+ end
21
+ change_table :oauth2_access_tokens do |t|
22
+ t.index :token, :unique => true
23
+ t.index :expires_at
24
+ t.index :user_id
25
+ t.index :client_id
26
+ end
27
+
28
+ create_table :oauth2_refresh_tokens do |t|
29
+ t.belongs_to :user, :client
30
+ t.string :token
31
+ t.datetime :expires_at
32
+ t.timestamps
33
+ end
34
+ change_table :oauth2_refresh_tokens do |t|
35
+ t.index :token, :unique => true
36
+ t.index :expires_at
37
+ t.index :user_id
38
+ t.index :client_id
39
+ end
40
+
41
+ create_table :oauth2_authorization_codes do |t|
42
+ t.belongs_to :user, :client
43
+ t.string :token
44
+ t.datetime :expires_at
45
+ t.string :redirect_uri
46
+ t.timestamps
47
+ end
48
+ change_table :oauth2_authorization_codes do |t|
49
+ t.index :token, :unique => true
50
+ t.index :expires_at
51
+ t.index :user_id
52
+ t.index :client_id
53
+ end
54
+ end
55
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "devise_oauth2_providable/version"
3
+ require "devise/oauth2_providable/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "devise_oauth2_providable"
@@ -14,10 +14,13 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "devise_oauth2_providable"
16
16
 
17
- s.add_runtime_dependency(%q<rails>, [">= 3.0.7"])
18
- s.add_runtime_dependency(%q<devise>, [">= 1.3.3"])
17
+ s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
18
+ s.add_runtime_dependency(%q<devise>, [">= 1.4.3"])
19
19
  s.add_runtime_dependency(%q<rack-oauth2>, ["~> 0.11.0"])
20
- s.add_development_dependency(%q<rspec>, ['>= 2.5.0'])
20
+ s.add_development_dependency(%q<rspec-rails>, ['2.6.1'])
21
+ s.add_development_dependency(%q<sqlite3>, ['1.3.4'])
22
+ s.add_development_dependency(%q<shoulda-matchers>, ['1.0.0.beta3'])
23
+ s.add_development_dependency(%q<pry>, ['0.9.6.2'])
21
24
 
22
25
  s.files = `git ls-files`.split("\n")
23
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,10 +1,11 @@
1
1
  module Devise
2
2
  module Oauth2Providable
3
3
  class Engine < Rails::Engine
4
+ engine_name 'oauth2'
5
+ isolate_namespace Devise::Oauth2Providable
4
6
  initializer "devise_oauth2_providable.initialize_application" do |app|
5
7
  app.config.filter_parameters << :client_secret
6
8
  end
7
9
  end
8
10
  end
9
11
  end
10
-
@@ -0,0 +1,13 @@
1
+ require 'devise/models'
2
+
3
+ module Devise
4
+ module Models
5
+ module Oauth2Providable
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ has_many :access_tokens, :class_name => 'Devise::Oauth2Providable::AccessToken'
9
+ has_many :authorization_codes, :class_name => 'Devise::Oauth2Providable::AuthorizationCode'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- require 'devise_oauth2_providable/strategies/oauth2_grant_type_strategy'
1
+ require 'devise/oauth2_providable/strategies/oauth2_grant_type_strategy'
2
2
 
3
3
  module Devise
4
4
  module Strategies
@@ -8,7 +8,7 @@ module Devise
8
8
  end
9
9
 
10
10
  def authenticate!
11
- if client && code = AuthorizationCode.valid.find_by_token(params[:code])
11
+ if client && code = client.authorization_codes.valid.find_by_token(params[:code])
12
12
  success! code.user
13
13
  elsif !halted?
14
14
  oauth_error! :invalid_grant, 'invalid authorization code request'
@@ -4,7 +4,7 @@ module Devise
4
4
  module Strategies
5
5
  class Oauth2GrantTypeStrategy < Authenticatable
6
6
  def valid?
7
- params[:controller] == 'oauth2/tokens' && request.post? && params[:grant_type] == grant_type
7
+ params[:controller] == 'devise/oauth2_providable/tokens' && request.post? && params[:grant_type] == grant_type
8
8
  end
9
9
 
10
10
  # defined by subclass
@@ -12,7 +12,7 @@ module Devise
12
12
  end
13
13
 
14
14
  def client
15
- @client ||= Client.find_by_identifier params[:client_id]
15
+ @client ||= Devise::Oauth2Providable::Client.find_by_identifier params[:client_id]
16
16
  env['oauth2.client'] = @client
17
17
  @client
18
18
  end
@@ -1,4 +1,4 @@
1
- require 'devise_oauth2_providable/strategies/oauth2_grant_type_strategy'
1
+ require 'devise/oauth2_providable/strategies/oauth2_grant_type_strategy'
2
2
 
3
3
  module Devise
4
4
  module Strategies
@@ -9,7 +9,7 @@ module Devise
9
9
  end
10
10
  def authenticate!
11
11
  @req.setup!
12
- token = AccessToken.valid.find_by_token @req.access_token
12
+ token = Devise::Oauth2Providable::AccessToken.valid.find_by_token @req.access_token
13
13
  env['oauth2.client'] = token ? token.client : nil
14
14
  resource = token ? token.user : nil
15
15
  if validate(resource)
@@ -1,4 +1,4 @@
1
- require 'devise_oauth2_providable/strategies/oauth2_grant_type_strategy'
1
+ require 'devise/oauth2_providable/strategies/oauth2_grant_type_strategy'
2
2
 
3
3
  module Devise
4
4
  module Strategies
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Oauth2Providable
3
- VERSION = "0.3.8"
3
+ VERSION = "1.0.0.beta1"
4
4
  end
5
5
  end
@@ -1,15 +1,14 @@
1
1
  require 'devise'
2
2
  require 'rack/oauth2'
3
- require 'devise_oauth2_providable/strategy'
4
- require 'devise_oauth2_providable/model'
5
- require 'devise_oauth2_providable/schema'
6
- require 'devise_oauth2_providable/engine'
7
- require 'devise_oauth2_providable/strategies/oauth2_password_grant_type_strategy'
8
- require 'devise_oauth2_providable/strategies/oauth2_refresh_token_grant_type_strategy'
9
- require 'devise_oauth2_providable/strategies/oauth2_authorization_code_grant_type_strategy'
10
- require 'devise_oauth2_providable/models/oauth2_password_grantable'
11
- require 'devise_oauth2_providable/models/oauth2_refresh_token_grantable'
12
- require 'devise_oauth2_providable/models/oauth2_authorization_code_grantable'
3
+ require 'devise/oauth2_providable/engine'
4
+ require 'devise/oauth2_providable/strategies/oauth2_providable_strategy'
5
+ require 'devise/oauth2_providable/strategies/oauth2_password_grant_type_strategy'
6
+ require 'devise/oauth2_providable/strategies/oauth2_refresh_token_grant_type_strategy'
7
+ require 'devise/oauth2_providable/strategies/oauth2_authorization_code_grant_type_strategy'
8
+ require 'devise/oauth2_providable/models/oauth2_providable'
9
+ require 'devise/oauth2_providable/models/oauth2_password_grantable'
10
+ require 'devise/oauth2_providable/models/oauth2_refresh_token_grantable'
11
+ require 'devise/oauth2_providable/models/oauth2_authorization_code_grantable'
13
12
 
14
13
  module Devise
15
14
  module Oauth2Providable
@@ -17,19 +16,22 @@ module Devise
17
16
  def random_id
18
17
  SecureRandom.hex
19
18
  end
19
+ def table_name_prefix
20
+ 'oauth2_'
21
+ end
20
22
  end
21
23
  end
22
24
  end
23
25
 
24
26
  Devise.add_module(:oauth2_providable,
25
27
  :strategy => true,
26
- :model => 'devise_oauth2_providable/model')
28
+ :model => 'devise/oauth2_providable/models/oauth2_providable')
27
29
  Devise.add_module(:oauth2_password_grantable,
28
30
  :strategy => true,
29
- :model => 'devise_oauth2_providable/models/oauth2_password_grantable')
31
+ :model => 'devise/oauth2_providable/models/oauth2_password_grantable')
30
32
  Devise.add_module(:oauth2_refresh_token_grantable,
31
33
  :strategy => true,
32
- :model => 'devise_oauth2_providable/models/oauth2_refresh_token_grantable')
34
+ :model => 'devise/oauth2_providable/models/oauth2_refresh_token_grantable')
33
35
  Devise.add_module(:oauth2_authorization_code_grantable,
34
36
  :strategy => true,
35
- :model => 'devise_oauth2_providable/models/oauth2_authorization_code_grantable')
37
+ :model => 'devise/oauth2_providable/models/oauth2_authorization_code_grantable')
data/script/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
+
5
+ ENGINE_PATH = File.expand_path('../..', __FILE__)
6
+ load File.expand_path('../../spec/dummy/script/rails', __FILE__)
@@ -4,9 +4,9 @@ describe ProtectedController do
4
4
 
5
5
  describe 'get :index' do
6
6
  before do
7
- client = Client.create! :name => 'test', :redirect_uri => 'http://localhost:3000', :website => 'http://localhost'
8
- @user = User.create! :name => 'ryan sonnek', :email => 'foo@example.com'
9
- @token = AccessToken.create! :client => client, :user => @user
7
+ client = Devise::Oauth2Providable::Client.create! :name => 'test', :redirect_uri => 'http://localhost:3000', :website => 'http://localhost'
8
+ @user = User.create! :email => 'foo@example.com'
9
+ @token = Devise::Oauth2Providable::AccessToken.create! :client => client, :user => @user
10
10
  end
11
11
  context 'with valid bearer token in header' do
12
12
  before do
@@ -1,7 +1,7 @@
1
+ #!/usr/bin/env rake
1
2
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
3
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
4
 
4
5
  require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
6
 
7
- RailsApp::Application.load_tasks
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -2,11 +2,10 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- # If you have a Gemfile, require the gems listed there, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(:default, Rails.env) if defined?(Bundler)
5
+ Bundler.require
6
+ require "devise_oauth2_providable"
8
7
 
9
- module RailsApp
8
+ module Dummy
10
9
  class Application < Rails::Application
11
10
  # Settings in config/environments/* take precedence over those specified here.
12
11
  # Application configuration should go into files in config/initializers
@@ -30,13 +29,17 @@ module RailsApp
30
29
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
30
  # config.i18n.default_locale = :de
32
31
 
33
- # JavaScript files you want as :defaults (application.js is always included).
34
- config.action_view.javascript_expansions[:defaults] = %w()
35
-
36
32
  # Configure the default encoding used in templates for Ruby 1.9.
37
33
  config.encoding = "utf-8"
38
34
 
39
35
  # Configure sensitive parameters which will be filtered from the log file.
40
36
  config.filter_parameters += [:password]
37
+
38
+ # Enable the asset pipeline
39
+ config.assets.enabled = true
40
+
41
+ # Version of your assets, change this if you want to expire all your assets
42
+ config.assets.version = '1.0'
41
43
  end
42
44
  end
45
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,5 +1,8 @@
1
1
  # SQLite version 3.x
2
2
  # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
3
6
  development:
4
7
  adapter: sqlite3
5
8
  database: db/development.sqlite3
@@ -2,4 +2,4 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the rails application
5
- RailsApp::Application.initialize!
5
+ Dummy::Application.initialize!