promoteAnonymousUser method
Future<UserInfo>
promoteAnonymousUser({
- required String redirectURI,
- String? wechatRedirectURI,
- List<
String> ? uiLocales, - ColorScheme? colorScheme,
Implementation
Future<UserInfo> promoteAnonymousUser({
required String redirectURI,
String? wechatRedirectURI,
List<String>? uiLocales,
ColorScheme? colorScheme,
}) async {
final kid = await _storage.getAnonymousKeyID(name);
if (kid == null) {
throw Exception("anonymous kid not found");
}
final challengeResponse =
await _apiClient.getChallenge("anonymous_request");
final now = DateTime.now().toUtc().millisecondsSinceEpoch / 1000;
final payload = {
"iat": now,
"exp": now + 300,
"challenge": challengeResponse.token,
"action": "promote",
};
final jwt = await native.signWithAnonymousPrivateKey(
kid: kid,
payload: payload,
);
final loginHint =
Uri.parse("https://authgear.com/login_hint").replace(queryParameters: {
"type": "anonymous",
"jwt": jwt,
}).toString();
final codeVerifier = CodeVerifier(_rng);
final oidcRequest = OIDCAuthenticationRequest(
clientID: clientID,
redirectURI: redirectURI,
responseType: "code",
scope: [
"openid",
"offline_access",
"https://authgear.com/scopes/full-access",
],
codeChallenge: codeVerifier.codeChallenge,
prompt: [PromptOption.login],
loginHint: loginHint,
uiLocales: uiLocales,
colorScheme: colorScheme,
suppressIDPSessionCookie: !shareSessionWithSystemBrowser,
wechatRedirectURI: wechatRedirectURI,
);
final config = await _apiClient.fetchOIDCConfiguration();
final authenticationURL = Uri.parse(config.authorizationEndpoint)
.replace(queryParameters: oidcRequest.toQueryParameters());
final resultURL = await native.authenticate(
url: authenticationURL.toString(),
redirectURI: redirectURI,
wechatRedirectURI: wechatRedirectURI,
onWechatRedirectURI: _onWechatRedirectURI,
preferEphemeral: !shareSessionWithSystemBrowser,
);
final xDeviceInfo = await _getXDeviceInfo();
final userInfo = await _finishAuthentication(
url: Uri.parse(resultURL),
redirectURI: redirectURI,
codeVerifier: codeVerifier,
xDeviceInfo: xDeviceInfo);
await _disableAnonymous();
await disableBiometric();
return userInfo;
}