@@ -25,14 +25,20 @@ class WebTokenAuthenticator < Auth::OAuthAuthenticator
2525 # @param jwt_lifetime [Integer] Lifetime of the JWT in seconds (default 3600 seconds).
2626 # @param jwt_algorithm [String] The JWT signing algorithm (default "RS256").
2727 # @param key_id [String, nil] Optional key identifier for the JWT header (default: nil).
28- # rubocop:disable Metrics/ParameterLists,Metrics/MethodLength
28+ # @param transport_options [TransportOptions, nil] Optional transport options for TLS, proxy, and headers.
29+ # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
2930 def initialize ( open_id , auth_scopes , jwt_issuer , jwt_subject , jwt_audience , private_key ,
30- jwt_lifetime : 3600 , jwt_algorithm : 'RS256' , key_id : nil )
31+ jwt_lifetime : 3600 , jwt_algorithm : 'RS256' , key_id : nil , transport_options : nil )
32+ transport_options ||= TransportOptions . defaults
33+
34+ conn_opts = transport_options . to_connection_opts
35+
3136 # noinspection RubyArgCount,RubyMismatchedArgumentType
3237 super ( open_id , auth_scopes , OAuth2 ::Client . new ( 'zitadel' , 'zitadel' , {
3338 site : open_id . host_endpoint ,
34- token_url : open_id . token_endpoint
35- } ) )
39+ token_url : open_id . token_endpoint ,
40+ connection_opts : conn_opts
41+ } ) , transport_options : transport_options )
3642 @jwt_issuer = jwt_issuer
3743 @jwt_subject = jwt_subject
3844 @jwt_audience = jwt_audience
@@ -47,7 +53,7 @@ def initialize(open_id, auth_scopes, jwt_issuer, jwt_subject, jwt_audience, priv
4753 end
4854 end
4955
50- # rubocop:enable Metrics/ParameterLists,Metrics/MethodLength
56+ # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
5157
5258 # Creates a WebTokenAuthenticator instance from a JSON configuration file.
5359 #
@@ -62,9 +68,11 @@ def initialize(open_id, auth_scopes, jwt_issuer, jwt_subject, jwt_audience, priv
6268 #
6369 # @param host [String] Base URL for the API endpoints.
6470 # @param json_path [String] File path to the JSON configuration file.
71+ # @param transport_options [TransportOptions, nil] Optional transport options for TLS, proxy, and headers.
6572 # @return [WebTokenAuthenticator] A new instance of WebTokenAuthenticator.
6673 # @raise [RuntimeError] If the file cannot be read, the JSON is invalid, or required keys are missing.
67- def self . from_json ( host , json_path )
74+ # rubocop:disable Metrics/MethodLength
75+ def self . from_json ( host , json_path , transport_options : nil )
6876 config = JSON . parse ( File . read ( json_path ) )
6977 rescue Errno ::ENOENT => e
7078 raise "Unable to read JSON file at #{ json_path } : #{ e . message } "
@@ -76,17 +84,21 @@ def self.from_json(host, json_path)
7684 user_id , private_key , key_id = config . values_at ( 'userId' , 'key' , 'keyId' )
7785 raise "Missing required keys 'userId', 'keyId' or 'key'" unless user_id && key_id && private_key
7886
79- WebTokenAuthenticator . builder ( host , user_id , private_key ) . key_identifier ( key_id ) . build
87+ WebTokenAuthenticator . builder ( host , user_id , private_key , transport_options : transport_options )
88+ . key_identifier ( key_id ) . build
8089 end
90+ # rubocop:enable Metrics/MethodLength
8191
8292 # Returns a builder for constructing a WebTokenAuthenticator.
8393 #
8494 # @param host [String] The base URL for the OAuth provider.
8595 # @param user_id [String] The user identifier (used as both the issuer and subject).
8696 # @param private_key [String] The private key used to sign the JWT.
97+ # @param transport_options [TransportOptions, nil] Optional transport options for TLS, proxy, and headers.
8798 # @return [WebTokenAuthenticatorBuilder] A builder instance.
88- def self . builder ( host , user_id , private_key )
89- WebTokenAuthenticatorBuilder . new ( host , user_id , user_id , host , private_key )
99+ def self . builder ( host , user_id , private_key , transport_options : nil )
100+ WebTokenAuthenticatorBuilder . new ( host , user_id , user_id , host , private_key ,
101+ transport_options : transport_options )
90102 end
91103
92104 protected
@@ -130,15 +142,18 @@ class WebTokenAuthenticatorBuilder < OAuthAuthenticatorBuilder
130142 # @param jwt_subject [String] The subject claim for the JWT.
131143 # @param jwt_audience [String] The audience claim for the JWT.
132144 # @param private_key [String] The PEM-formatted private key used for signing the JWT.
133- def initialize ( host , jwt_issuer , jwt_subject , jwt_audience , private_key )
145+ # @param transport_options [TransportOptions, nil] Optional transport options for TLS, proxy, and headers.
146+ # rubocop:disable Metrics/ParameterLists
147+ def initialize ( host , jwt_issuer , jwt_subject , jwt_audience , private_key , transport_options : nil )
134148 # noinspection RubyArgCount
135- super ( host )
149+ super ( host , transport_options : transport_options )
136150 @jwt_issuer = jwt_issuer
137151 @jwt_subject = jwt_subject
138152 @jwt_audience = jwt_audience
139153 @private_key = private_key
140154 @jwt_lifetime = 3600
141155 end
156+ # rubocop:enable Metrics/ParameterLists
142157
143158 # Sets the JWT token lifetime in seconds.
144159 #
@@ -159,7 +174,8 @@ def key_identifier(key_id)
159174 # @return [WebTokenAuthenticator] A configured instance.
160175 def build
161176 WebTokenAuthenticator . new ( open_id , auth_scopes , @jwt_issuer , @jwt_subject , @jwt_audience ,
162- @private_key , jwt_lifetime : @jwt_lifetime , key_id : @key_id )
177+ @private_key , jwt_lifetime : @jwt_lifetime , key_id : @key_id ,
178+ transport_options : @transport_options )
163179 end
164180 end
165181 end
0 commit comments