signIn method
Future
signIn(
{ - bool reAuthenticate = false,
- bool suppressErrors = true,
- bool silentOnly = false,
})
Implementation
@override
Future signIn({
bool reAuthenticate = false,
bool suppressErrors = true,
bool silentOnly = false,
}) async {
String debugPrefix = '$runtimeType.signIn()';
lazy.log(debugPrefix, forced: debugLog);
// We don't want to keep updating token.value in middle of process
String tokenTmp = token.value;
Duration secondSinceSignIn =
DateTime.now().toUtc().difference(_apiFirefoxSignInTime);
if (reAuthenticate ||
token.value.isEmpty ||
secondSinceSignIn.inSeconds > (_apiFireFoxSignInDuration - 100)) {
try {
// https://{redirectUri}/
// #access_token={token}
// &token_type=Bearer
// &expires_in={3599}
// &scope={scopes}
dynamic res;
if (!reAuthenticate) {
lazy.log('$debugPrefix:_api.launchWebAuthFlow(interactive: false)',
forced: debugLog);
res = await _api.launchWebAuthFlow(interactive: false);
lazy.log(
'$debugPrefix:_api.launchWebAuthFlow(interactive: false):res:${res.toString()}',
forced: debugLog);
tokenTmp = _extractToken(res);
}
if (tokenTmp.isEmpty) {
lazy.log('$debugPrefix:_api.launchWebAuthFlow(interactive: true)',
forced: debugLog);
res = await _api.launchWebAuthFlow(interactive: true);
lazy.log(
'$debugPrefix:_api.launchWebAuthFlow(interactive: true):res:${res.toString()}',
forced: debugLog);
tokenTmp = _extractToken(res);
}
if (_apiFireFoxSignInDuration == 0) {
_reset();
throw ('Something wrong, cannot get [expire_in].');
}
_apiFirefoxSignInTime = DateTime.now().toUtc();
_photoUrl = await getPhotoUrl(tokenTmp);
token.value = tokenTmp;
isSignedIn.value = true;
} catch (e) {
_reset();
lazy.log('$debugPrefix:catch:$e', forced: debugLog);
throw ('$debugPrefix:$e');
}
}
}