Class: KeycloakConnectRuby::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak-connect-ruby/token.rb

Class Method Summary collapse

Class Method Details

.generate_from_client_credentialsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/keycloak-connect-ruby/token.rb', line 7

def self.generate_from_client_credentials
  # colocar logger e proxy aqui
  uri = URI("#{KeycloakConnectRuby.config.url}/realms/#{KeycloakConnectRuby.config.realm}/protocol/openid-connect/token")

  params = {
    'client_id' => KeycloakConnectRuby.config.client_id,
    'client_secret' => KeycloakConnectRuby.config.client_secret,
    'grant_type' => 'client_credentials'
  }

  response = Net::HTTP.post_form(uri, params)
  tokens = JSON.parse(response.body)
  tokens['access_token']
end