Class: Doorkeeper::OAuth::Authorization::Token
- Inherits:
-
Object
- Object
- Doorkeeper::OAuth::Authorization::Token
- Defined in:
- lib/doorkeeper/oauth/authorization/token.rb
Instance Attribute Summary collapse
-
#pre_auth ⇒ Object
readonly
Returns the value of attribute pre_auth.
-
#resource_owner ⇒ Object
readonly
Returns the value of attribute resource_owner.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
- .access_token_expires_in(configuration, context) ⇒ Object
- .build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner) ⇒ Object
- .refresh_token_enabled?(server, context) ⇒ Boolean
Instance Method Summary collapse
- #access_token? ⇒ Boolean
- #application ⇒ Object
-
#initialize(pre_auth, resource_owner) ⇒ Token
constructor
A new instance of Token.
- #issue_token! ⇒ Object
- #oob_redirect ⇒ Object
Constructor Details
#initialize(pre_auth, resource_owner) ⇒ Token
Returns a new instance of Token.
47 48 49 50 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 47 def initialize(pre_auth, resource_owner) @pre_auth = pre_auth @resource_owner = resource_owner end |
Instance Attribute Details
#pre_auth ⇒ Object (readonly)
Returns the value of attribute pre_auth.
7 8 9 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 7 def pre_auth @pre_auth end |
#resource_owner ⇒ Object (readonly)
Returns the value of attribute resource_owner.
7 8 9 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 7 def resource_owner @resource_owner end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 7 def token @token end |
Class Method Details
.access_token_expires_in(configuration, context) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 27 def access_token_expires_in(configuration, context) if configuration.option_defined?(:custom_access_token_expires_in) expiration = configuration.custom_access_token_expires_in.call(context) return nil if expiration == Float::INFINITY expiration || configuration.access_token_expires_in else configuration.access_token_expires_in end end |
.build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 10 def build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner) oauth_client = if pre_auth_or_oauth_client.respond_to?(:application) pre_auth_or_oauth_client.application elsif pre_auth_or_oauth_client.respond_to?(:client) pre_auth_or_oauth_client.client else pre_auth_or_oauth_client end Doorkeeper::OAuth::Authorization::Context.new( client: oauth_client, grant_type: grant_type, scopes: scopes, resource_owner: resource_owner, ) end |
.refresh_token_enabled?(server, context) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 38 def refresh_token_enabled?(server, context) if server.refresh_token_enabled?.respond_to?(:call) server.refresh_token_enabled?.call(context) else !!server.refresh_token_enabled? end end |
Instance Method Details
#access_token? ⇒ Boolean
85 86 87 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 85 def access_token? true end |
#application ⇒ Object
71 72 73 74 75 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 71 def application return unless pre_auth.client pre_auth.client.is_a?(Doorkeeper.config.application_model) ? pre_auth.client : pre_auth.client.application end |
#issue_token! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 52 def issue_token! return @token if defined?(@token) context = self.class.build_context( pre_auth.client, Doorkeeper::OAuth::IMPLICIT, pre_auth.scopes, resource_owner, ) @token = Doorkeeper.config.access_token_model.find_or_create_for( application: application, resource_owner: resource_owner, scopes: pre_auth.scopes, expires_in: self.class.access_token_expires_in(Doorkeeper.config, context), use_refresh_token: false, ) end |
#oob_redirect ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 77 def oob_redirect { controller: controller, action: :show, access_token: token.plaintext_token, } end |