Skip to content

Commit ea87688

Browse files
committed
👌 Remove redundant credentials in authenticator
1 parent 7e0a608 commit ea87688

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/src/auth/auth.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ abstract class PostgresAuthenticator {
1717
void onMessage(AuthenticationMessage message);
1818
}
1919

20-
PostgresAuthenticator createAuthenticator(PostgreSQLConnection connection, UsernamePasswordCredential credentials) {
20+
PostgresAuthenticator createAuthenticator(PostgreSQLConnection connection) {
2121
switch (connection.authenticationScheme) {
2222
case AuthenticationScheme.MD5:
23-
return MD5Authenticator(connection, credentials);
23+
return MD5Authenticator(connection);
2424
case AuthenticationScheme.SCRAM_SHA_256:
25+
final credentials = UsernamePasswordCredential(username: connection.username, password: connection.password);
2526
return PostgresSaslAuthenticator(connection, ScramAuthenticator('SCRAM-SHA-256', sha256, credentials));
2627
default:
2728
throw PostgreSQLException("Authenticator wasn't specified");

lib/src/auth/md5_authenticator.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:buffer/buffer.dart';
22
import 'package:crypto/crypto.dart';
3-
import 'package:sasl_scram/sasl_scram.dart';
43

54
import '../../postgres.dart';
65
import '../client_messages.dart';
@@ -11,9 +10,7 @@ import 'auth.dart';
1110
class MD5Authenticator extends PostgresAuthenticator {
1211
static final String name = 'MD5';
1312

14-
final UsernamePasswordCredential credentials;
15-
16-
MD5Authenticator(PostgreSQLConnection connection, this.credentials) : super(connection);
13+
MD5Authenticator(PostgreSQLConnection connection) : super(connection);
1714

1815
@override
1916
void onMessage(AuthenticationMessage message) {

lib/src/connection_fsm.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ class _PostgreSQLConnectionStateAuthenticating
113113
continue authInit;
114114
authInit:
115115
case AuthenticationMessage.KindSASL:
116-
final credential = UsernamePasswordCredential(
117-
username: connection!.username, password: connection!.password);
118-
_authenticator = createAuthenticator(connection!, credential);
116+
_authenticator = createAuthenticator(connection!);
119117
continue authMsg;
120118
authMsg:
121119
case AuthenticationMessage.KindSASLContinue:

0 commit comments

Comments
 (0)