authByToken static method

Future<AuthResult> authByToken(
  1. String token,
  2. AuthRequest authRequest
)

Auth by Authing token

Implementation

static Future<AuthResult> authByToken(
    String token, AuthRequest authRequest) async {
  String url = "https://" + Util.getHost(Authing.config) + "/oidc/token";
  String body = "client_id=" +
      Authing.sAppId +
      "&grant_type=http://authing.cn/oidc/grant_type/authing_token" +
      "&token=" +
      token +
      "&scope=" +
      authRequest.scope +
      "&prompt=" +
      "consent" +
      "&code_verifier=" +
      authRequest.codeVerifier +
      "&redirect_uri=" +
      Uri.encodeComponent(authRequest.redirectUrl);

  Result result = await oauthRequest("post", url, body);
  AuthResult authResult = AuthResult(result);
  if (authResult.code == 200 || authResult.code == 201) {
    AuthResult userResult = await AuthClient.getCurrentUser();
    authResult.user =
        await User.update(userResult.user ?? User(), result.data);
    return authResult;
  } else {
    return authResult;
  }
}