signInWithGoogleWindows method
Future<UserCredential>
signInWithGoogleWindows(
{ - bool retry = true,
})
Implementation
Future<UserCredential> signInWithGoogleWindows({bool retry = true}) async {
if (!Arcane.app.canSignInWithGoogleOnWindows) {
error("Unable to sign in with google on windows!");
info(
"1. Define windowsGoogleSignInClientId in your Arcane instance. Copy this from https://console.cloud.google.com/apis/credentials");
info(" 1.a: Click on Web client (auto created by Google Service)");
info(
" 1.b: Copy Client ID under Additional Information (right sidebar)");
info(
"2. Define windowsGoogleSignInRedirectUri in your Arcane instance. Copy this from Authorized Redirect URIs section in the same page");
throw Exception(
"Unable to sign in with google on windows! See console for instructions on how to set this up!");
}
if (await hasAuthToken()) {
try {
verbose("Logging in with GSToken on Windows using saved token");
final OAuthCredential at = GoogleAuthProvider.credential(
accessToken: (await loadAuthToken()).accessToken);
return await FirebaseAuth.instance.signInWithCredential(AuthCredential(
providerId: at.providerId,
signInMethod: at.signInMethod,
accessToken: at.accessToken,
token: at.token,
));
} catch (e, es) {
error("Looks like our saved credentials are invalid!");
warn(e);
warn(es);
await clearAuthToken();
if (retry) {
return signInWithGoogleWindows();
} else {
rethrow;
}
}
} else {
try {
verbose("Logging in with GSToken on Windows with popup");
final AuthResult ar = (await openGoogleSignInPopupWindows())!;
final OAuthCredential at =
GoogleAuthProvider.credential(accessToken: ar.accessToken);
return await FirebaseAuth.instance
.signInWithCredential(AuthCredential(
providerId: at.providerId,
signInMethod: at.signInMethod,
accessToken: at.accessToken,
token: at.token,
))
.thenRun((_) => saveAuthToken(ar));
} catch (e, es) {
error("Failed to sign in with Google!");
error(e);
error(es);
rethrow;
}
}
}