| 5 | |
| 6 | export class Plain extends AuthProvider { |
| 7 | override async auth(authContext: AuthContext): Promise<void> { |
| 8 | const { connection, credentials } = authContext; |
| 9 | if (!credentials) { |
| 10 | throw new MongoMissingCredentialsError('AuthContext must provide credentials.'); |
| 11 | } |
| 12 | |
| 13 | const { username, password } = credentials; |
| 14 | |
| 15 | const payload = new Binary(ByteUtils.fromUTF8(`\x00${username}\x00${password}`)); |
| 16 | const command = { |
| 17 | saslStart: 1, |
| 18 | mechanism: 'PLAIN', |
| 19 | payload: payload, |
| 20 | autoAuthorize: 1 |
| 21 | }; |
| 22 | |
| 23 | await connection.command(ns('$external.$cmd'), command, undefined); |
| 24 | } |
| 25 | } |