Class: Zitadel::Client::Auth::ClientCredentialsAuthenticator

Inherits:
OAuthAuthenticator show all
Defined in:
lib/zitadel/client/auth/client_credentials_authenticator.rb,
sig/lib.rbs

Overview

ClientCredentialsAuthenticator implements the client credentials flow.

Defined Under Namespace

Classes: ClientCredentialsAuthenticatorBuilder

Instance Attribute Summary

Attributes inherited from Authenticator

#host

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OAuthAuthenticator

#auth_headers, #auth_token, #refresh_token

Methods inherited from Authenticator

#auth_headers

Constructor Details

#initialize(open_id, client_id, client_secret, auth_scopes, transport_options: nil) ⇒ ClientCredentialsAuthenticator

Constructs a ClientCredentialsAuthenticator using client credentials flow.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zitadel/client/auth/client_credentials_authenticator.rb', line 15

def initialize(open_id, client_id, client_secret, auth_scopes, transport_options: nil)
  transport_options ||= TransportOptions.defaults

  conn_opts = transport_options.to_connection_opts

  # noinspection RubyArgCount
  super(open_id, auth_scopes, OAuth2::Client.new(client_id, client_secret, {
                                                   site: open_id.host_endpoint,
                                                   token_url: open_id.token_endpoint,
                                                   connection_opts: conn_opts
                                                 }), transport_options: transport_options)
end

Class Method Details

.builder(host, client_id, client_secret, transport_options: nil) ⇒ ClientCredentialsAuthenticatorBuilder

Returns a new builder for constructing a ClientCredentialsAuthenticator.



35
36
37
38
# File 'lib/zitadel/client/auth/client_credentials_authenticator.rb', line 35

def self.builder(host, client_id, client_secret, transport_options: nil)
  ClientCredentialsAuthenticatorBuilder.new(host, client_id, client_secret,
                                            transport_options: transport_options)
end

Instance Method Details

#get_grant(client, auth_scopes) ⇒ OAuth2::AccessToken



45
46
47
# File 'lib/zitadel/client/auth/client_credentials_authenticator.rb', line 45

def get_grant(client, auth_scopes)
  client.client_credentials.get_token({ scope: auth_scopes })
end