Class: KeycloakSdk::TokenSet

Inherits:
Data
  • Object
show all
Defined in:
lib/keycloak_sdk/tokens.rb

Overview

OAuth 토큰 응답의 불변 값타입. access/refresh/id 토큰은 inspect에서 마스킹.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token

Returns:

  • (Object)

    the current value of access_token



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def access_token
  @access_token
end

#expires_atObject (readonly)

Returns the value of attribute expires_at

Returns:

  • (Object)

    the current value of expires_at



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in

Returns:

  • (Object)

    the current value of expires_in



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def expires_in
  @expires_in
end

#id_tokenObject (readonly)

Returns the value of attribute id_token

Returns:

  • (Object)

    the current value of id_token



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def id_token
  @id_token
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token

Returns:

  • (Object)

    the current value of refresh_token



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def refresh_token
  @refresh_token
end

#scopeObject (readonly)

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def scope
  @scope
end

#token_typeObject (readonly)

Returns the value of attribute token_type

Returns:

  • (Object)

    the current value of token_type



5
6
7
# File 'lib/keycloak_sdk/tokens.rb', line 5

def token_type
  @token_type
end

Class Method Details

.from_response(body, received_at: Time.now.to_f) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/keycloak_sdk/tokens.rb', line 7

def self.from_response(body, received_at: Time.now.to_f)
  expires_in = body["expires_in"] && Integer(body["expires_in"])
  new(
    access_token: body["access_token"],
    token_type: body["token_type"],
    expires_in: expires_in,
    refresh_token: body["refresh_token"],
    id_token: body["id_token"],
    scope: body["scope"],
    expires_at: expires_in ? received_at + expires_in : nil
  )
end

Instance Method Details

#expired?(skew: 0, now: Time.now.to_f) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/keycloak_sdk/tokens.rb', line 20

def expired?(skew: 0, now: Time.now.to_f)
  return false if expires_at.nil?

  now >= (expires_at - skew)
end

#inspectObject Also known as: to_s



26
27
28
29
30
# File 'lib/keycloak_sdk/tokens.rb', line 26

def inspect
  "#<KeycloakSdk::TokenSet access_token=\"***\" token_type=#{token_type.inspect} " \
    "expires_in=#{expires_in.inspect} refresh_token=#{refresh_token ? '"***"' : 'nil'} " \
    "id_token=#{id_token ? '"***"' : 'nil'} scope=#{scope.inspect} expires_at=#{expires_at.inspect}>"
end