@@ -146,7 +146,11 @@ export class Connection {
146146 this . logger . info ( `Connected to RabbitMQ ${ this . params . hostname } :${ this . params . port } ` )
147147 this . peerProperties = ( await this . exchangeProperties ( ) ) . properties
148148 this . filteringEnabled = lt ( coerce ( this . rabbitManagementVersion ) ! , REQUIRED_MANAGEMENT_VERSION ) ? false : true
149- await this . auth ( { username : this . params . username , password : this . params . password } )
149+ await this . auth ( {
150+ username : this . params . username ,
151+ password : this . params . password ,
152+ mechanism : this . params . mechanism ?? "PLAIN" ,
153+ } )
150154 const { heartbeat } = await this . tune ( this . params . heartbeat ?? 0 )
151155 await this . open ( { virtualHost : this . params . vhost } )
152156 if ( ! this . heartbeat . started ) this . heartbeat . start ( heartbeat )
@@ -436,19 +440,17 @@ export class Connection {
436440 return this . setupCompleted
437441 }
438442
439- private async auth ( params : { username : string ; password : string } ) {
443+ private async auth ( params : { username : string ; password : string ; mechanism : string } ) {
440444 this . logger . debug ( `Start authentication process ...` )
441445 this . logger . debug ( `Start SASL handshake ...` )
442446 const handshakeResponse = await this . sendAndWait < SaslHandshakeResponse > ( new SaslHandshakeRequest ( ) )
443447 this . logger . debug ( `Mechanisms: ${ handshakeResponse . mechanisms } ` )
444- if ( ! handshakeResponse . mechanisms . find ( ( m ) => m === "PLAIN" ) ) {
445- throw new Error ( `Unable to find PLAIN mechanism in ${ handshakeResponse . mechanisms } ` )
448+ if ( ! handshakeResponse . mechanisms . find ( ( m ) => m === params . mechanism ) ) {
449+ throw new Error ( `Unable to find ${ params . mechanism } mechanism in ${ handshakeResponse . mechanisms } ` )
446450 }
447451
448- this . logger . debug ( `Start SASL PLAIN authentication ...` )
449- const authResponse = await this . sendAndWait < SaslAuthenticateResponse > (
450- new SaslAuthenticateRequest ( { ...params , mechanism : "PLAIN" } )
451- )
452+ this . logger . debug ( `Start SASL ${ params . mechanism } authentication ...` )
453+ const authResponse = await this . sendAndWait < SaslAuthenticateResponse > ( new SaslAuthenticateRequest ( params ) )
452454 this . logger . debug ( `Authentication: ${ authResponse . ok } - '${ authResponse . data } '` )
453455 if ( ! authResponse . ok ) {
454456 throw new Error ( `Unable Authenticate -> ${ authResponse . code } ` )
0 commit comments