Class: KeycloakSdk::ClientCredentialsTokenProvider

Inherits:
Object
  • Object
show all
Includes:
TokenProvider
Defined in:
lib/keycloak_sdk/token_provider.rb

Overview

client-credentials 그랜트로 토큰을 발급하고 만료 전까지 캐시한다(Mutex single-flight). admin 파사드가 소비하는 캐싱 provider(무캐시 AuthClient 직접 주입 금지 — §4 캐시 불변식).

Instance Method Summary collapse

Constructor Details

#initialize(config:, http:) ⇒ ClientCredentialsTokenProvider

Returns a new instance of ClientCredentialsTokenProvider.



14
15
16
17
18
19
20
21
# File 'lib/keycloak_sdk/token_provider.rb', line 14

def initialize(config:, http:)
  @config = config
  @http = http
  @token_url = OidcEndpoints.from_config(config).token
  @mutex = Mutex.new
  @cached = nil
  @expires_at = 0.0
end

Instance Method Details

#access_tokenObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/keycloak_sdk/token_provider.rb', line 23

def access_token
  @mutex.synchronize do
    now = Time.now.to_f
    return @cached if @cached && now < @expires_at

    ts = request_token
    @cached = ts.access_token
    @expires_at = ts.expires_at ? (ts.expires_at - @config.clock_skew) : (now + 60)
    @cached
  end
end