Class: Doorkeeper::OAuth::Authorization::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/doorkeeper/oauth/authorization/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_authObject (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_ownerObject (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

#tokenObject (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

Returns:

  • (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

Returns:

  • (Boolean)

79
80
81
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 79

def access_token?
  true
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: pre_auth.client,
    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_redirectObject


71
72
73
74
75
76
77
# File 'lib/doorkeeper/oauth/authorization/token.rb', line 71

def oob_redirect
  {
    controller: controller,
    action: :show,
    access_token: token.plaintext_token,
  }
end