使用电子邮件/密码进行Firebase身份验证

时间:2017-03-03 23:00:44

标签: json vb.net authentication firebase

我已将这两个包添加到我的项目中: https://github.com/step-up-labs/firebase-database-dotnethttps://github.com/step-up-labs/firebase-authentication-dotnet

我正在尝试从VB.NET访问Firebase上的JSON数据,使用API​​密钥和电子邮件/密码进行身份验证。我的代码:

Async Sub AccessTheWebAsync()

    Dim authProvider = New FirebaseAuthProvider(New FirebaseConfig("myAPIkey"))

    Dim auth = authProvider.SignInWithEmailAndPasswordAsync("myemail", "myPW").Result

    Dim firebase = New FirebaseClient("myFireBaseURL")

    Dim venues = Await firebase.Child("venues").OrderByKey().WithAuth(auth.FirebaseToken).OnceAsync(Of Venue)()

    'more code

end sub

在“auth.FirebaseToken”上获取此错误: “类型'String'的值不能转换为'System.Func(Of String)'”

还尝试了这种方法(Google身份验证):

Async Sub AccessTheWebAsync()

    Dim result = Await GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = myclientID, .ClientSecret = myclientsecret}, {"https://www.googleapis.com/auth/firebase"}, "user", CancellationToken.None)

    FetchFirebaseData(result.Token.AccessToken, FirebaseAuthType.Google)

End Sub

Private Async Sub FetchFirebaseData(accessToken As String, authType As FirebaseAuthType)

    Dim auth = New FirebaseAuthProvider(New FirebaseConfig(myFirebaseAppKey))

    'error on this line:
    Dim data = Await auth.SignInWithOAuthAsync(authType, accessToken)

    'more code to do something with the data

End Sub

错误消息为:“message”:“无法将Google用户个人资料响应解析为JSON:{\”error \“:{\”code \“:403,\”message \“:\”Insufficient Permission \“ ,\“errors \”:[{\“reason \”:\“insufficientPermissions \”,\“domain \”:\“global \”,\“message \”:\“Perufficient Permission \”}]}}“

最终,我希望能够访问“数据”(JSON)以及我的Firebase项目的“规则”(JSON)。这样我就可以创建一个非常基本的前端,我可以在本地机器上运行。

1 个答案:

答案 0 :(得分:0)

WithAuth()方法需要Func(Of String)而非普通String

Func(Of String)是一个委托方法,指向一个返回字符串的函数,所以你可以让它返回auth.FirebaseToken并且它应该有效:

Dim venues = Await firebase.Child("venues").OrderByKey().WithAuth(DirectCast(Function() auth.FirebaseToken, Func(Of String))).OnceAsync(Of Venue)()