Skip to content

Commit

Permalink
app_auth platform interface: implement SFSafariController
Browse files Browse the repository at this point in the history
  • Loading branch information
john-slow committed Sep 17, 2024
1 parent c15d81e commit ca99141
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -7,11 +9,15 @@ mixin AuthorizationParameters {
/// Server prompts the End-User for reauthentication and consent.
List<String>? 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;
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +17,8 @@ class AuthorizationRequest extends CommonRequestDetails
Map<String, String>? additionalParameters,
List<String>? promptValues,
bool allowInsecureConnections = false,
bool preferEphemeralSession = false,
ExternalAgentType preferredExternalAgent =
ExternalAgentType.ASWebAuthenticationSession,
String? nonce,
String? responseMode,
}) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'authorization_parameters.dart';
import 'external_agent_type.dart';
import 'grant_types.dart';
import 'token_request.dart';

Expand All @@ -17,15 +18,16 @@ class AuthorizationTokenRequest extends TokenRequest
super.discoveryUrl,
List<String>? promptValues,
super.allowInsecureConnections,
bool preferEphemeralSession = false,
ExternalAgentType preferredExternalAgent =
ExternalAgentType.ASWebAuthenticationSession,
super.nonce,
String? responseMode,
}) : super(
grantType: GrantType.authorizationCode,
) {
this.loginHint = loginHint;
this.promptValues = promptValues;
this.preferEphemeralSession = preferEphemeralSession;
this.preferredExternalAgent = preferredExternalAgent;
this.responseMode = responseMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, String>? additionalParameters;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum ExternalAgentType {
ASWebAuthenticationSession,
EphemeralSession,
SFSafariViewController
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension EndSessionRequestMapper on EndSessionRequest {
'issuer': issuer,
'discoveryUrl': discoveryUrl,
'serviceConfiguration': serviceConfiguration?.toMap(),
'preferEphemeralSession': preferEphemeralSession,
'preferredExternalAgent': preferredExternalAgent.toString(),
};
}
}
Expand Down Expand Up @@ -99,7 +99,8 @@ Map<String, Object?> _convertAuthorizationParametersToMap(
return <String, Object?>{
'loginHint': authorizationParameters.loginHint,
'promptValues': authorizationParameters.promptValues,
'preferEphemeralSession': authorizationParameters.preferEphemeralSession,
'preferredExternalAgent':
authorizationParameters.preferredExternalAgent.toString(),
'responseMode': authorizationParameters.responseMode,
};
}
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -38,7 +39,8 @@ void main() {
'serviceConfiguration': null,
'additionalParameters': null,
'allowInsecureConnections': false,
'preferEphemeralSession': false,
'preferredExternalAgent':
ExternalAgentType.ASWebAuthenticationSession.toString(),
'promptValues': null,
'responseMode': null,
'nonce': null,
Expand Down Expand Up @@ -66,7 +68,8 @@ void main() {
'serviceConfiguration': null,
'additionalParameters': null,
'allowInsecureConnections': false,
'preferEphemeralSession': false,
'preferredExternalAgent':
ExternalAgentType.ASWebAuthenticationSession.toString(),
'promptValues': null,
'clientSecret': null,
'refreshToken': null,
Expand Down Expand Up @@ -184,7 +187,8 @@ void main() {
'issuer': null,
'discoveryUrl': 'someDiscoveryUrl',
'serviceConfiguration': null,
'preferEphemeralSession': false,
'preferredExternalAgent':
ExternalAgentType.ASWebAuthenticationSession.toString(),
})
]);
});
Expand Down

0 comments on commit ca99141

Please sign in to comment.