通过Google SSO进行Firebase Web身份验证-如何知道用户是否已注册或登录

时间:2018-07-24 09:12:03

标签: firebase firebase-authentication

我想检测用户是刚刚通过SSO注册还是直接登录。

文档没有帮助。

我正在使用React + ES6。这是我当前的身份验证方法:

authWithGoogle = () => {
    this.props.setIsLoggingInState(true);
    firebaseApp
      .auth()
      .getRedirectResult()
      .catch(() => console.error('something went wrong with Google SSO'));
    firebaseApp
      .auth()
      .signInWithRedirect(googleProvider)
      .catch(() => console.error('something went wrong with Google SSO'));
};

说实话,上面的代码似乎不正确...(但它可以工作)

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

var principal = actionContext.RequestContext.Principal;
if (principal != null)
{
    Thread.CurrentPrincipal = principal;
    AzureActiveDirectoryCredentials identity;
    try
    {
         identity = await principal.GetAppServiceIdentityAsync<AzureActiveDirectoryCredentials>(actionContext.Request);
    }
    catch (Exception ex)
    {
         logger.Error(ex, "Error while retrieving AD Identity");
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
    }
    ......
}