diff --git a/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart b/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart index 3f85c897ef..16c79df35e 100644 --- a/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart +++ b/packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart @@ -16,6 +16,7 @@ import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart'; import 'package:amplify_authenticator/src/l10n/authenticator_localizations.dart'; import 'package:amplify_authenticator/src/models/authenticator_builder.dart'; import 'package:amplify_authenticator/src/models/authenticator_exception.dart'; +import 'package:amplify_authenticator/src/models/oidc_options.dart'; import 'package:amplify_authenticator/src/models/totp_options.dart'; import 'package:amplify_authenticator/src/screens/authenticator_screen.dart'; import 'package:amplify_authenticator/src/screens/loading_screen.dart'; @@ -45,6 +46,7 @@ export 'package:amplify_authenticator/src/utils/dial_code_options.dart' export 'src/enums/enums.dart' show AuthenticatorStep, Gender; export 'src/l10n/auth_strings_resolver.dart' hide ButtonResolverKeyType; export 'src/models/authenticator_exception.dart'; +export 'src/models/oidc_options.dart'; export 'src/models/totp_options.dart'; export 'src/models/username_input.dart' show UsernameType, UsernameInput, UsernameSelection; @@ -312,6 +314,7 @@ class Authenticator extends StatefulWidget { this.onException, this.exceptionBannerLocation = ExceptionBannerLocation.auto, this.preferPrivateSession = false, + this.oidcOptions, this.initialStep = AuthenticatorStep.signIn, this.authenticatorBuilder, this.padding = const EdgeInsets.all(32), @@ -420,6 +423,9 @@ class Authenticator extends StatefulWidget { /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.private_session} final bool preferPrivateSession; + /// {@macro amplify_authenticator.oidc_options} + final OidcOptions? oidcOptions; + /// This widget will be displayed after a user has signed in. final Widget child; @@ -465,6 +471,11 @@ class Authenticator extends StatefulWidget { ..add( DiagnosticsProperty('preferPrivateSession', preferPrivateSession), ) + ..add(StringProperty('nonce', oidcOptions?.nonce)) + ..add(StringProperty('language', oidcOptions?.language)) + ..add(StringProperty('loginHint', oidcOptions?.loginHint)) + ..add(IterableProperty('prompt', oidcOptions?.prompt)) + ..add(StringProperty('resource', oidcOptions?.resource)) ..add(EnumProperty('initialStep', initialStep)) ..add( ObjectFlagProperty.has( @@ -519,6 +530,7 @@ class _AuthenticatorState extends State { (StateMachineBloc( authService: _authService, preferPrivateSession: widget.preferPrivateSession, + oidcOptions: widget.oidcOptions, initialStep: widget.initialStep, totpOptions: widget.totpOptions, )..add(const AuthLoad())); diff --git a/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart b/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart index 57d6b1fe1e..ffa4d5ec52 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart @@ -24,6 +24,7 @@ class StateMachineBloc StateMachineBloc({ required AuthService authService, required this.preferPrivateSession, + this.oidcOptions, this.initialStep = AuthenticatorStep.signIn, this.totpOptions, }) : _authService = authService { @@ -40,6 +41,7 @@ class StateMachineBloc } final AuthService _authService; final bool preferPrivateSession; + final OidcOptions? oidcOptions; final AuthenticatorStep initialStep; final TotpOptions? totpOptions; diff --git a/packages/authenticator/amplify_authenticator/lib/src/models/oidc_options.dart b/packages/authenticator/amplify_authenticator/lib/src/models/oidc_options.dart new file mode 100644 index 0000000000..4fff0d4dc4 --- /dev/null +++ b/packages/authenticator/amplify_authenticator/lib/src/models/oidc_options.dart @@ -0,0 +1,56 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; + +/// {@template amplify_authenticator.oidc_options} +/// Options for configuring the OIDC sign in parameters +/// +/// ```dart +/// @override +/// Widget build(BuildContext context) { +/// return Authenticator( +/// oidcOptions: const OidcOptions( +/// nonce: 'nonce', +/// language: 'language', +/// loginHint: 'loginHint', +/// prompt: [CognitoSignInWithWebUIPrompt.login], +/// resource: 'resource', +/// ), +/// child: MaterialApp( +/// builder: Authenticator.builder(), +/// home: Scaffold( +/// body: Center( +/// child: Text('You are logged in!'), +/// ), +/// ), +/// ), +/// ), +/// } +/// ``` +/// {@endtemplate} +class OidcOptions { + /// {@macro amplify_authenticator.oidc_options} + const OidcOptions({ + this.nonce, + this.language, + this.loginHint, + this.prompt, + this.resource, + }); + + /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.private_session} + final String? nonce; + + /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.language} + final String? language; + + /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.loginHint} + final String? loginHint; + + /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.prompt} + final List? prompt; + + /// {@macro amplify_auth_cognito.model.cognito_sign_in_with_web_ui_options.resource} + final String? resource; +} diff --git a/packages/authenticator/amplify_authenticator/lib/src/services/amplify_auth_service.dart b/packages/authenticator/amplify_authenticator/lib/src/services/amplify_auth_service.dart index 3c815c7f97..f623b225ce 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/services/amplify_auth_service.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/services/amplify_auth_service.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; +import 'package:amplify_authenticator/amplify_authenticator.dart'; import 'package:amplify_authenticator/src/version.dart'; import 'package:amplify_flutter/amplify_flutter.dart'; import 'package:collection/collection.dart'; @@ -14,6 +15,7 @@ abstract class AuthService { Future signInWithProvider( AuthProvider provider, { required bool preferPrivateSession, + OidcOptions? oidcOptions, }); Future signOut(); @@ -104,6 +106,7 @@ class AmplifyAuthService Future signInWithProvider( AuthProvider provider, { required bool preferPrivateSession, + OidcOptions? oidcOptions, }) { return _withUserAgent( () => Amplify.Auth.signInWithWebUI( @@ -111,6 +114,11 @@ class AmplifyAuthService options: SignInWithWebUIOptions( pluginOptions: CognitoSignInWithWebUIPluginOptions( isPreferPrivateSession: preferPrivateSession, + nonce: oidcOptions?.nonce, + language: oidcOptions?.language, + loginHint: oidcOptions?.loginHint, + prompt: oidcOptions?.prompt, + resource: oidcOptions?.resource, ), ), ), diff --git a/packages/authenticator/amplify_authenticator_test/lib/src/mock_authenticator_app.dart b/packages/authenticator/amplify_authenticator_test/lib/src/mock_authenticator_app.dart index 73c722be6e..92f6977457 100644 --- a/packages/authenticator/amplify_authenticator_test/lib/src/mock_authenticator_app.dart +++ b/packages/authenticator/amplify_authenticator_test/lib/src/mock_authenticator_app.dart @@ -3,6 +3,7 @@ // ignore_for_file: diagnostic_describe_all_properties, invalid_use_of_visible_for_testing_member, implementation_imports +import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart'; import 'package:amplify_authenticator/amplify_authenticator.dart'; import 'package:amplify_authenticator/src/blocs/auth/auth_bloc.dart'; import 'package:amplify_authenticator/src/services/amplify_auth_service.dart'; @@ -55,6 +56,13 @@ class _MockAuthenticatorAppState extends State { final baseBloc = StateMachineBloc( authService: AmplifyAuthService(), preferPrivateSession: false, + oidcOptions: const OidcOptions( + nonce: 'nonce', + language: 'language', + loginHint: 'loginHint', + prompt: [CognitoSignInWithWebUIPrompt.selectAccount], + resource: 'resource', + ), initialStep: widget.initialStep, ); switch (baseBloc.initialStep) { diff --git a/packages/authenticator/amplify_authenticator_test/pubspec.yaml b/packages/authenticator/amplify_authenticator_test/pubspec.yaml index 9543490d61..f3844eece2 100644 --- a/packages/authenticator/amplify_authenticator_test/pubspec.yaml +++ b/packages/authenticator/amplify_authenticator_test/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: amplify_authenticator: any amplify_flutter: any + amplify_auth_cognito_dart: any amplify_integration_test: path: ../../test/amplify_integration_test flutter: