Skip to content

Commit 33b8f6e

Browse files
authored
Allows for the select_account prompt value to be used by not clearing cookies if user wishes not to on a logout (#331)
* WIP: getting select_account to work * Added cookies to the webview for mobile * Adjusted `config.dart` to account for new `prompt` value
1 parent f9c5f85 commit 33b8f6e

6 files changed

Lines changed: 15 additions & 9 deletions

File tree

lib/aad_oauth.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class AadOAuth {
3737
Future<String?> getIdToken() async => _coreOAuth.getIdToken();
3838

3939
/// Perform Azure AD logout.
40-
Future<void> logout({bool showWebPopup = true}) async =>
41-
_coreOAuth.logout(showPopup: showWebPopup);
40+
Future<void> logout({bool showWebPopup = true, bool clearCookies = true}) async =>
41+
_coreOAuth.logout(showPopup: showWebPopup, clearCookies: clearCookies);
4242

4343
/// Checks if MSAL has cached information
4444
Future<bool> get hasCachedAccountInformation async =>

lib/helper/core_oauth.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CoreOAuth {
2121
errorType: ErrorType.unsupported,
2222
message: 'Unsupported silentlyLogin');
2323

24-
Future<void> logout({bool showPopup = true}) async =>
24+
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async =>
2525
throw UnsupportedFailure(
2626
errorType: ErrorType.unsupported, message: 'Unsupported logout');
2727

@@ -48,7 +48,7 @@ class MockCoreOAuth extends CoreOAuth {
4848
Right(Token(accessToken: mockAccessToken));
4949

5050
@override
51-
Future<void> logout({bool showPopup = true}) async {}
51+
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {}
5252

5353
@override
5454
Future<bool> get hasCachedAccountInformation async => true;

lib/helper/mobile_oauth.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ class MobileOAuth extends CoreOAuth {
102102

103103
/// Perform Azure AD logout.
104104
@override
105-
Future<void> logout({bool showPopup = true}) async {
105+
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {
106106
await _authStorage.clear();
107-
await _requestCode.clearCookies();
107+
if (clearCookies) {
108+
await _requestCode.clearCookies();
109+
}
108110
}
109111

110112
@override

lib/helper/web_oauth.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class WebOAuth extends CoreOAuth {
132132
}
133133

134134
@override
135-
Future<void> logout({bool showPopup = true}) async {
135+
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {
136136
final completer = Completer<void>();
137137

138138
jsLogout(

lib/model/config.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class Config {
5757
final String? state;
5858

5959
/// Indicates the type of user interaction that is required.
60-
/// The only valid values at this time are *login*, *none*, and *consent*.
60+
/// The only valid values at this time are *login*, *none*, *consent*, and *select_account*.
61+
/// If *select_account* is wanting to be used, the user must have at least signed in once and
62+
/// when logging out, the *clearCookies* value must be false.
6163
final String? prompt;
6264

6365
/// Used to secure authorization code grants via Proof Key for Code Exchange (PKCE).

lib/request_code.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class RequestCode {
1111
final AuthorizationRequest _authorizationRequest;
1212
final String _redirectUriHost;
1313
late NavigationDelegate _navigationDelegate;
14+
late WebViewCookieManager _cookieManager;
1415
String? _code;
1516

1617
RequestCode(Config config)
@@ -20,6 +21,7 @@ class RequestCode {
2021
_navigationDelegate = NavigationDelegate(
2122
onNavigationRequest: _onNavigationRequest,
2223
);
24+
_cookieManager = WebViewCookieManager();
2325
}
2426

2527
Future<String?> requestCode() async {
@@ -100,7 +102,7 @@ class RequestCode {
100102
}
101103

102104
Future<void> clearCookies() async {
103-
await WebViewCookieManager().clearCookies();
105+
await _cookieManager.clearCookies();
104106
}
105107

106108
String _constructUrlParams() => _mapToQueryParams(

0 commit comments

Comments
 (0)