Skip to content

Commit

Permalink
Support for auth token
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
  • Loading branch information
wallyqs committed Aug 31, 2018
1 parent dfcef28 commit 4da9716
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/nats/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def user_err_cb? # :nodoc:
end

def auth_connection?
!@uri.user.nil?
!@uri.user.nil? || @options[:token]
end

def connect_command #:nodoc:
Expand All @@ -782,10 +782,16 @@ def connect_command #:nodoc:
:protocol => ::NATS::PROTOCOL_VERSION,
:echo => !@options[:no_echo]
}
if auth_connection?
case
when @options[:token]
cs[:auth_token] = @options[:token]
when @uri.password.nil?
cs[:auth_token] = @uri.user
else
cs[:user] = @uri.user
cs[:pass] = @uri.password
end
end if auth_connection?

cs[:name] = @options[:name] if @options[:name]
cs[:ssl_required] = @ssl if @ssl
cs[:tls_required] = true if @tls
Expand Down Expand Up @@ -943,9 +949,9 @@ def process_info(info) #:nodoc:
u.password = options[:pass] if options[:pass]

# Use creds from the current server if not set explicitly.
if @uri
u.user ||= @uri.user if @uri.user
u.password ||= @uri.password if @uri.password
if @uri and !@uri.user.nil? and !@uri.user.empty?
u.user ||= @uri.user
u.password ||= @uri.password
end

srvs << { :uri => u, :reconnect_attempts => 0, :discovered => true }
Expand Down

0 comments on commit 4da9716

Please sign in to comment.