Skip to content

Commit

Permalink
Allows for the select_account prompt value to be used by not clea…
Browse files Browse the repository at this point in the history
…ring 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
  • Loading branch information
paulhwangfti authored Aug 9, 2024
1 parent f9c5f85 commit 33b8f6e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/aad_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class AadOAuth {
Future<String?> getIdToken() async => _coreOAuth.getIdToken();

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

/// Checks if MSAL has cached information
Future<bool> get hasCachedAccountInformation async =>
Expand Down
4 changes: 2 additions & 2 deletions lib/helper/core_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CoreOAuth {
errorType: ErrorType.unsupported,
message: 'Unsupported silentlyLogin');

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

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

@override
Future<void> logout({bool showPopup = true}) async {}
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {}

@override
Future<bool> get hasCachedAccountInformation async => true;
Expand Down
6 changes: 4 additions & 2 deletions lib/helper/mobile_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ class MobileOAuth extends CoreOAuth {

/// Perform Azure AD logout.
@override
Future<void> logout({bool showPopup = true}) async {
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {
await _authStorage.clear();
await _requestCode.clearCookies();
if (clearCookies) {
await _requestCode.clearCookies();
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/web_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class WebOAuth extends CoreOAuth {
}

@override
Future<void> logout({bool showPopup = true}) async {
Future<void> logout({bool showPopup = true, bool clearCookies = true}) async {
final completer = Completer<void>();

jsLogout(
Expand Down
4 changes: 3 additions & 1 deletion lib/model/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class Config {
final String? state;

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

/// Used to secure authorization code grants via Proof Key for Code Exchange (PKCE).
Expand Down
4 changes: 3 additions & 1 deletion lib/request_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class RequestCode {
final AuthorizationRequest _authorizationRequest;
final String _redirectUriHost;
late NavigationDelegate _navigationDelegate;
late WebViewCookieManager _cookieManager;
String? _code;

RequestCode(Config config)
Expand All @@ -20,6 +21,7 @@ class RequestCode {
_navigationDelegate = NavigationDelegate(
onNavigationRequest: _onNavigationRequest,
);
_cookieManager = WebViewCookieManager();
}

Future<String?> requestCode() async {
Expand Down Expand Up @@ -100,7 +102,7 @@ class RequestCode {
}

Future<void> clearCookies() async {
await WebViewCookieManager().clearCookies();
await _cookieManager.clearCookies();
}

String _constructUrlParams() => _mapToQueryParams(
Expand Down

0 comments on commit 33b8f6e

Please sign in to comment.