Class: Hydra::Keycloak::Urls

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/keycloak/urls.rb

Constant Summary collapse

DEFAULT_SCOPE =
['openid'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Urls

Returns a new instance of Urls.



8
9
10
# File 'lib/hydra/keycloak/urls.rb', line 8

def initialize(config)
  @config = config
end

Instance Method Details

#auth_code_token_request_body(auth_code, code_verifier) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/hydra/keycloak/urls.rb', line 32

def auth_code_token_request_body(auth_code, code_verifier)
  {
    grant_type: 'authorization_code',
    code: auth_code,
    redirect_uri: @config[:redirect_uri],
    client_id: @config[:client_id],
    client_secret: @config[:secret],
    code_verifier: code_verifier
  }
end

#auth_url(code_challenge) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hydra/keycloak/urls.rb', line 12

def auth_url(code_challenge)
  URI(URI.join(@config[:auth_server_url], "realms/#{@config[:realm]}/protocol/openid-connect/auth")).tap do |uri|
    uri.query = URI.encode_www_form(
      {
        response_type: 'code',
        client_id: @config[:client_id],
        redirect_uri: @config[:redirect_uri],
        nonce: @config[:secret],
        scope: scope,
        code_challenge: code_challenge,
        code_challenge_method: 'S256'
      }
    )
  end.to_s
end

#end_session_url(id_token) ⇒ Object



67
68
69
70
71
# File 'lib/hydra/keycloak/urls.rb', line 67

def end_session_url(id_token)
  URI.join(@config[:auth_server_url], "realms/#{@config[:realm]}/protocol/openid-connect/logout").tap do |uri|
    uri.query = URI.encode_www_form(id_token_hint: id_token, post_logout_redirect_uri: @config[:logout_redirect])
  end.to_s
end

#introspection_endpointObject



54
55
56
# File 'lib/hydra/keycloak/urls.rb', line 54

def introspection_endpoint
  URI.join(@config[:auth_server_url], "realms/#{@config[:realm]}/protocol/openid-connect/token/introspect")
end

#introspection_request_body(token) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/hydra/keycloak/urls.rb', line 58

def introspection_request_body(token)
  {
    token: token,
    token_type_hint: 'access_token',
    client_id: @config[:client_id],
    client_secret: @config[:secret]
  }
end

#password_token_request_body(username, password) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/hydra/keycloak/urls.rb', line 43

def password_token_request_body(username, password)
  {
    grant_type: 'password',
    username: username,
    password: password,
    scope: scope,
    client_id: @config[:client_id],
    client_secret: @config[:secret]
  }
end

#refresh_request_body(refresh_token) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/hydra/keycloak/urls.rb', line 73

def refresh_request_body(refresh_token)
  {
    client_id: @config[:client_id],
    client_secret: @config[:secret],
    grant_type: 'refresh_token',
    refresh_token: refresh_token,
    scope: scope
  }
end

#token_endpointObject



28
29
30
# File 'lib/hydra/keycloak/urls.rb', line 28

def token_endpoint
  URI.join(@config[:auth_server_url], "realms/#{@config[:realm]}/protocol/openid-connect/token")
end