Skip to content

Commit 6cd53a2

Browse files
refactor: Minor UX improvements to the new auth (serverpod#4386)
1 parent 042ab95 commit 6cd53a2

22 files changed

Lines changed: 137 additions & 106 deletions

File tree

examples/auth/auth_server/config/template.passwords.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ development:
2121
# Authentication managers configuration
2222
serverSideSessionKeyHashPepper: 'test_session_key_pepper'
2323
jwtRefreshTokenHashPepper: 'test_refresh_token_pepper'
24-
jwtPrivateKey: 'test_private_key'
24+
jwtHmacSha512PrivateKey: 'test_private_key'
2525

2626
# Email Sign In configuration
2727
emailSecretHashPepper: 'test_email_password_hash_pepper'

examples/auth/auth_server/lib/server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void run(List<String> args) async {
3232
'jwtRefreshTokenHashPepper',
3333
)!,
3434
algorithm: JwtAlgorithm.hmacSha512(
35-
SecretKey(pod.getPassword('jwtPrivateKey')!),
35+
SecretKey(pod.getPassword('jwtHmacSha512PrivateKey')!),
3636
),
3737
);
3838

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_client/lib/serverpod_auth_core_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export 'src/protocol/protocol.dart';
22
export 'package:serverpod_client/serverpod_client.dart';
33
export 'src/auth_key_providers/jwt_auth_key_provider.dart';
44
export 'src/auth_key_providers/sas_auth_key_provider.dart';
5-
export 'src/session_manager.dart' hide ClientAuthSessionManagerExtension;
5+
export 'src/session_manager.dart';
66
export 'src/storage/client_auth_success_storage.dart';
77
export 'src/storage/cached_client_auth_success_storage.dart';
88
export 'src/storage/key_value_client_auth_success_storage.dart';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export 'package:serverpod_auth_core_client/serverpod_auth_core_client.dart'
2-
hide ClientAuthSessionManager;
2+
hide ClientAuthSessionManager, ClientAuthSessionManagerExtension;
33

44
export 'src/session_manager.dart';
55
export 'src/storage/secure_client_auth_success_storage.dart';

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_flutter/lib/src/session_manager.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/foundation.dart';
2-
import 'package:serverpod_auth_core_client/serverpod_auth_core_client.dart'
3-
as core;
2+
import 'package:serverpod_auth_core_client/serverpod_auth_core_client.dart';
43

54
import 'storage/secure_client_auth_success_storage.dart';
65

