Class: KeycloakAdmin::ConfigurableTokenClient

Inherits:
Client
  • Object
show all
Defined in:
lib/keycloak-admin/client/configurable_token_client.rb

Instance Method Summary collapse

Methods inherited from Client

#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url

Constructor Details

#initialize(configuration, realm_client) ⇒ ConfigurableTokenClient

Returns a new instance of ConfigurableTokenClient.

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/keycloak-admin/client/configurable_token_client.rb', line 3

def initialize(configuration, realm_client)
  super(configuration)
  raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
  @realm_client = realm_client
end

Instance Method Details

#exchange_with(user_access_token, token_lifespan_in_seconds) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/keycloak-admin/client/configurable_token_client.rb', line 17

def exchange_with(user_access_token, token_lifespan_in_seconds)
  response = execute_http do
    RestClient::Request.execute(
      @configuration.rest_client_options.merge(
        method: :post,
        url: token_url,
        payload: { tokenLifespanInSeconds: token_lifespan_in_seconds }.to_json,
        headers: {
          Authorization: "Bearer #{user_access_token}",
          content_type: :json,
          accept: :json
        }
      )
    )
  end
  TokenRepresentation.from_json(response.body)
end

#realm_urlObject



13
14
15
# File 'lib/keycloak-admin/client/configurable_token_client.rb', line 13

def realm_url
  @realm_client.realm_url
end

#token_urlObject



9
10
11
# File 'lib/keycloak-admin/client/configurable_token_client.rb', line 9

def token_url
  "#{realm_url}/configurable-token"
end