Class: Oauth2Token::AccessToken

Inherits:
Oauth2Token
  • Object
show all
Defined in:
app/models/oauth2_token/access_token.rb

Instance Method Summary collapse

Methods inherited from Oauth2Token

#expire!, #expires_in

Instance Method Details

#setupObject



23
24
25
26
27
28
29
30
31
# File 'app/models/oauth2_token/access_token.rb', line 23

def setup
  super

  if refresh_token
    self.user       = refresh_token.user
    self.client     = refresh_token.client
    self.expires_at = [ expires_at, refresh_token.expires_at ].min
  end
end

#to_bearer_token(with_refresh_token = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/oauth2_token/access_token.rb', line 7

def to_bearer_token(with_refresh_token = false)
  bearer_token = Rack::OAuth2::AccessToken::Bearer.new(
    access_token: token,
    expires_in:   expires_in
  )

  if with_refresh_token
    bearer_token.refresh_token = create_refresh_token!(
      user: user,
      client: client
    ).token
  end

  bearer_token
end