@@ -10,17 +9,17 @@ import 'storage/secure_client_auth_success_storage.dart';
109
/// see supported methods. Session information is stored in the secure shared
1110
/// preferences of the app and persists between restarts of the app.
1211
///
13-
/// This class extends [core.ClientAuthSessionManager] and adds Flutter-specific
12+
/// This class extends [ClientAuthSessionManager] and adds Flutter-specific
1413
/// reactive primitives ([ValueNotifier] and [ValueListenable]) for state
1514
/// management.
16-
class FlutterAuthSessionManager extends core.ClientAuthSessionManager {
17-
final ValueNotifier<core.AuthSuccess?> _authInfoNotifier;
15+
class FlutterAuthSessionManager extends ClientAuthSessionManager {
16+
final ValueNotifier<AuthSuccess?> _authInfoNotifier;
1817

1918
/// Creates a new [FlutterAuthSessionManager].
2019
FlutterAuthSessionManager._internal({
21-
required ValueNotifier<core.AuthSuccess?> authInfoNotifier,
20+
required ValueNotifier<AuthSuccess?> authInfoNotifier,
2221
required super.storage,
23-
required void Function(core.AuthSuccess?) onAuthInfoChanged,
22+
required void Function(AuthSuccess?) onAuthInfoChanged,
2423
super.caller,
2524
super.authKeyProviderDelegates,
2625
}) : _authInfoNotifier = authInfoNotifier,
@@ -30,17 +29,17 @@ class FlutterAuthSessionManager extends core.ClientAuthSessionManager {
3029
factory FlutterAuthSessionManager({
3130
/// Optionally override the caller. If not provided directly, the caller
3231
/// must be set before usage by calling [setCaller].
33-
core.Caller? caller,
32+
Caller? caller,
3433

3534
/// The authentication key provider to use for each auth strategy. If not
3635
/// provided, a default one will be created as needed.
37-
Map<String, core.ClientAuthKeyProvider>? authKeyProviderDelegates,
36+
Map<String, ClientAuthKeyProvider>? authKeyProviderDelegates,
3837

3938
/// The storage to keep user authentication info. If missing, the
4039
/// session manager will create a [SecureClientAuthSuccessStorage].
41-
core.ClientAuthSuccessStorage? storage,
40+
ClientAuthSuccessStorage? storage,
4241
}) {
43-
final authInfoNotifier = ValueNotifier<core.AuthSuccess?>(null);
42+
final authInfoNotifier = ValueNotifier<AuthSuccess?>(null);
4443

4544
return FlutterAuthSessionManager._internal(
4645
caller: caller,
@@ -66,12 +65,11 @@ class FlutterAuthSessionManager extends core.ClientAuthSessionManager {
6665
/// ```
6766
///
6867
/// To get the current auth info value directly, use the [authInfo] property.
69-
ValueListenable<core.AuthSuccess?> get authInfoListenable =>
70-
_authInfoNotifier;
68+
ValueListenable<AuthSuccess?> get authInfoListenable => _authInfoNotifier;
7169
}
7270

7371
/// Extension for ServerpodClientShared to provide auth session management.
74-
extension FlutterAuthSessionManagerExtension on core.ServerpodClientShared {
72+
extension FlutterAuthSessionManagerExtension on ServerpodClientShared {
7573
/// The authentication session manager to sign in and manage user sessions.
7674
FlutterAuthSessionManager get authSessionManager {
7775
final currentProvider = authKeyProvider;
@@ -101,9 +99,9 @@ extension FlutterAuthSessionManagerExtension on core.ServerpodClientShared {
10199
}
102100
}
103101

104-
extension on core.ServerpodClientShared {
105-
core.Caller getCaller() {
106-
var caller = moduleLookup.values.whereType<core.Caller>().firstOrNull;
102+
extension on ServerpodClientShared {
103+
Caller getCaller() {
104+
var caller = moduleLookup.values.whereType<Caller>().firstOrNull;
107105
if (caller != null) return caller;
108106
throw StateError('No authentication module found.');
109107
}

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/auth_services.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/common.dart

Lines changed: 0 additions & 5 deletions
This file was deleted.

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/serverpod_auth_core_server.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export 'src/common/business/multi_token_manager.dart';
1212
export 'src/common/integrations/provider_builder.dart';
1313
export 'src/common/integrations/token_manager.dart';
1414
export 'src/common/integrations/token_manager_builder.dart';
15+
export 'src/common/utils/argon2_hash_util.dart';
1516
export 'src/generated/endpoints.dart';
1617
export 'src/generated/protocol.dart';
1718
export 'src/jwt/jwt.dart';

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/src/jwt/business/jwt.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'dart:typed_data';
44
import 'package:clock/clock.dart';
55
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart' as dart_jsonwebtoken;
66
import 'package:serverpod/serverpod.dart';
7-
import 'package:serverpod_auth_core_server/common.dart';
87
import 'package:serverpod_auth_core_server/src/jwt/business/refresh_token_exceptions.dart';
98
import 'package:serverpod_shared/serverpod_shared.dart';
109

1110
import '../../auth_user/auth_user.dart';
11+
import '../../common/utils/argon2_hash_util.dart';
1212
import '../../generated/protocol.dart';
1313
import 'authentication_info_from_jwt.dart';
1414
import 'jwt_admin.dart';

modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/src/jwt/business/jwt_admin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import 'dart:typed_data';
33
import 'package:clock/clock.dart';
44
import 'package:meta/meta.dart';
55
import 'package:serverpod/serverpod.dart';
6-
import 'package:serverpod_auth_core_server/common.dart';
76
import 'package:serverpod_auth_core_server/src/jwt/business/refresh_token_exceptions.dart';
87
import 'package:serverpod_shared/serverpod_shared.dart';
98

9+
import '../../common/utils/argon2_hash_util.dart';
1010
import '../../generated/protocol.dart';
1111
import 'jwt_util.dart';
1212
import 'refresh_token_string.dart';

0 commit comments

Comments
 (0)