grape_oauth2 0.1.1 → 0.2.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/.gitignore +11 -11
- data/Gemfile +23 -23
- data/Rakefile +11 -11
- data/grape_oauth2.gemspec +26 -27
- data/lib/grape_oauth2.rb +129 -129
- data/lib/grape_oauth2/configuration.rb +143 -143
- data/lib/grape_oauth2/configuration/class_accessors.rb +36 -36
- data/lib/grape_oauth2/configuration/validation.rb +71 -71
- data/lib/grape_oauth2/endpoints/authorize.rb +34 -34
- data/lib/grape_oauth2/endpoints/token.rb +72 -72
- data/lib/grape_oauth2/gem_version.rb +24 -24
- data/lib/grape_oauth2/generators/authorization.rb +44 -44
- data/lib/grape_oauth2/generators/base.rb +26 -26
- data/lib/grape_oauth2/generators/token.rb +62 -62
- data/lib/grape_oauth2/helpers/access_token_helpers.rb +52 -54
- data/lib/grape_oauth2/helpers/oauth_params.rb +41 -41
- data/lib/grape_oauth2/mixins/active_record/access_grant.rb +47 -47
- data/lib/grape_oauth2/mixins/active_record/access_token.rb +75 -75
- data/lib/grape_oauth2/mixins/active_record/client.rb +36 -35
- data/lib/grape_oauth2/mixins/mongoid/access_grant.rb +58 -58
- data/lib/grape_oauth2/mixins/mongoid/access_token.rb +88 -88
- data/lib/grape_oauth2/mixins/mongoid/client.rb +44 -41
- data/lib/grape_oauth2/mixins/sequel/access_grant.rb +68 -68
- data/lib/grape_oauth2/mixins/sequel/access_token.rb +86 -86
- data/lib/grape_oauth2/mixins/sequel/client.rb +54 -46
- data/lib/grape_oauth2/responses/authorization.rb +11 -10
- data/lib/grape_oauth2/responses/base.rb +56 -56
- data/lib/grape_oauth2/responses/token.rb +10 -10
- data/lib/grape_oauth2/scopes.rb +74 -74
- data/lib/grape_oauth2/strategies/authorization_code.rb +38 -38
- data/lib/grape_oauth2/strategies/base.rb +47 -47
- data/lib/grape_oauth2/strategies/client_credentials.rb +20 -20
- data/lib/grape_oauth2/strategies/password.rb +22 -22
- data/lib/grape_oauth2/strategies/refresh_token.rb +47 -47
- data/lib/grape_oauth2/unique_token.rb +20 -20
- data/lib/grape_oauth2/version.rb +14 -14
- data/spec/configuration/config_spec.rb +231 -231
- data/spec/configuration/version_spec.rb +12 -12
- data/spec/dummy/endpoints/custom_authorization.rb +25 -25
- data/spec/dummy/endpoints/custom_token.rb +35 -35
- data/spec/dummy/endpoints/status.rb +25 -25
- data/spec/dummy/grape_oauth2_config.rb +11 -11
- data/spec/dummy/orm/active_record/app/config/db.rb +7 -7
- data/spec/dummy/orm/active_record/app/models/access_code.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/access_token.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/application.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/application_record.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/user.rb +10 -10
- data/spec/dummy/orm/active_record/app/twitter.rb +36 -36
- data/spec/dummy/orm/active_record/config.ru +7 -7
- data/spec/dummy/orm/active_record/db/schema.rb +53 -53
- data/spec/dummy/orm/mongoid/app/config/db.rb +6 -6
- data/spec/dummy/orm/mongoid/app/config/mongoid.yml +21 -21
- data/spec/dummy/orm/mongoid/app/models/access_code.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/access_token.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/application.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/user.rb +11 -11
- data/spec/dummy/orm/mongoid/app/twitter.rb +34 -34
- data/spec/dummy/orm/mongoid/config.ru +5 -5
- data/spec/dummy/orm/sequel/app/config/db.rb +1 -1
- data/spec/dummy/orm/sequel/app/models/access_code.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/access_token.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/application.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/application_record.rb +2 -2
- data/spec/dummy/orm/sequel/app/models/user.rb +11 -11
- data/spec/dummy/orm/sequel/app/twitter.rb +47 -47
- data/spec/dummy/orm/sequel/config.ru +5 -5
- data/spec/dummy/orm/sequel/db/schema.rb +50 -50
- data/spec/lib/scopes_spec.rb +50 -50
- data/spec/mixins/active_record/access_token_spec.rb +185 -185
- data/spec/mixins/active_record/client_spec.rb +104 -95
- data/spec/mixins/mongoid/access_token_spec.rb +185 -185
- data/spec/mixins/mongoid/client_spec.rb +104 -95
- data/spec/mixins/sequel/access_token_spec.rb +185 -185
- data/spec/mixins/sequel/client_spec.rb +105 -96
- data/spec/requests/flows/authorization_code_spec.rb +67 -67
- data/spec/requests/flows/client_credentials_spec.rb +101 -101
- data/spec/requests/flows/password_spec.rb +210 -210
- data/spec/requests/flows/refresh_token_spec.rb +222 -222
- data/spec/requests/flows/revoke_token_spec.rb +103 -103
- data/spec/requests/protected_resources_spec.rb +64 -64
- data/spec/spec_helper.rb +60 -60
- data/spec/support/api_helper.rb +11 -11
- metadata +50 -52
- data/.rspec +0 -2
- data/.rubocop.yml +0 -18
- data/.travis.yml +0 -42
- data/README.md +0 -820
- data/gemfiles/active_record.rb +0 -25
- data/gemfiles/mongoid.rb +0 -14
- data/gemfiles/sequel.rb +0 -24
- data/grape_oauth2.png +0 -0
@@ -1,10 +1,11 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
# Grape::OAuth2 responses namespace.
|
4
|
-
module Responses
|
5
|
-
# Authorization response.
|
6
|
-
class Authorization < Base
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
# Grape::OAuth2 responses namespace.
|
4
|
+
module Responses
|
5
|
+
# Authorization response.
|
6
|
+
class Authorization < Base
|
7
|
+
# [IMPORTANT]: need to be implemented!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,56 +1,56 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
# Grape::OAuth2 responses namespace.
|
4
|
-
module Responses
|
5
|
-
# Base class for Grape::OAuth2 endpoints responses.
|
6
|
-
# Processes raw Rack Responses and contains helper methods.
|
7
|
-
class Base
|
8
|
-
# Raw Rack::Response to process
|
9
|
-
#
|
10
|
-
# @return [Array] Rack response
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# response = Grape::OAuth2::Responses::Base.new([200, {}, Rack::BodyProxy.new('Test')])
|
14
|
-
# response.rack_response
|
15
|
-
#
|
16
|
-
# #=> [200, {}, Rack::BodyProxy.new('Test')]
|
17
|
-
#
|
18
|
-
attr_reader :rack_response
|
19
|
-
|
20
|
-
# OAuth2 response class.
|
21
|
-
#
|
22
|
-
# @param rack_response [Array]
|
23
|
-
# raw Rack::Response object
|
24
|
-
#
|
25
|
-
def initialize(rack_response)
|
26
|
-
# Rack Body:
|
27
|
-
# [Status Code, Headers, Body]
|
28
|
-
@rack_response = rack_response
|
29
|
-
end
|
30
|
-
|
31
|
-
# Response status
|
32
|
-
def status
|
33
|
-
@rack_response[0]
|
34
|
-
end
|
35
|
-
|
36
|
-
# Response headers
|
37
|
-
def headers
|
38
|
-
@rack_response[1]
|
39
|
-
end
|
40
|
-
|
41
|
-
# Raw Rack body
|
42
|
-
def raw_body
|
43
|
-
@rack_response[2].body
|
44
|
-
end
|
45
|
-
|
46
|
-
# JSON-parsed body
|
47
|
-
def body
|
48
|
-
response_body = raw_body.first
|
49
|
-
return {} if response_body.nil? || response_body.empty?
|
50
|
-
|
51
|
-
JSON.parse(response_body)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
# Grape::OAuth2 responses namespace.
|
4
|
+
module Responses
|
5
|
+
# Base class for Grape::OAuth2 endpoints responses.
|
6
|
+
# Processes raw Rack Responses and contains helper methods.
|
7
|
+
class Base
|
8
|
+
# Raw Rack::Response to process
|
9
|
+
#
|
10
|
+
# @return [Array] Rack response
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# response = Grape::OAuth2::Responses::Base.new([200, {}, Rack::BodyProxy.new('Test')])
|
14
|
+
# response.rack_response
|
15
|
+
#
|
16
|
+
# #=> [200, {}, Rack::BodyProxy.new('Test')]
|
17
|
+
#
|
18
|
+
attr_reader :rack_response
|
19
|
+
|
20
|
+
# OAuth2 response class.
|
21
|
+
#
|
22
|
+
# @param rack_response [Array]
|
23
|
+
# raw Rack::Response object
|
24
|
+
#
|
25
|
+
def initialize(rack_response)
|
26
|
+
# Rack Body:
|
27
|
+
# [Status Code, Headers, Body]
|
28
|
+
@rack_response = rack_response
|
29
|
+
end
|
30
|
+
|
31
|
+
# Response status
|
32
|
+
def status
|
33
|
+
@rack_response[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Response headers
|
37
|
+
def headers
|
38
|
+
@rack_response[1]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Raw Rack body
|
42
|
+
def raw_body
|
43
|
+
@rack_response[2].body
|
44
|
+
end
|
45
|
+
|
46
|
+
# JSON-parsed body
|
47
|
+
def body
|
48
|
+
response_body = raw_body.first
|
49
|
+
return {} if response_body.nil? || response_body.empty?
|
50
|
+
|
51
|
+
JSON.parse(response_body)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
# Grape::OAuth2 responses namespace.
|
4
|
-
module Responses
|
5
|
-
# Token response.
|
6
|
-
class Token < Base
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
# Grape::OAuth2 responses namespace.
|
4
|
+
module Responses
|
5
|
+
# Token response.
|
6
|
+
class Token < Base
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/grape_oauth2/scopes.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
# OAuth2 helper for scopes validation
|
4
|
-
# (between requested and presented in Access Token).
|
5
|
-
class Scopes
|
6
|
-
# Array of requested scopes
|
7
|
-
#
|
8
|
-
# @return [Array<String>] scopes
|
9
|
-
#
|
10
|
-
attr_reader :scopes
|
11
|
-
|
12
|
-
# Helper class initializer.
|
13
|
-
#
|
14
|
-
# @param scopes [Array, String, #to_a]
|
15
|
-
# array, string of any object that responds to `to_a`
|
16
|
-
#
|
17
|
-
def initialize(scopes)
|
18
|
-
@scopes = to_array(scopes || [])
|
19
|
-
end
|
20
|
-
|
21
|
-
# Checks if requested scopes (passed and processed on initialization)
|
22
|
-
# are presented in the Access Token.
|
23
|
-
#
|
24
|
-
# @param access_token [Object]
|
25
|
-
# instance of the Access Token class that responds to `scopes`
|
26
|
-
#
|
27
|
-
# @return [Boolean]
|
28
|
-
# true if requested scopes are empty or present in access token scopes
|
29
|
-
# and false in other cases
|
30
|
-
#
|
31
|
-
def valid_for?(access_token)
|
32
|
-
scopes.empty? || present_in?(access_token.scopes)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# Checks if scopes present in Access Token scopes.
|
38
|
-
#
|
39
|
-
# @param token_scopes [Array, String, #to_a]
|
40
|
-
# array, string of any object that responds to `to_a`
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
# true if requested scopes present in Access Token and false in other cases
|
44
|
-
#
|
45
|
-
def present_in?(token_scopes)
|
46
|
-
required_scopes = Set.new(to_array(scopes))
|
47
|
-
authorized_scopes = Set.new(to_array(token_scopes))
|
48
|
-
|
49
|
-
authorized_scopes >= required_scopes
|
50
|
-
end
|
51
|
-
|
52
|
-
# Converts scopes set to the array.
|
53
|
-
#
|
54
|
-
# @param scopes [Array, String, #to_a]
|
55
|
-
# string, array or object that responds to `to_a`
|
56
|
-
# @return [Array<String>]
|
57
|
-
# array of scopes
|
58
|
-
#
|
59
|
-
def to_array(scopes)
|
60
|
-
return [] if scopes.nil?
|
61
|
-
|
62
|
-
collection = if scopes.is_a?(Array) || scopes.respond_to?(:to_a)
|
63
|
-
scopes.to_a
|
64
|
-
elsif scopes.is_a?(String)
|
65
|
-
scopes.split
|
66
|
-
else
|
67
|
-
raise ArgumentError, 'scopes class is not supported!'
|
68
|
-
end
|
69
|
-
|
70
|
-
collection.map(&:to_s)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
# OAuth2 helper for scopes validation
|
4
|
+
# (between requested and presented in Access Token).
|
5
|
+
class Scopes
|
6
|
+
# Array of requested scopes
|
7
|
+
#
|
8
|
+
# @return [Array<String>] scopes
|
9
|
+
#
|
10
|
+
attr_reader :scopes
|
11
|
+
|
12
|
+
# Helper class initializer.
|
13
|
+
#
|
14
|
+
# @param scopes [Array, String, #to_a]
|
15
|
+
# array, string of any object that responds to `to_a`
|
16
|
+
#
|
17
|
+
def initialize(scopes)
|
18
|
+
@scopes = to_array(scopes || [])
|
19
|
+
end
|
20
|
+
|
21
|
+
# Checks if requested scopes (passed and processed on initialization)
|
22
|
+
# are presented in the Access Token.
|
23
|
+
#
|
24
|
+
# @param access_token [Object]
|
25
|
+
# instance of the Access Token class that responds to `scopes`
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
# true if requested scopes are empty or present in access token scopes
|
29
|
+
# and false in other cases
|
30
|
+
#
|
31
|
+
def valid_for?(access_token)
|
32
|
+
scopes.empty? || present_in?(access_token.scopes)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Checks if scopes present in Access Token scopes.
|
38
|
+
#
|
39
|
+
# @param token_scopes [Array, String, #to_a]
|
40
|
+
# array, string of any object that responds to `to_a`
|
41
|
+
#
|
42
|
+
# @return [Boolean]
|
43
|
+
# true if requested scopes present in Access Token and false in other cases
|
44
|
+
#
|
45
|
+
def present_in?(token_scopes)
|
46
|
+
required_scopes = Set.new(to_array(scopes))
|
47
|
+
authorized_scopes = Set.new(to_array(token_scopes))
|
48
|
+
|
49
|
+
authorized_scopes >= required_scopes
|
50
|
+
end
|
51
|
+
|
52
|
+
# Converts scopes set to the array.
|
53
|
+
#
|
54
|
+
# @param scopes [Array, String, #to_a]
|
55
|
+
# string, array or object that responds to `to_a`
|
56
|
+
# @return [Array<String>]
|
57
|
+
# array of scopes
|
58
|
+
#
|
59
|
+
def to_array(scopes)
|
60
|
+
return [] if scopes.nil?
|
61
|
+
|
62
|
+
collection = if scopes.is_a?(Array) || scopes.respond_to?(:to_a)
|
63
|
+
scopes.to_a
|
64
|
+
elsif scopes.is_a?(String)
|
65
|
+
scopes.split
|
66
|
+
else
|
67
|
+
raise ArgumentError, 'scopes class is not supported!'
|
68
|
+
end
|
69
|
+
|
70
|
+
collection.map(&:to_s)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
module Strategies
|
4
|
-
# Auth Code strategy class.
|
5
|
-
# Processes request and responds with Token or Code
|
6
|
-
# (depend on requested response type).
|
7
|
-
class AuthorizationCode < Base
|
8
|
-
class << self
|
9
|
-
# Processes Authorization request.
|
10
|
-
def process(request, response)
|
11
|
-
client = authenticate_client(request)
|
12
|
-
request.bad_request! if client.nil?
|
13
|
-
|
14
|
-
response.redirect_uri = request.verify_redirect_uri!(client.redirect_uri)
|
15
|
-
|
16
|
-
# TODO: verify scopes if they valid
|
17
|
-
# scopes = request.scope
|
18
|
-
# request.invalid_scope! "Unknown scope: #{scope}"
|
19
|
-
|
20
|
-
case request.response_type
|
21
|
-
when :code
|
22
|
-
# resource owner can't be nil!
|
23
|
-
authorization_code = config.access_grant_class.create_for(client, nil, response.redirect_uri)
|
24
|
-
response.code = authorization_code.token
|
25
|
-
when :token
|
26
|
-
# resource owner can't be nil!
|
27
|
-
access_token = config.access_token_class.create_for(client, nil, scopes_from(request))
|
28
|
-
response.access_token = expose_to_bearer_token(access_token)
|
29
|
-
end
|
30
|
-
|
31
|
-
response.approve!
|
32
|
-
response
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
module Strategies
|
4
|
+
# Auth Code strategy class.
|
5
|
+
# Processes request and responds with Token or Code
|
6
|
+
# (depend on requested response type).
|
7
|
+
class AuthorizationCode < Base
|
8
|
+
class << self
|
9
|
+
# Processes Authorization request.
|
10
|
+
def process(request, response)
|
11
|
+
client = authenticate_client(request)
|
12
|
+
request.bad_request! if client.nil?
|
13
|
+
|
14
|
+
response.redirect_uri = request.verify_redirect_uri!(client.redirect_uri)
|
15
|
+
|
16
|
+
# TODO: verify scopes if they valid
|
17
|
+
# scopes = request.scope
|
18
|
+
# request.invalid_scope! "Unknown scope: #{scope}"
|
19
|
+
|
20
|
+
case request.response_type
|
21
|
+
when :code
|
22
|
+
# resource owner can't be nil!
|
23
|
+
authorization_code = config.access_grant_class.create_for(client, nil, response.redirect_uri)
|
24
|
+
response.code = authorization_code.token
|
25
|
+
when :token
|
26
|
+
# resource owner can't be nil!
|
27
|
+
access_token = config.access_token_class.create_for(client, nil, scopes_from(request))
|
28
|
+
response.access_token = expose_to_bearer_token(access_token)
|
29
|
+
end
|
30
|
+
|
31
|
+
response.approve!
|
32
|
+
response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,47 +1,47 @@
|
|
1
|
-
module Grape
|
2
|
-
module OAuth2
|
3
|
-
# Grape::OAuth2 strategies namespace
|
4
|
-
module Strategies
|
5
|
-
# Base Grape::OAuth2 Strategies class .
|
6
|
-
# Contains common functionality for all the descendants.
|
7
|
-
class Base
|
8
|
-
class << self
|
9
|
-
# Authenticates Client from the request.
|
10
|
-
def authenticate_client(request)
|
11
|
-
config.client_class.authenticate(request.client_id, request.try(:client_secret))
|
12
|
-
end
|
13
|
-
|
14
|
-
# Authenticates Resource Owner from the request.
|
15
|
-
def authenticate_resource_owner(client, request)
|
16
|
-
config.resource_owner_class.oauth_authenticate(client, request.username, request.password)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Short getter for Grape::OAuth2 configuration
|
20
|
-
def config
|
21
|
-
Grape::OAuth2.config
|
22
|
-
end
|
23
|
-
|
24
|
-
# Converts scopes from the request string. Separate them by the whitespace.
|
25
|
-
# @return [String] scopes string
|
26
|
-
#
|
27
|
-
def scopes_from(request)
|
28
|
-
return nil if request.scope.nil?
|
29
|
-
|
30
|
-
Array(request.scope).join(' ')
|
31
|
-
end
|
32
|
-
|
33
|
-
# Exposes token object to Bearer token.
|
34
|
-
#
|
35
|
-
# @param token [#to_bearer_token]
|
36
|
-
# any object that responds to `to_bearer_token`
|
37
|
-
# @return [Rack::OAuth2::AccessToken::Bearer]
|
38
|
-
# bearer token instance
|
39
|
-
#
|
40
|
-
def expose_to_bearer_token(token)
|
41
|
-
Rack::OAuth2::AccessToken::Bearer.new(token.to_bearer_token)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
module Grape
|
2
|
+
module OAuth2
|
3
|
+
# Grape::OAuth2 strategies namespace
|
4
|
+
module Strategies
|
5
|
+
# Base Grape::OAuth2 Strategies class .
|
6
|
+
# Contains common functionality for all the descendants.
|
7
|
+
class Base
|
8
|
+
class << self
|
9
|
+
# Authenticates Client from the request.
|
10
|
+
def authenticate_client(request)
|
11
|
+
config.client_class.authenticate(request.client_id, request.try(:client_secret))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Authenticates Resource Owner from the request.
|
15
|
+
def authenticate_resource_owner(client, request)
|
16
|
+
config.resource_owner_class.oauth_authenticate(client, request.username, request.password)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Short getter for Grape::OAuth2 configuration
|
20
|
+
def config
|
21
|
+
Grape::OAuth2.config
|
22
|
+
end
|
23
|
+
|
24
|
+
# Converts scopes from the request string. Separate them by the whitespace.
|
25
|
+
# @return [String] scopes string
|
26
|
+
#
|
27
|
+
def scopes_from(request)
|
28
|
+
return nil if request.scope.nil?
|
29
|
+
|
30
|
+
Array(request.scope).join(' ')
|
31
|
+
end
|
32
|
+
|
33
|
+
# Exposes token object to Bearer token.
|
34
|
+
#
|
35
|
+
# @param token [#to_bearer_token]
|
36
|
+
# any object that responds to `to_bearer_token`
|
37
|
+
# @return [Rack::OAuth2::AccessToken::Bearer]
|
38
|
+
# bearer token instance
|
39
|
+
#
|
40
|
+
def expose_to_bearer_token(token)
|
41
|
+
Rack::OAuth2::AccessToken::Bearer.new(token.to_bearer_token)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|