From ca991419986ace9dba73751505a26d8370d2cbde Mon Sep 17 00:00:00 2001 From: Cheng Date: Tue, 17 Sep 2024 13:42:07 -0400 Subject: [PATCH] app_auth platform interface: implement SFSafariController --- .../flutter_appauth_platform_interface.dart | 1 + .../lib/src/authorization_parameters.dart | 14 ++++++++++---- .../lib/src/authorization_request.dart | 6 ++++-- .../lib/src/authorization_token_request.dart | 6 ++++-- .../lib/src/end_session_request.dart | 19 +++++++++++-------- .../lib/src/external_agent_type.dart | 5 +++++ .../lib/src/method_channel_mappers.dart | 5 +++-- .../method_channel_flutter_appauth_test.dart | 10 +++++++--- 8 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 flutter_appauth_platform_interface/lib/src/external_agent_type.dart diff --git a/flutter_appauth_platform_interface/lib/flutter_appauth_platform_interface.dart b/flutter_appauth_platform_interface/lib/flutter_appauth_platform_interface.dart index 16582ebe..c738b9cc 100644 --- a/flutter_appauth_platform_interface/lib/flutter_appauth_platform_interface.dart +++ b/flutter_appauth_platform_interface/lib/flutter_appauth_platform_interface.dart @@ -6,6 +6,7 @@ export 'src/authorization_token_response.dart'; export 'src/end_session_request.dart'; export 'src/end_session_response.dart'; export 'src/errors.dart'; +export 'src/external_agent_type.dart'; export 'src/flutter_appauth_platform.dart'; export 'src/grant_types.dart'; export 'src/token_request.dart'; diff --git a/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart b/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart index 94c427b4..ab74de96 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart @@ -1,3 +1,5 @@ +import 'external_agent_type.dart'; + mixin AuthorizationParameters { /// Hint to the Authorization Server about the login identifier the End-User /// might use to log in. @@ -7,11 +9,15 @@ mixin AuthorizationParameters { /// Server prompts the End-User for reauthentication and consent. List? promptValues; - /// Whether to use an ephemeral session that prevents cookies and other - /// browser data being shared with the user's normal browser session. - /// + /// Decides what type of external agent to use for the authorization flow. + /// ASWebAuthenticationSession is the default for iOS 12 and above. + /// EphemeralSession is not sharing browser data + /// with the user's normal browser session but not keeping the cache + /// SFSafariViewController is not sharing browser data + /// with the user's normal browser session but keeping the cache. /// This property is only applicable to iOS versions 13 and above. - bool? preferEphemeralSession; + /// ExternalAgentType? preferredExternalAgent; + ExternalAgentType? preferredExternalAgent; String? responseMode; } diff --git a/flutter_appauth_platform_interface/lib/src/authorization_request.dart b/flutter_appauth_platform_interface/lib/src/authorization_request.dart index b7b56fb1..837ed649 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_request.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_request.dart @@ -1,6 +1,7 @@ import 'authorization_parameters.dart'; import 'authorization_service_configuration.dart'; import 'common_request_details.dart'; +import 'external_agent_type.dart'; /// The details of an authorization request to get an authorization code. class AuthorizationRequest extends CommonRequestDetails @@ -16,7 +17,8 @@ class AuthorizationRequest extends CommonRequestDetails Map? additionalParameters, List? promptValues, bool allowInsecureConnections = false, - bool preferEphemeralSession = false, + ExternalAgentType preferredExternalAgent = + ExternalAgentType.ASWebAuthenticationSession, String? nonce, String? responseMode, }) { @@ -30,7 +32,7 @@ class AuthorizationRequest extends CommonRequestDetails this.loginHint = loginHint; this.promptValues = promptValues; this.allowInsecureConnections = allowInsecureConnections; - this.preferEphemeralSession = preferEphemeralSession; + this.preferredExternalAgent = preferredExternalAgent; this.nonce = nonce; this.responseMode = responseMode; assertConfigurationInfo(); diff --git a/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart b/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart index dad96b52..9ae5bc0b 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart @@ -1,4 +1,5 @@ import 'authorization_parameters.dart'; +import 'external_agent_type.dart'; import 'grant_types.dart'; import 'token_request.dart'; @@ -17,7 +18,8 @@ class AuthorizationTokenRequest extends TokenRequest super.discoveryUrl, List? promptValues, super.allowInsecureConnections, - bool preferEphemeralSession = false, + ExternalAgentType preferredExternalAgent = + ExternalAgentType.ASWebAuthenticationSession, super.nonce, String? responseMode, }) : super( @@ -25,7 +27,7 @@ class AuthorizationTokenRequest extends TokenRequest ) { this.loginHint = loginHint; this.promptValues = promptValues; - this.preferEphemeralSession = preferEphemeralSession; + this.preferredExternalAgent = preferredExternalAgent; this.responseMode = responseMode; } } diff --git a/flutter_appauth_platform_interface/lib/src/end_session_request.dart b/flutter_appauth_platform_interface/lib/src/end_session_request.dart index 4f5f1d32..b8d34c61 100644 --- a/flutter_appauth_platform_interface/lib/src/end_session_request.dart +++ b/flutter_appauth_platform_interface/lib/src/end_session_request.dart @@ -8,7 +8,7 @@ class EndSessionRequest with AcceptedAuthorizationServiceConfigurationDetails { this.postLogoutRedirectUrl, this.state, this.allowInsecureConnections = false, - this.preferEphemeralSession = false, + this.preferredExternalAgent = ExternalAgentType.ASWebAuthenticationSession, this.additionalParameters, String? issuer, String? discoveryUrl, @@ -38,14 +38,17 @@ class EndSessionRequest with AcceptedAuthorizationServiceConfigurationDetails { /// This property is only applicable to Android. bool allowInsecureConnections; - /// Whether to use an ephemeral session that prevents cookies and other - /// browser data being shared with the user's normal browser session. + /// Decides what type of external agent to use for the authorization flow. + /// ASWebAuthenticationSession is the default for iOS 12 and above. + /// EphemeralSession is not sharing browser data + /// with the user's normal browser session but not keeping the cache + /// SFSafariViewController is not sharing browser data + /// with the user's normal browser session but keeping the cache. + /// This property is only applicable to iOS versions 13 and above. + /// ExternalAgentType? preferredExternalAgent; /// - /// This property is only applicable to iOS (versions 13 and above) and macOS. - /// - /// preferEphemeralSession = true must only be used here, if it is also used - /// for the sign in call. - bool preferEphemeralSession; + /// Sign in and out must have the same type. + ExternalAgentType? preferredExternalAgent; final Map? additionalParameters; } diff --git a/flutter_appauth_platform_interface/lib/src/external_agent_type.dart b/flutter_appauth_platform_interface/lib/src/external_agent_type.dart new file mode 100644 index 00000000..c5ea7882 --- /dev/null +++ b/flutter_appauth_platform_interface/lib/src/external_agent_type.dart @@ -0,0 +1,5 @@ +enum ExternalAgentType { + ASWebAuthenticationSession, + EphemeralSession, + SFSafariViewController +} diff --git a/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart b/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart index 95c64e00..77c24fd1 100644 --- a/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart +++ b/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart @@ -33,7 +33,7 @@ extension EndSessionRequestMapper on EndSessionRequest { 'issuer': issuer, 'discoveryUrl': discoveryUrl, 'serviceConfiguration': serviceConfiguration?.toMap(), - 'preferEphemeralSession': preferEphemeralSession, + 'preferredExternalAgent': preferredExternalAgent.toString(), }; } } @@ -99,7 +99,8 @@ Map _convertAuthorizationParametersToMap( return { 'loginHint': authorizationParameters.loginHint, 'promptValues': authorizationParameters.promptValues, - 'preferEphemeralSession': authorizationParameters.preferEphemeralSession, + 'preferredExternalAgent': + authorizationParameters.preferredExternalAgent.toString(), 'responseMode': authorizationParameters.responseMode, }; } diff --git a/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart b/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart index 3d4ec46f..55c0d456 100644 --- a/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart +++ b/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart @@ -1,5 +1,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_appauth_platform_interface/flutter_appauth_platform_interface.dart'; +import 'package:flutter_appauth_platform_interface/src/external_agent_type.dart'; import 'package:flutter_appauth_platform_interface/src/method_channel_flutter_appauth.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -38,7 +39,8 @@ void main() { 'serviceConfiguration': null, 'additionalParameters': null, 'allowInsecureConnections': false, - 'preferEphemeralSession': false, + 'preferredExternalAgent': + ExternalAgentType.ASWebAuthenticationSession.toString(), 'promptValues': null, 'responseMode': null, 'nonce': null, @@ -66,7 +68,8 @@ void main() { 'serviceConfiguration': null, 'additionalParameters': null, 'allowInsecureConnections': false, - 'preferEphemeralSession': false, + 'preferredExternalAgent': + ExternalAgentType.ASWebAuthenticationSession.toString(), 'promptValues': null, 'clientSecret': null, 'refreshToken': null, @@ -184,7 +187,8 @@ void main() { 'issuer': null, 'discoveryUrl': 'someDiscoveryUrl', 'serviceConfiguration': null, - 'preferEphemeralSession': false, + 'preferredExternalAgent': + ExternalAgentType.ASWebAuthenticationSession.toString(), }) ]); });