authenticate method
Future<AuthenticationResult?>
authenticate({
- required OAuthProvider provider,
- required Uri redirectUri,
- required List<
String> scope, - required String responseType,
- required String responseMode,
- required String? prompt,
- required String? codeChallenge,
- required String? codeChallengeMethod,
- required Map<
String, dynamic> otherParams, - required WebAuthenticationMode webMode,
override
Implementation
@override
Future<AuthenticationResult?> authenticate({
required OAuthProvider provider,
required Uri redirectUri,
required List<String> scope,
required String responseType,
required String responseMode,
required String? prompt,
required String? codeChallenge,
required String? codeChallengeMethod,
required Map<String, dynamic> otherParams,
required WebAuthenticationMode webMode,
}) async {
final authUri = provider.getAuthUri(
redirectUri: redirectUri,
scope: scope,
responseType: responseType,
responseMode: responseMode,
prompt: prompt,
codeChallenge: codeChallenge,
codeChallengeMethod: codeChallengeMethod,
otherParams: otherParams,
);
final completer = Completer<Uri?>();
webMode.when(
sameTab: (sameTab) {
html.window.location.href = authUri.toString();
},
popup: (popup) async {
final screen = html.window.screen;
final screenWidth = screen?.width;
final screenHeight = screen?.height;
final ScreenDimensions? screenDimensions;
if (screenWidth != null && screenHeight != null) {
screenDimensions = ScreenDimensions(
width: screenWidth,
height: screenHeight,
);
} else {
screenDimensions = null;
}
final window = html.window.open(
authUri.toString(),
popup.windowName,
popup.constructSpecs(screenDimensions: screenDimensions),
);
html.window.onMessage.first.then(
(value) {
final redirect = Uri.parse(value.data['redirect']);
completer.complete(redirect);
},
);
Timer.periodic(const Duration(seconds: 1), (timer) {
if (completer.isCompleted) {
timer.cancel();
} else if (window.closed == true) {
completer.complete(null);
timer.cancel();
}
});
},
);
final redirect = await completer.future;
if (redirect != null) {
return AuthenticationResult(redirect: redirect);
} else {
return null;
}
}