Class: Devise::Oauth::AccessToken

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Blockable, Scopable
Defined in:
app/models/devise/oauth/access_token.rb

Instance Method Summary collapse

Methods included from Blockable

#block!, #blocked?, #unblock!

Methods included from Scopable

#has_scope?, #scope, #scope=, #scope_to_response

Instance Method Details

#expired?(at = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/devise/oauth/access_token.rb', line 16

def expired?(at = Time.now)
  self.expires_at < at
end

#refresh!Object



20
21
22
23
24
25
26
27
28
# File 'app/models/devise/oauth/access_token.rb', line 20

def refresh!
  generate_refresh_token if Devise::Oauth.regenerate_refresh_token

  generate_value
  setup_expiration

  save
  token_response(Devise::Oauth.regenerate_refresh_token)
end

#refresh_token_expired?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/devise/oauth/access_token.rb', line 30

def refresh_token_expired?
  self.refresh_token_expires_at < Time.now
end

#token_response(generated_refresh_token = true) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'app/models/devise/oauth/access_token.rb', line 34

def token_response(generated_refresh_token=true)
  res = {
    access_token: value,
    token_type: 'bearer'
  }
  res[:scope]         = scope_to_response if scope.present?
  res[:expires_in]    = Devise::Oauth.access_token_expires_in if Devise::Oauth.access_token_expires_in
  res[:refresh_token] = refresh_token if generated_refresh_token
  res
end