ServiceStack中使用Firebase的自定义凭据提供程序

时间:2016-09-28 06:14:41

标签: c# firebase servicestack firebase-authentication

我想为服务堆栈创建一个自定义凭据提供程序,使用firebaseauthentication.net库登录用户到Firebase。我遇到的问题是,在调用身份验证方法后,浏览器会一直说 loading 。这是我的代码:

 public override  bool TryAuthenticate(IServiceBase authService,string userName, string password)
    {
        return  Authenticate(userName, password).Result;
    }

    private async Task<bool> Authenticate(string userName,string password)
    {
        provider = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));
        try
        {
            auth = await provider.SignInWithEmailAndPasswordAsync(userName, password);


            return auth.User != null;
        }
        catch(Exception e)
        {
            return false;
        }

    }

    public override IHttpResult OnAuthenticated(IServiceBase authService,IAuthSession session, IAuthTokens tokens,Dictionary<string, string> authInfo)
    {

        session.FirstName = auth.User.DisplayName;
        session.Id = auth.User.LocalId;
        session.Email = auth.User.Email;

        return base.OnAuthenticated(authService, session, tokens, authInfo);


    }

1 个答案:

答案 0 :(得分:1)

你不应该在同步方法中使用async / await,只需使用一个Task,例如:

private Task<bool> Authenticate(string userName,string password)
{
    provider = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));
    return provider.SignInWithEmailAndPasswordAsync(userName, password)
        .Success(r => r.User != null)
        .Error(ex => false);
}