simple_oauth2 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -6
- data/Gemfile +1 -0
- data/lib/simple_oauth2.rb +0 -7
- data/lib/simple_oauth2/configuration.rb +1 -1
- data/lib/simple_oauth2/generators/token.rb +1 -1
- data/lib/simple_oauth2/strategies/base.rb +2 -2
- data/lib/simple_oauth2/strategies/refresh_token.rb +1 -1
- data/lib/simple_oauth2/version.rb +1 -1
- data/spec/configuration/config_spec.rb +8 -4
- data/spec/dummy/orm/nobrainer/app/models/access_grant.rb +1 -1
- data/spec/dummy/orm/nobrainer/app/models/access_token.rb +1 -1
- data/spec/dummy/orm/nobrainer/app/models/client.rb +1 -1
- data/spec/dummy/orm/nobrainer/app/models/user.rb +1 -9
- data/spec/spec_helper.rb +1 -0
- metadata +1 -5
- data/gemfiles/nobrainer.rb +0 -15
- data/lib/simple_oauth2/mixins/nobrainer/access_grant.rb +0 -62
- data/lib/simple_oauth2/mixins/nobrainer/access_token.rb +0 -98
- data/lib/simple_oauth2/mixins/nobrainer/client.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c571e4fa9cd993df75fdb5416df55c386bc97503
|
4
|
+
data.tar.gz: e994bccde3012073687e723ec829ccb9e6453569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83368b14042af9aa05107cb83a55e333f3c71d1aeb6a3669e9a9b65160a5ddb50bc310d2b1ee63cebb1deb684ab38f09849b5c00740b0ba54ece10170476d1ec
|
7
|
+
data.tar.gz: 8b6cc5aec58182a68cfaecc34de807986b82dab2be4bbae905bc050f20827d7319fd9291738daff0efa34989f4027b0f06fd715b2c02938c2c2d7b9d3a640535
|
data/.travis.yml
CHANGED
@@ -21,11 +21,5 @@ matrix:
|
|
21
21
|
- rvm: ruby-head
|
22
22
|
include:
|
23
23
|
- rvm: 2.2.6
|
24
|
-
gemfile: gemfiles/nobrainer.rb
|
25
|
-
env: ORM=nobrainer
|
26
24
|
- rvm: 2.3.3
|
27
|
-
gemfile: gemfiles/nobrainer.rb
|
28
|
-
env: ORM=nobrainer
|
29
25
|
- rvm: ruby-head
|
30
|
-
gemfile: gemfiles/nobrainer.rb
|
31
|
-
env: ORM=nobrainer
|
data/Gemfile
CHANGED
data/lib/simple_oauth2.rb
CHANGED
@@ -7,13 +7,6 @@ require 'simple_oauth2/scopes'
|
|
7
7
|
require 'simple_oauth2/uniq_token'
|
8
8
|
require 'simple_oauth2/resource/bearer'
|
9
9
|
|
10
|
-
# Mixins
|
11
|
-
if defined?(NoBrainer::Document)
|
12
|
-
require 'simple_oauth2/mixins/nobrainer/access_token'
|
13
|
-
require 'simple_oauth2/mixins/nobrainer/access_grant'
|
14
|
-
require 'simple_oauth2/mixins/nobrainer/client'
|
15
|
-
end
|
16
|
-
|
17
10
|
# Authorization Grants aka Flows (Strategies)
|
18
11
|
require 'simple_oauth2/strategies/base'
|
19
12
|
require 'simple_oauth2/strategies/password'
|
@@ -113,7 +113,7 @@ module Simple
|
|
113
113
|
# Validates token value passed with the request params
|
114
114
|
def default_token_authenticator
|
115
115
|
lambda do |request|
|
116
|
-
access_token_class.
|
116
|
+
access_token_class.by_token(request.access_token) || request.invalid_token!
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -28,7 +28,7 @@ module Simple
|
|
28
28
|
# @return [Response] with HTTP status code 200
|
29
29
|
#
|
30
30
|
def revoke(token, env)
|
31
|
-
access_token = config.access_token_class.
|
31
|
+
access_token = config.access_token_class.by_refresh_token(token)
|
32
32
|
|
33
33
|
if access_token
|
34
34
|
request = Rack::OAuth2::Server::Token::Request.new(env)
|
@@ -8,7 +8,7 @@ module Simple
|
|
8
8
|
class << self
|
9
9
|
# Authenticates Client from the request
|
10
10
|
def authenticate_client(request)
|
11
|
-
config.client_class.
|
11
|
+
config.client_class.by_key(request.client_id)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Authenticates Resource Owner from the request
|
@@ -22,7 +22,7 @@ module Simple
|
|
22
22
|
|
23
23
|
# Authenticates Access Grant from the request
|
24
24
|
def authenticate_access_grant(request)
|
25
|
-
config.access_grant_class.
|
25
|
+
config.access_grant_class.by_token(request.code)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Exposes token object to Bearer token.
|
@@ -22,7 +22,7 @@ module Simple
|
|
22
22
|
|
23
23
|
# Check refresh token and client id for exact matching verifier
|
24
24
|
def verify_refresh_token!(request, client_id)
|
25
|
-
refresh_token = config.access_token_class.
|
25
|
+
refresh_token = config.access_token_class.by_refresh_token(request.refresh_token)
|
26
26
|
refresh_token || request.invalid_grant!
|
27
27
|
refresh_token.client_id == client_id || request.unauthorized_client!
|
28
28
|
|
@@ -14,7 +14,7 @@ module Simple
|
|
14
14
|
# Level changes for implementation level detail changes, such as small bug fixes
|
15
15
|
PATCH = 0
|
16
16
|
# Level changes for any backwards compatible API changes, such as new functionality/features
|
17
|
-
MINOR =
|
17
|
+
MINOR = 1
|
18
18
|
# Level changes for backwards incompatible API changes,
|
19
19
|
# such as changes that will break existing users code if they update
|
20
20
|
MAJOR = 0
|
@@ -4,7 +4,7 @@ describe Simple::OAuth2::Configuration do
|
|
4
4
|
let(:config) { described_class.new }
|
5
5
|
|
6
6
|
class CustomClient
|
7
|
-
def self.
|
7
|
+
def self.by_key(_key)
|
8
8
|
'Test'
|
9
9
|
end
|
10
10
|
end
|
@@ -12,7 +12,11 @@ describe Simple::OAuth2::Configuration do
|
|
12
12
|
class CustomAccessToken
|
13
13
|
def self.create_for(_client, _resource_owner, _scopes = nil); end
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.by_token(_token)
|
16
|
+
'Test'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.by_refresh_token(_refresh_token)
|
16
20
|
'Test'
|
17
21
|
end
|
18
22
|
|
@@ -105,11 +109,11 @@ describe Simple::OAuth2::Configuration do
|
|
105
109
|
end
|
106
110
|
|
107
111
|
context 'works with custom Access Token class' do
|
108
|
-
it { expect(config.access_token_class.
|
112
|
+
it { expect(config.access_token_class.by_token('')).to eq('Test') }
|
109
113
|
end
|
110
114
|
|
111
115
|
context 'works with custom Client class' do
|
112
|
-
it { expect(config.client_class.
|
116
|
+
it { expect(config.client_class.by_key('')).to eq('Test') }
|
113
117
|
end
|
114
118
|
|
115
119
|
context 'works with custom Resource Owner class' do
|
@@ -1,11 +1,3 @@
|
|
1
1
|
class User
|
2
|
-
include NoBrainer::
|
3
|
-
|
4
|
-
field :username, type: String, index: true
|
5
|
-
field :encrypted_password, type: String
|
6
|
-
|
7
|
-
def self.oauth_authenticate(_client, username, password)
|
8
|
-
user = where(username: username.to_s).first
|
9
|
-
user if user && user.encrypted_password == password
|
10
|
-
end
|
2
|
+
include NoBrainer::Simple::OAuth2::ResourceOwner
|
11
3
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodimir Partytskyi
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- LICENSE
|
48
48
|
- README.md
|
49
49
|
- Rakefile
|
50
|
-
- gemfiles/nobrainer.rb
|
51
50
|
- lib/simple_oauth2.rb
|
52
51
|
- lib/simple_oauth2/configuration.rb
|
53
52
|
- lib/simple_oauth2/configuration/class_accessors.rb
|
@@ -56,9 +55,6 @@ files:
|
|
56
55
|
- lib/simple_oauth2/generators/base.rb
|
57
56
|
- lib/simple_oauth2/generators/token.rb
|
58
57
|
- lib/simple_oauth2/helpers.rb
|
59
|
-
- lib/simple_oauth2/mixins/nobrainer/access_grant.rb
|
60
|
-
- lib/simple_oauth2/mixins/nobrainer/access_token.rb
|
61
|
-
- lib/simple_oauth2/mixins/nobrainer/client.rb
|
62
58
|
- lib/simple_oauth2/resource/bearer.rb
|
63
59
|
- lib/simple_oauth2/responses.rb
|
64
60
|
- lib/simple_oauth2/scopes.rb
|
data/gemfiles/nobrainer.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec path: '../'
|
4
|
-
|
5
|
-
gem 'nobrainer'
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem 'coveralls', require: false
|
9
|
-
gem 'factory_girl', '~> 4.0'
|
10
|
-
gem 'ffaker'
|
11
|
-
gem 'rack-test', require: 'rack/test'
|
12
|
-
gem 'rspec-rails', '~> 3.4'
|
13
|
-
end
|
14
|
-
|
15
|
-
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Simple
|
2
|
-
module OAuth2
|
3
|
-
module NoBrainer
|
4
|
-
# Includes all the required API, associations, validations and callbacks
|
5
|
-
module AccessGrant
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do # rubocop:disable Metrics/BlockLength
|
9
|
-
include ::NoBrainer::Document
|
10
|
-
include ::NoBrainer::Document::Timestamps
|
11
|
-
|
12
|
-
belongs_to :client, class_name: Simple::OAuth2.config.client_class_name,
|
13
|
-
foreign_key: :client_id, primary_key: :id
|
14
|
-
belongs_to :resource_owner, class_name: Simple::OAuth2.config.resource_owner_class_name,
|
15
|
-
foreign_key: :resource_owner_id, primary_key: :id
|
16
|
-
|
17
|
-
before_save { self.updated_at = Time.now }
|
18
|
-
before_validation :setup_expiration, if: :new_record?
|
19
|
-
|
20
|
-
field :resource_owner_id, type: String, index: true, required: true
|
21
|
-
field :client_id, type: String, index: true, required: true
|
22
|
-
|
23
|
-
field :token,
|
24
|
-
type: String,
|
25
|
-
required: true,
|
26
|
-
uniq: true,
|
27
|
-
index: true,
|
28
|
-
default: -> { Simple::OAuth2.config.token_generator.generate }
|
29
|
-
|
30
|
-
field :redirect_uri, type: String, required: true
|
31
|
-
field :scopes, type: String
|
32
|
-
|
33
|
-
field :revoked_at, type: Time
|
34
|
-
field :expires_at, type: Time, required: true
|
35
|
-
field :created_at, type: Time, required: true, default: -> { Time.now }
|
36
|
-
field :updated_at, type: Time, required: true, default: -> { Time.now }
|
37
|
-
|
38
|
-
class << self
|
39
|
-
def create_for(client, resource_owner, redirect_uri, scopes = nil)
|
40
|
-
create(
|
41
|
-
client_id: client.id,
|
42
|
-
resource_owner_id: resource_owner.id,
|
43
|
-
redirect_uri: redirect_uri,
|
44
|
-
scopes: scopes
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
def authenticate(token)
|
49
|
-
where(token: token.to_s).first
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def setup_expiration
|
56
|
-
self.expires_at = Time.now.utc + Simple::OAuth2.config.authorization_code_lifetime if expires_at.nil?
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Simple
|
2
|
-
module OAuth2
|
3
|
-
module NoBrainer
|
4
|
-
# Includes all the required API, associations, validations and callbacks
|
5
|
-
module AccessToken
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do # rubocop:disable Metrics/BlockLength
|
9
|
-
include ::NoBrainer::Document
|
10
|
-
include ::NoBrainer::Document::Timestamps
|
11
|
-
|
12
|
-
before_save { self.updated_at = Time.now }
|
13
|
-
before_validation :setup_expiration, if: :new_record?
|
14
|
-
|
15
|
-
belongs_to :client, class_name: Simple::OAuth2.config.client_class_name,
|
16
|
-
foreign_key: :client_id, primary_key: :id
|
17
|
-
belongs_to :resource_owner, class_name: Simple::OAuth2.config.resource_owner_class_name,
|
18
|
-
foreign_key: :resource_owner_id, primary_key: :id
|
19
|
-
|
20
|
-
field :resource_owner_id, type: String, index: true, required: true
|
21
|
-
field :client_id, type: String, index: true, required: true
|
22
|
-
field :token,
|
23
|
-
type: String,
|
24
|
-
index: true,
|
25
|
-
required: true,
|
26
|
-
uniq: true,
|
27
|
-
default: -> { Simple::OAuth2.config.token_generator.generate }
|
28
|
-
field :refresh_token,
|
29
|
-
type: String,
|
30
|
-
index: true,
|
31
|
-
uniq: true,
|
32
|
-
default: -> do
|
33
|
-
if Simple::OAuth2.config.issue_refresh_token
|
34
|
-
Simple::OAuth2.config.token_generator.generate
|
35
|
-
else
|
36
|
-
''
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
field :scopes, type: String
|
41
|
-
|
42
|
-
field :revoked_at, type: Time
|
43
|
-
field :expires_at, type: Time, required: true
|
44
|
-
field :created_at, type: Time, required: true, default: -> { Time.now }
|
45
|
-
field :updated_at, type: Time, required: true, default: -> { Time.now }
|
46
|
-
|
47
|
-
class << self
|
48
|
-
def create_for(client, resource_owner, scopes = nil)
|
49
|
-
create(
|
50
|
-
client_id: client.id,
|
51
|
-
resource_owner_id: resource_owner.id,
|
52
|
-
scopes: scopes
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def authenticate(token, token_type_hint = nil)
|
57
|
-
return if token.blank?
|
58
|
-
|
59
|
-
if token_type_hint == 'refresh_token'
|
60
|
-
where(refresh_token: token).first
|
61
|
-
else
|
62
|
-
where(token: token).first
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def expired?
|
68
|
-
expires_at && Time.now.utc > expires_at
|
69
|
-
end
|
70
|
-
|
71
|
-
def revoked?
|
72
|
-
revoked_at && revoked_at <= Time.now.utc
|
73
|
-
end
|
74
|
-
|
75
|
-
def revoke!(revoked_at = Time.now.utc)
|
76
|
-
update!(revoked_at: revoked_at)
|
77
|
-
end
|
78
|
-
|
79
|
-
def to_bearer_token
|
80
|
-
{
|
81
|
-
access_token: token,
|
82
|
-
expires_in: expires_at && Simple::OAuth2.config.access_token_lifetime.to_i,
|
83
|
-
refresh_token: refresh_token,
|
84
|
-
scope: scopes
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def setup_expiration
|
91
|
-
expires_in = Simple::OAuth2.config.access_token_lifetime.to_i
|
92
|
-
self.expires_at = Time.now.utc + expires_in if expires_at.nil? && !expires_in.nil?
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Simple
|
2
|
-
module OAuth2
|
3
|
-
module NoBrainer
|
4
|
-
# Includes all the required API, associations, validations and callbacks
|
5
|
-
module Client
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
include ::NoBrainer::Document
|
10
|
-
include ::NoBrainer::Document::Timestamps
|
11
|
-
|
12
|
-
before_save { self.updated_at = Time.now }
|
13
|
-
|
14
|
-
has_many :access_tokens, class_name: Simple::OAuth2.config.access_token_class_name, foreign_key: :client_id
|
15
|
-
has_many :access_grants, class_name: Simple::OAuth2.config.access_grant_class_name, foreign_key: :client_id
|
16
|
-
|
17
|
-
field :name, type: String, required: true
|
18
|
-
field :redirect_uri, type: String, required: true
|
19
|
-
|
20
|
-
field :key,
|
21
|
-
type: String,
|
22
|
-
required: true,
|
23
|
-
index: true,
|
24
|
-
uniq: true,
|
25
|
-
default: -> { Simple::OAuth2.config.token_generator.generate }
|
26
|
-
field :secret,
|
27
|
-
type: String,
|
28
|
-
required: true,
|
29
|
-
index: true,
|
30
|
-
uniq: true,
|
31
|
-
default: -> { Simple::OAuth2.config.token_generator.generate }
|
32
|
-
|
33
|
-
field :created_at, type: Time, required: true, default: -> { Time.now }
|
34
|
-
field :updated_at, type: Time, required: true, default: -> { Time.now }
|
35
|
-
|
36
|
-
def self.authenticate(key)
|
37
|
-
where(key: key.to_s).first
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|