@@ -10,82 +10,88 @@ import 'package:model/oidc/token_oidc.dart';
10
10
import 'package:tmail_ui_user/features/login/data/extensions/authentication_token_extension.dart' ;
11
11
import 'package:tmail_ui_user/features/login/data/extensions/token_response_extension.dart' ;
12
12
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart' ;
13
+ import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_interaction_mixin.dart' ;
13
14
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart' ;
14
15
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart' ;
15
16
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart' ;
16
17
17
- class AuthenticationClientMobile implements AuthenticationClientBase {
18
+ class AuthenticationClientMobile with AuthenticationClientInteractionMixin
19
+ implements AuthenticationClientBase {
18
20
19
21
final FlutterAppAuth _appAuth;
20
22
21
23
AuthenticationClientMobile (this ._appAuth);
22
24
23
25
@override
24
- Future <TokenOIDC > getTokenOIDC (String clientId, String redirectUrl,
25
- String discoveryUrl, List <String > scopes) async {
26
+ Future <TokenOIDC > getTokenOIDC (
27
+ String clientId,
28
+ String redirectUrl,
29
+ String discoveryUrl,
30
+ List <String > scopes,
31
+ ) async {
32
+ final authorizationTokenRequest = getAuthorizationTokenRequest (
33
+ clientId,
34
+ redirectUrl,
35
+ discoveryUrl,
36
+ scopes,
37
+ );
26
38
final authorizationTokenResponse = await _appAuth.authorizeAndExchangeCode (
27
- AuthorizationTokenRequest (
28
- clientId,
29
- redirectUrl,
30
- discoveryUrl: discoveryUrl,
31
- scopes: scopes,
32
- preferEphemeralSession: true ));
33
-
34
- log ('AuthenticationClientMobile::getTokenOIDC(): token: ${authorizationTokenResponse ?.accessToken }' );
35
-
36
- if (authorizationTokenResponse != null ) {
37
- final tokenOIDC = authorizationTokenResponse.toTokenOIDC ();
38
- if (tokenOIDC.isTokenValid ()) {
39
- return tokenOIDC;
40
- } else {
41
- throw AccessTokenInvalidException ();
42
- }
39
+ authorizationTokenRequest,
40
+ );
41
+ log ('$runtimeType ::getTokenOIDC(): token: ${authorizationTokenResponse .accessToken }' );
42
+ final tokenOIDC = authorizationTokenResponse.toTokenOIDC ();
43
+ if (tokenOIDC.isTokenValid ()) {
44
+ return tokenOIDC;
43
45
} else {
44
- throw NotFoundAccessTokenException ();
46
+ throw AccessTokenInvalidException ();
45
47
}
46
48
}
47
49
48
50
@override
49
- Future <bool > logoutOidc (TokenId tokenId, OIDCConfiguration config, OIDCDiscoveryResponse oidcRescovery) async {
50
- final authorizationServiceConfiguration = oidcRescovery.authorizationEndpoint == null || oidcRescovery.tokenEndpoint == null
51
- ? null
52
- : AuthorizationServiceConfiguration (
53
- authorizationEndpoint: oidcRescovery.authorizationEndpoint! ,
54
- tokenEndpoint: oidcRescovery.tokenEndpoint! ,
55
- endSessionEndpoint: oidcRescovery.endSessionEndpoint);
56
-
57
- final endSession = await _appAuth.endSession (EndSessionRequest (
58
- idTokenHint: tokenId.uuid,
59
- postLogoutRedirectUrl: config.logoutRedirectUrl,
60
- discoveryUrl: config.discoveryUrl,
61
- serviceConfiguration: authorizationServiceConfiguration,
62
- preferEphemeralSession: true ,
63
- ));
64
- log ('AuthenticationClientMobile::logoutOidc(): ${endSession ?.state }' );
65
- return endSession? .state? .isNotEmpty == true ;
51
+ Future <bool > logoutOidc (
52
+ TokenId tokenId,
53
+ OIDCConfiguration config,
54
+ OIDCDiscoveryResponse discoveryResponse,
55
+ ) async {
56
+ final endSessionRequest = getEndSessionRequest (
57
+ tokenId,
58
+ config,
59
+ discoveryResponse,
60
+ );
61
+ final endSession = await _appAuth.endSession (endSessionRequest);
62
+ log ('$runtimeType ::logoutOidc(): ${endSession .state }' );
63
+ return endSession.state? .isNotEmpty == true ;
66
64
}
67
65
68
66
@override
69
- Future <TokenOIDC > refreshingTokensOIDC (String clientId, String redirectUrl,
70
- String discoveryUrl, List <String > scopes, String refreshToken) async {
71
- final tokenResponse = await _appAuth.token (TokenRequest (
67
+ Future <TokenOIDC > refreshingTokensOIDC (
68
+ String clientId,
69
+ String redirectUrl,
70
+ String discoveryUrl,
71
+ List <String > scopes,
72
+ String refreshToken,
73
+ ) async {
74
+ try {
75
+ final tokenRequest = getRefreshTokenRequest (
72
76
clientId,
73
77
redirectUrl,
74
- discoveryUrl: discoveryUrl,
75
- refreshToken: refreshToken,
76
- scopes: scopes));
77
-
78
- log ('AuthenticationClientMobile::refreshingTokensOIDC(): refreshToken: ${tokenResponse ?.accessToken }' );
79
-
80
- if (tokenResponse != null ) {
81
- final tokenOIDC = tokenResponse.toTokenOIDC (maybeAvailableRefreshToken: refreshToken);
78
+ discoveryUrl,
79
+ refreshToken,
80
+ scopes,
81
+ );
82
+ final tokenResponse = await _appAuth.token (tokenRequest);
83
+ log ('$runtimeType ::refreshingTokensOIDC():Token: ${tokenResponse .accessToken }' );
84
+ final tokenOIDC = tokenResponse.toTokenOIDC (
85
+ maybeAvailableRefreshToken: refreshToken,
86
+ );
82
87
if (tokenOIDC.isTokenValid ()) {
83
88
return tokenOIDC;
84
89
} else {
85
90
throw AccessTokenInvalidException ();
86
91
}
87
- } else {
88
- throw NotFoundAccessTokenException ();
92
+ } catch (e) {
93
+ logError ('$runtimeType ::refreshingTokensOIDC(): $e ' );
94
+ throw handleException (e);
89
95
}
90
96
}
91
97
@@ -104,7 +110,7 @@ class AuthenticationClientMobile implements AuthenticationClientBase {
104
110
intentFlags: ephemeralIntentFlags,
105
111
),
106
112
);
107
- log ('AuthenticationClientMobile ::signInTwakeWorkplace():Uri = $uri ' );
113
+ log ('$ runtimeType ::signInTwakeWorkplace():Uri = $uri ' );
108
114
return TokenOIDC .fromUri (uri);
109
115
}
110
116
@@ -117,7 +123,7 @@ class AuthenticationClientMobile implements AuthenticationClientBase {
117
123
intentFlags: ephemeralIntentFlags,
118
124
),
119
125
);
120
- log ('AuthenticationClientMobile ::signUpTwakeWorkplace():Uri = $uri ' );
126
+ log ('$ runtimeType ::signUpTwakeWorkplace():Uri = $uri ' );
121
127
return TokenOIDC .fromUri (uri);
122
128
}
123
129
}
0 commit comments