-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54bb6a2
commit 6931f0f
Showing
4 changed files
with
231 additions
and
194 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 |
---|---|---|
|
@@ -32,13 +32,21 @@ class MyHomePage extends StatefulWidget { | |
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
|
||
static const String authorizationEndpointUrl = String.fromEnvironment('AUTHORIZATION_ENDPOINT_URL', defaultValue: 'https://test-auth-endpoint.com'); | ||
static const String tokenEndpointUrl = String.fromEnvironment('TOKEN_ENDPOINT_URL', defaultValue: 'https://test-token-endpoint.com'); | ||
static const String clientSecret = String.fromEnvironment('CLIENT_SECRET', defaultValue: 'XXXXXXXXX'); | ||
static const String clientId = String.fromEnvironment('CLIENT_ID', defaultValue: 'realmClientID'); | ||
static const String redirectUrl = String.fromEnvironment('REDIRECT_URL', defaultValue: 'https://test-redirect-to.com'); | ||
final List<String> scopes = const String.fromEnvironment('SCOPES', defaultValue: 'https://test-redirect-to.com').split(' '); | ||
static const String authorizationEndpointUrl = String.fromEnvironment( | ||
'AUTHORIZATION_ENDPOINT_URL', | ||
defaultValue: 'https://test-auth-endpoint.com'); | ||
static const String tokenEndpointUrl = String.fromEnvironment( | ||
'TOKEN_ENDPOINT_URL', | ||
defaultValue: 'https://test-token-endpoint.com'); | ||
static const String clientSecret = | ||
String.fromEnvironment('CLIENT_SECRET', defaultValue: 'XXXXXXXXX'); | ||
static const String clientId = | ||
String.fromEnvironment('CLIENT_ID', defaultValue: 'realmClientID'); | ||
static const String redirectUrl = String.fromEnvironment('REDIRECT_URL', | ||
defaultValue: 'https://test-redirect-to.com'); | ||
final List<String> scopes = const String.fromEnvironment('SCOPES', | ||
defaultValue: 'https://test-redirect-to.com') | ||
.split(' '); | ||
|
||
String authResponse = 'Authorization data will be shown here'; | ||
|
||
|
@@ -61,8 +69,7 @@ class _MyHomePageState extends State<MyHomePage> { | |
onPressed: loginV1, | ||
child: const Text('Login variant 1'), | ||
style: ButtonStyle( | ||
backgroundColor: MaterialStateProperty.all(Colors.green) | ||
), | ||
backgroundColor: MaterialStateProperty.all(Colors.green)), | ||
), | ||
const SizedBox(height: 4), | ||
ElevatedButton( | ||
|
@@ -78,31 +85,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é?', | ||
} | ||
); | ||
if(result != null) { | ||
if(result is Credentials) { | ||
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é?', | ||
}); | ||
if (result != null) { | ||
if (result is Credentials) { | ||
authResponse = getPrettyCredentialsJson(result); | ||
} else { | ||
authResponse = result.toString(); | ||
|
@@ -115,44 +124,46 @@ class _MyHomePageState extends State<MyHomePage> { | |
|
||
void loginV2() { | ||
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 text 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é?', | ||
}, | ||
onSuccess: (credentials) { | ||
setState(() { | ||
authResponse = getPrettyCredentialsJson(credentials); | ||
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 text 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é?', | ||
}, | ||
onSuccess: (credentials) { | ||
setState(() { | ||
authResponse = getPrettyCredentialsJson(credentials); | ||
}); | ||
}, | ||
onError: (error) { | ||
setState(() { | ||
authResponse = error.toString(); | ||
}); | ||
}, | ||
onCancel: () { | ||
setState(() { | ||
authResponse = 'User cancelled authentication'; | ||
}); | ||
}); | ||
}, | ||
onError: (error) { | ||
setState(() { | ||
authResponse = error.toString(); | ||
}); | ||
}, | ||
onCancel: () { | ||
setState(() { | ||
authResponse = 'User cancelled authentication'; | ||
}); | ||
} | ||
); | ||
} | ||
|
||
String getPrettyCredentialsJson(Credentials 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
Oops, something went wrong.