oa2c 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +31 -11
- data/app/models/oa2c/access_token.rb +1 -1
- data/app/models/oa2c/client.rb +2 -2
- data/app/models/oa2c/oauth2_token.rb +1 -1
- data/app/models/oa2c/refresh_token.rb +1 -1
- data/app/models/oa2c/user.rb +2 -2
- data/lib/oa2c/version.rb +1 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,36 @@ It's mostly extract from [rack-oauth2-sample](https://github.com/nov/rack-oauth2
|
|
10
10
|
|
11
11
|
Right now it supports only Mongoid 3 as ORM.
|
12
12
|
|
13
|
+
# Installation
|
14
|
+
|
15
|
+
First of all, add `gem 'oa2c'` to your Gemfile and bundle it.
|
16
|
+
|
17
|
+
Then add this to `config/application.rb`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
config.middleware.use Oa2c::Middleware
|
21
|
+
```
|
22
|
+
|
23
|
+
And add this to your `config/routes.rb`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
mount Oa2c::Engine => "/oauth"
|
27
|
+
```
|
28
|
+
|
29
|
+
And then you need to add this line to your user model:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
include Oa2c::User
|
33
|
+
```
|
34
|
+
|
35
|
+
This will add `access_tokens` and `authorization_codes` associations.
|
36
|
+
|
37
|
+
And finally add to your controllers that require OAuth2 authentictation:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
include Oa2c::Authentication
|
41
|
+
```
|
42
|
+
|
13
43
|
# Configuration
|
14
44
|
|
15
45
|
To change some settings, e.g. user model, add an initializer `config/initializers/oa2c.rb`:
|
@@ -20,7 +50,7 @@ Oa2c.setup do |config|
|
|
20
50
|
config.authentication_method = :authenticate_user!
|
21
51
|
config.login_method = :sign_in
|
22
52
|
config.current_user_method = :current_user
|
23
|
-
config.
|
53
|
+
config.find_user_for_password_authentication = proc {|username, password|
|
24
54
|
user = Oa2c.user_model.constantize.where(email: username).first
|
25
55
|
user if user.valid_password? password
|
26
56
|
}
|
@@ -29,16 +59,6 @@ end
|
|
29
59
|
|
30
60
|
**Note**: these are defaults for Devise. You don't need to do anything if you use the same settings
|
31
61
|
|
32
|
-
# User model
|
33
|
-
|
34
|
-
You need to add this line to your user model:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
include Oa2c::User
|
38
|
-
```
|
39
|
-
|
40
|
-
This will add `access_tokens` and `authorization_codes` associations.
|
41
|
-
|
42
62
|
# License
|
43
63
|
|
44
64
|
See MIT-LICENSE
|
@@ -4,7 +4,7 @@ module Oa2c
|
|
4
4
|
include Mongoid::Document
|
5
5
|
include OAuth2Token
|
6
6
|
|
7
|
-
belongs_to :refresh_token
|
7
|
+
belongs_to :refresh_token, class_name: "Oa2c::RefreshToken"
|
8
8
|
|
9
9
|
def to_bearer_token(with_refresh_token = false)
|
10
10
|
Rack::OAuth2::AccessToken::Bearer.new(access_token: token, expires_in: expires_in).tap do |bearer_token|
|
data/app/models/oa2c/client.rb
CHANGED
@@ -7,8 +7,8 @@ module Oa2c
|
|
7
7
|
field :redirect_uri
|
8
8
|
field :name
|
9
9
|
|
10
|
-
has_many :access_tokens
|
11
|
-
has_many :refresh_tokens
|
10
|
+
has_many :access_tokens, class_name: "Oa2c::AccessToken"
|
11
|
+
has_many :refresh_tokens, class_name: "Oa2c::RefreshToken"
|
12
12
|
|
13
13
|
before_validation :setup, on: :create
|
14
14
|
validates :secret, presence: true
|
@@ -10,7 +10,7 @@ module Oa2c
|
|
10
10
|
field :expires_at, type: Time
|
11
11
|
|
12
12
|
belongs_to :user, class_name: Oa2c.user_model
|
13
|
-
belongs_to :client
|
13
|
+
belongs_to :client, class_name: "Oa2c::Client"
|
14
14
|
|
15
15
|
before_validation :setup, on: :create
|
16
16
|
validates :client, :expires_at, presence: true
|
data/app/models/oa2c/user.rb
CHANGED
@@ -2,8 +2,8 @@ module Oa2c
|
|
2
2
|
module User
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
included do
|
5
|
-
has_many :access_tokens, :
|
6
|
-
has_many :authorization_codes, :
|
5
|
+
has_many :access_tokens, class_name: "Oa2c::AccessToken"
|
6
|
+
has_many :authorization_codes, class_name: "Oa2c::AuthorizationCode"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/oa2c/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oa2c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -286,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
286
|
version: '0'
|
287
287
|
segments:
|
288
288
|
- 0
|
289
|
-
hash:
|
289
|
+
hash: 622341743
|
290
290
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
291
291
|
none: false
|
292
292
|
requirements:
|
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
version: '0'
|
296
296
|
segments:
|
297
297
|
- 0
|
298
|
-
hash:
|
298
|
+
hash: 622341743
|
299
299
|
requirements: []
|
300
300
|
rubyforge_project:
|
301
301
|
rubygems_version: 1.8.24
|