forked from luis901101/oauth_webauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-
contentLocale
property can be set to indicate the web auth to use…
… that locale for internationalization.
- Loading branch information
1 parent
dd291c3
commit 2479672
Showing
11 changed files
with
109 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ | |
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
build/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ | |
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
build/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ void main() { | |
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
|
@@ -49,6 +50,8 @@ class _MyHomePageState extends State<MyHomePage> { | |
.split(' '); | ||
|
||
String authResponse = 'Authorization data will be shown here'; | ||
Locale? contentLocale; | ||
final locales = const [null, Locale('es'), Locale('en')]; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
|
@@ -65,6 +68,24 @@ class _MyHomePageState extends State<MyHomePage> { | |
authResponse, | ||
), | ||
const SizedBox(height: 16), | ||
SizedBox( | ||
width: 120, | ||
child: DropdownButtonFormField<Locale>( | ||
items: locales | ||
.map((e) => DropdownMenuItem( | ||
value: e, | ||
child: Text(e?.toLanguageTag() ?? 'Default OS'))) | ||
.toList(), | ||
value: contentLocale, | ||
onChanged: (locale) { | ||
setState(() { | ||
contentLocale = locale; | ||
}); | ||
}, | ||
decoration: | ||
const InputDecoration(label: Text('Content language')), | ||
), | ||
), | ||
ElevatedButton( | ||
onPressed: loginV1, | ||
child: const Text('Login variant 1'), | ||
|
@@ -85,31 +106,33 @@ class _MyHomePageState extends State<MyHomePage> { | |
|
||
void loginV1() async { | ||
final result = await OAuthWebScreen.start( | ||
context: context, | ||
authorizationEndpointUrl: authorizationEndpointUrl, | ||
tokenEndpointUrl: tokenEndpointUrl, | ||
clientSecret: clientSecret, | ||
clientId: clientId, | ||
redirectUrl: redirectUrl, | ||
scopes: scopes, | ||
promptValues: const ['login'], | ||
loginHint: '[email protected]', | ||
onCertificateValidate: (certificate) { | ||
///This is recommended | ||
/// Do certificate validations here | ||
/// If false is returned then a CertificateException() will be thrown | ||
return true; | ||
}, | ||
textLocales: { | ||
///Optionally texts can be localized | ||
OAuthWebView.backButtonTooltipKey: 'Ir atrás', | ||
OAuthWebView.forwardButtonTooltipKey: 'Ir adelante', | ||
OAuthWebView.reloadButtonTooltipKey: 'Recargar', | ||
OAuthWebView.clearCacheButtonTooltipKey: 'Limpiar caché', | ||
OAuthWebView.closeButtonTooltipKey: 'Cerrar', | ||
OAuthWebView.clearCacheWarningMessageKey: | ||
'¿Está seguro que desea limpiar la caché?', | ||
}); | ||
context: context, | ||
authorizationEndpointUrl: authorizationEndpointUrl, | ||
tokenEndpointUrl: tokenEndpointUrl, | ||
clientSecret: clientSecret, | ||
clientId: clientId, | ||
redirectUrl: redirectUrl, | ||
scopes: scopes, | ||
promptValues: const ['login'], | ||
loginHint: '[email protected]', | ||
onCertificateValidate: (certificate) { | ||
///This is recommended | ||
/// Do certificate validations here | ||
/// If false is returned then a CertificateException() will be thrown | ||
return true; | ||
}, | ||
textLocales: { | ||
///Optionally texts can be localized | ||
OAuthWebView.backButtonTooltipKey: 'Ir atrás', | ||
OAuthWebView.forwardButtonTooltipKey: 'Ir adelante', | ||
OAuthWebView.reloadButtonTooltipKey: 'Recargar', | ||
OAuthWebView.clearCacheButtonTooltipKey: 'Limpiar caché', | ||
OAuthWebView.closeButtonTooltipKey: 'Cerrar', | ||
OAuthWebView.clearCacheWarningMessageKey: | ||
'¿Está seguro que desea limpiar la caché?', | ||
}, | ||
contentLocale: contentLocale, | ||
); | ||
if (result != null) { | ||
if (result is Credentials) { | ||
authResponse = getPrettyCredentialsJson(result); | ||
|
@@ -149,6 +172,7 @@ class _MyHomePageState extends State<MyHomePage> { | |
OAuthWebView.clearCacheWarningMessageKey: | ||
'¿Está seguro que desea limpiar la caché?', | ||
}, | ||
contentLocale: contentLocale, | ||
onSuccess: (credentials) { | ||
setState(() { | ||
authResponse = getPrettyCredentialsJson(credentials); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters