@@ -23,7 +23,7 @@ pub type TransportOptions {
23
23
}
24
24
25
25
pub type AuthDetails {
26
- AuthDetails ( user_name : String , password : Option ( BitArray ) )
26
+ AuthDetails ( username : String , password : Option ( BitArray ) )
27
27
}
28
28
29
29
pub type ConnectOptions {
@@ -171,16 +171,21 @@ pub fn server_timeout_ms(
171
171
172
172
pub fn using_auth (
173
173
options : ConnectOptions ,
174
- details : AuthDetails ,
174
+ username : String ,
175
+ password : Option ( BitArray ) ,
175
176
) -> ConnectOptions {
176
- ConnectOptions ( .. options , authentication : Some ( details ) )
177
+ ConnectOptions (
178
+ .. options ,
179
+ authentication : Some ( AuthDetails ( username , password ) ) ,
180
+ )
177
181
}
178
182
179
183
/// Starts a new MQTT client with the given options.
180
184
/// Does not connect to the server, until `connect` is called.
181
185
pub fn start ( connect_options : ConnectOptions ) -> Client {
182
186
start_with_ms_keep_alive (
183
187
connect_options . client_id ,
188
+ connect_options . authentication ,
184
189
connect_options . keep_alive_seconds * 1000 ,
185
190
connect_options . server_timeout_ms ,
186
191
connect_options . transport_options ,
@@ -288,13 +293,15 @@ fn call_or_disconnect(
288
293
@ internal
289
294
pub fn start_with_ms_keep_alive (
290
295
client_id : String ,
296
+ auth : Option ( AuthDetails ) ,
291
297
keep_alive_ms : Int ,
292
298
server_timeout_ms : Int ,
293
299
transport_opts : TransportOptions ,
294
300
) -> Client {
295
301
let updates = process . new_subject ( )
296
302
let connect = fn ( ) { create_channel ( transport_opts ) }
297
- let config = Config ( client_id , keep_alive_ms , server_timeout_ms , connect )
303
+ let config =
304
+ Config ( client_id , auth , keep_alive_ms , server_timeout_ms , connect )
298
305
let assert Ok ( client ) =
299
306
actor . start_spec ( actor . Spec ( fn ( ) { init ( config , updates ) } , 100 , run_client ) )
300
307
Client ( client , updates , config )
@@ -310,6 +317,7 @@ fn create_channel(options: TransportOptions) -> ChannelResult(ByteChannel) {
310
317
type Config {
311
318
Config (
312
319
client_id : String ,
320
+ auth : Option ( AuthDetails ) ,
313
321
keep_alive : Int ,
314
322
server_timeout : Int ,
315
323
connect : fn ( ) -> ChannelResult ( ByteChannel ) ,
@@ -452,6 +460,11 @@ fn handle_connect(
452
460
return : actor . continue ( state ) ,
453
461
)
454
462
463
+ let auth =
464
+ option . map ( state . config . auth , fn ( auth ) {
465
+ packet . AuthOptions ( auth . username , auth . password )
466
+ } )
467
+
455
468
let will =
456
469
option . map ( will , fn ( will ) {
457
470
let data = packet . MessageData ( will . topic , will . payload , will . retain )
@@ -466,6 +479,7 @@ fn handle_connect(
466
479
clean_session ,
467
480
config . keep_alive ,
468
481
config . server_timeout ,
482
+ auth ,
469
483
will ,
470
484
)
471
485
0 commit comments