oauned 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,23 +1,25 @@
1
1
  # Oauned
2
2
 
3
3
  Rails Engine that lets you become an OAuth Provider.
4
+ [![Travis](https://secure.travis-ci.org/evome/oauned.png)](http://travis-ci.org/evome/oauned)
4
5
 
5
6
  ## Installation
6
7
 
7
- You can use the latest gem which is on rubygems.
8
+ Add this to your Gemfile :
8
9
 
9
- gem install oauned
10
+ gem 'oauned'
11
+ gem 'devise'
10
12
 
11
- Don't forget to add it to your Gemfile !
12
-
13
- Then, you must create the local models.
13
+ Then, you must execute the generators :
14
14
 
15
+ rails g devise:install
16
+ rails g devise user
15
17
  rails g oauned:install
16
18
 
17
- This will create three models in your application : `Application`, `Authorization`, `Connection`
18
- You'll need a fourth one, which is not created : `User`. The authentication management gem you're using should be creating it, not us.
19
+ This will create three models in your application : `Application`, `Authorization`, `Connection`.
20
+ Devise will also create a fourth one : `User`.
19
21
 
20
- You can easily rename those models. Just change their name and the relations names between them.
22
+ You can't currently rename those models and hope for oauned to keep working. This is something we intend to do though.
21
23
 
22
24
  A route is also created.
23
25
 
@@ -64,11 +66,11 @@ We're open to any contribution. It has to be tested properly though.
64
66
  * [Fork](http://help.github.com/forking/) the project
65
67
  * Do your changes and commit them to your repository
66
68
  * Test your changes. We won't accept any untested contributions (except if they're not testable).
67
- * Create an [issue](https://github.com/dmathieu/oauned/issues) with a link to your commits.
69
+ * Create an [issue](https://github.com/evome/oauned/issues) with a link to your commits.
68
70
 
69
71
  ## Maintainers
70
72
 
71
- * Damien MATHIEU (http://github.com/dmathieu)
73
+ * Damien MATHIEU ([github/dmathieu](http://github.com/dmathieu), [dmathieu.com](http://dmathieu.com))
72
74
 
73
75
  ## License
74
- MIT License. Copyright 2010 Damien MATHIEU. http://dmathieu.com
76
+ MIT License. Copyright 2010 Evome. http://evome.fr
@@ -1,14 +1,19 @@
1
1
  module Oauned
2
2
  module Generators
3
3
  module Helpers
4
-
4
+
5
+ private
5
6
  def model_exists?(model)
6
7
  File.exists?(File.join(destination_root, model_path(model)))
7
8
  end
8
-
9
+
9
10
  def model_path(model)
10
11
  File.join("app", "models", "#{model}.rb")
11
12
  end
13
+
14
+ def migration_exists?(model_name)
15
+ Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_oauned_to_#{model_name}.rb$/).first
16
+ end
12
17
  end
13
18
  end
14
- end
19
+ end
@@ -3,47 +3,97 @@ require 'generators/oauned/helpers'
3
3
 
4
4
  module Oauned
5
5
  module Generators
6
- class InstallGenerator < Rails::Generators::Base
7
- source_root File.expand_path("../templates", __FILE__)
6
+ class InstallGenerator < ActiveRecord::Generators::Base
8
7
  include Oauned::Generators::Helpers
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ argument :authorization,
11
+ :type => :string,
12
+ :default => "authorization"
13
+ argument :connection,
14
+ :type => :string,
15
+ :default => "connection"
9
16
 
10
17
  desc "Creates the oauned routes and models"
11
18
  def add_oauned_routes
12
19
  route "scope '/scoped' { oauned_routing }"
13
20
  end
14
-
21
+
22
+ def copy_migration
23
+ [:application, :authorization, :connection].each do |model_sym|
24
+ model_name = send(model_sym)
25
+ @table_name = model_name.pluralize
26
+ if (behavior == :invoke && model_exists?(model_name)) || (behavior == :revoke && migration_exists?(model_name))
27
+ migration_template "migration_existing.rb",
28
+ "db/migrate/add_oauned_to_#{model_name}"
29
+ else
30
+ migration_template "migration.rb",
31
+ "db/migrate/oauned_create_#{model_name}"
32
+ end
33
+ end
34
+ end
35
+
15
36
  def create_models
16
- [:application, :authorization, :connection].each do |model|
17
- invoke "active_record:model", [model], :migration => false unless model_exists?(model) && behavior == :invoke
37
+ [:application, :authorization, :connection].each do |model_sym|
38
+ model_name = send(model_sym)
39
+ if !model_exists?(model_name) && behavior == :invoke
40
+ Rails::Generators.invoke "active_record:model",
41
+ [model_name],
42
+ :migration => false,
43
+ :destination_root => destination_root
44
+ require File.join(destination_root, model_path(model_name))
45
+ end
18
46
  end
19
47
  end
20
-
48
+
21
49
  def inject_application_content
22
- inject_into_class model_path(:application), Application, <<EOS if model_exists?(:authorization)
50
+ if model_exists?(application)
51
+ inject_into_class model_path(application),
52
+ application.capitalize.constantize,
53
+ <<EOS
23
54
  include Oauned::Models::Application
24
-
55
+
25
56
  has_many :authorizations
26
57
  has_many :connections
27
58
  EOS
59
+ end
28
60
  end
29
-
61
+
30
62
  def inject_authorization_content
31
- inject_into_class model_path(:authorization), Application, <<EOS if model_exists?(:authorization)
63
+ if model_exists?(authorization)
64
+ inject_into_class model_path(authorization),
65
+ authorization.capitalize.constantize,
66
+ <<EOS
32
67
  include Oauned::Models::Authorization
33
-
68
+
34
69
  belongs_to :user
35
70
  belongs_to :application
36
71
  EOS
72
+ end
37
73
  end
38
-
74
+
39
75
  def inject_connection_content
40
- inject_into_class model_path(:connection), Application, <<EOS if model_exists?(:authorization)
76
+ if model_exists?(connection)
77
+ inject_into_class model_path(connection),
78
+ connection.capitalize.constantize,
79
+ <<EOS
41
80
  include Oauned::Models::Connection
42
-
81
+
43
82
  belongs_to :user
44
83
  belongs_to :application
45
84
  EOS
85
+ end
86
+ end
87
+
88
+ private
89
+ #
90
+ # We can't use an argument, but must rely on the name attribute
91
+ # Because ActiveRecord::Generators::Base extends from NamedBase
92
+ #
93
+ def application
94
+ @application ||= name || "application"
46
95
  end
96
+
47
97
  end
48
98
  end
49
- end
99
+ end
@@ -0,0 +1,12 @@
1
+ class OaunedCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :<%= table_name %>
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class AddDOaunedTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:<%= table_name %>) do |t|
4
+ # Uncomment below if timestamps were not included in your original model.
5
+ # t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ # By default, we don't want to make any assumption about how to roll back a migration when your
11
+ # model already existed. Please edit below which fields you would like to remove in this migration.
12
+ raise ActiveRecord::IrreversibleMigration
13
+ end
14
+ end
data/lib/oauned.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Oauned
2
2
  autoload :ControllerMethods, 'oauned/controller_methods'
3
3
  autoload :Models, 'oauned/models'
4
-
4
+ autoload :Version, 'oauned/version'
5
+
5
6
  end
6
7
 
7
- require 'oauned/rails'
8
+ require 'oauned/rails'
@@ -28,7 +28,7 @@ module Oauned
28
28
 
29
29
  private
30
30
  def user_from_oauth
31
- token = Connection.where(:access_token => params[:access_token]).first
31
+ token = Connection.where(['access_token LIKE ?', params[:access_token]]).first
32
32
  token.user if (token && !token.expired?)
33
33
  end
34
34
 
data/lib/oauned/models.rb CHANGED
@@ -2,4 +2,14 @@ module Oauned::Models
2
2
  autoload :Application, 'oauned/models/application'
3
3
  autoload :Authorization, 'oauned/models/authorization'
4
4
  autoload :Connection, 'oauned/models/connection'
5
- end
5
+
6
+
7
+ @@models = {}
8
+ def self.[](key)
9
+ @@models[key]
10
+ end
11
+
12
+ def self.[]=(key, value)
13
+ @@models[key] = value
14
+ end
15
+ end
@@ -1,5 +1,7 @@
1
1
  module Oauned::Models::Application
2
2
  def self.included(klass)
3
+ Oauned::Models['application'] = klass
4
+
3
5
  klass.class_eval do
4
6
  before_create :set_default
5
7
 
@@ -13,4 +15,4 @@ module Oauned::Models::Application
13
15
  end
14
16
  end
15
17
  end
16
- end
18
+ end
@@ -1,5 +1,7 @@
1
1
  module Oauned::Models::Authorization
2
2
  def self.included(klass)
3
+ Oauned::Models['authorization'] = klass
4
+
3
5
  klass.class_eval do
4
6
  before_create :set_default
5
7
 
@@ -12,7 +14,7 @@ module Oauned::Models::Authorization
12
14
 
13
15
  def tokenize!
14
16
  self.destroy
15
- Connection.create!(:user_id => user.id, :application_id => application.id)
17
+ Connection.create!(:user_id => user_id, :application_id => application_id)
16
18
  end
17
19
 
18
20
  private
@@ -22,4 +24,4 @@ module Oauned::Models::Authorization
22
24
  end
23
25
  end
24
26
  end
25
- end
27
+ end
@@ -1,5 +1,7 @@
1
1
  module Oauned::Models::Connection
2
2
  def self.included(klass)
3
+ Oauned::Models['connection'] = klass
4
+
3
5
  klass.class_eval do
4
6
  before_create :set_default
5
7
 
@@ -18,8 +20,9 @@ module Oauned::Models::Connection
18
20
  private
19
21
  def set_default
20
22
  self.access_token = SecureRandom.hex(20)
23
+ self.refresh_token = SecureRandom.hex(20)
21
24
  self.expires_at = 1.hour.from_now
22
25
  end
23
26
  end
24
27
  end
25
- end
28
+ end
@@ -1,10 +1,10 @@
1
1
  module ActionDispatch::Routing
2
2
  class Mapper
3
-
3
+
4
4
  def oauned_routing
5
5
  get '/' => 'oauned/oauth#index', :as => 'oauth'
6
6
  post '/' => 'oauned/oauth#authorize'
7
7
  post '/token' => 'oauned/oauth#token'
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Oauned
2
+ VERSION = "1.0.0"
3
+ end
metadata CHANGED
@@ -1,34 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oauned
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors: []
12
-
7
+ authors:
8
+ - Damien MATHIEU
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-21 00:00:00 +01:00
12
+ date: 2011-09-13 00:00:00.000000000 +02:00
18
13
  default_executable:
19
14
  dependencies: []
20
-
21
15
  description: Rails Engine to be an Oauth Provider
22
16
  email:
23
17
  executables: []
24
-
25
18
  extensions: []
26
-
27
19
  extra_rdoc_files: []
28
-
29
- files:
20
+ files:
30
21
  - lib/generators/oauned/helpers.rb
31
22
  - lib/generators/oauned/install_generator.rb
23
+ - lib/generators/oauned/templates/migration.rb
24
+ - lib/generators/oauned/templates/migration_existing.rb
32
25
  - lib/oauned/controller_methods.rb
33
26
  - lib/oauned/models/application.rb
34
27
  - lib/oauned/models/authorization.rb
@@ -36,6 +29,7 @@ files:
36
29
  - lib/oauned/models.rb
37
30
  - lib/oauned/rails/routing.rb
38
31
  - lib/oauned/rails.rb
32
+ - lib/oauned/version.rb
39
33
  - lib/oauned.rb
40
34
  - MIT-LICENSE
41
35
  - Rakefile
@@ -43,34 +37,26 @@ files:
43
37
  has_rdoc: true
44
38
  homepage:
45
39
  licenses: []
46
-
47
40
  post_install_message:
48
41
  rdoc_options: []
49
-
50
- require_paths:
42
+ require_paths:
51
43
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
44
+ required_ruby_version: !ruby/object:Gem::Requirement
53
45
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- version: "0"
60
- required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
51
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- segments:
66
- - 0
67
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
68
56
  requirements: []
69
-
70
57
  rubyforge_project:
71
- rubygems_version: 1.3.7
58
+ rubygems_version: 1.6.2
72
59
  signing_key:
73
60
  specification_version: 3
74
61
  summary: Oauth Provider
75
62
  test_files: []
76
-