用电子邮件/密码进行Firebase身份验证 [英] Firebase authentication with email/password
问题描述
我已经将这两个软件包添加到了我的项目中:
https ://github.com/step-up-labs/firebase-database-dotnet 和
https://github.com/step-up-labs/firebase-authentication-dotnet
我正在尝试从VB.NET访问Firebase上的JSON数据,使用API密钥和电子邮件/密码进行身份验证。我的代码:
$ b $ pre $ Async Sub AccessTheWebAsync()
暗淡的authProvider =新的FirebaseAuthProvider(新的FirebaseConfig( myAPIkey))
Dim auth = authProvider.SignInWithEmailAndPasswordAsync(myemail,myPW)。结果
Dim firebase =新的FirebaseClient(myFireBaseURL)
Dim venues =等待firebase.Child(venues)。OrderByKey()。WithAuth(auth.FirebaseToken).OnceAsync(Of Venue)()
'more code
end sub
在auth.FirebaseToken上获取这个错误:
'String'类型的值不能转换为'System.Func(Of String)'
也试过这个方法(Google身份验证):
pre $
Async Sub AccessTheWebAsync()
Dim result =等待GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets()with {.ClientId = myclientID ,.ClientSecret = myclientsecret},{https://www.googleapis.com/auth/firebase},用户,Cancella tionToken.None)
FetchFirebaseData(result.Token.AccessToken,FirebaseAuthType.Google)
End Sub
Private Async Sub FetchFirebaseData(accessToken As String ,authType As FirebaseAuthType)
Dim auth =新的FirebaseAuthProvider(新的FirebaseConfig(myFirebaseAppKey))
'在这一行上的错误:
Dim data = Await auth.SignInWithOAuthAsync (authType,accessToken)
'更多的代码来处理数据
结束Sub
错误消息是:message:无法将Google用户配置文件响应解析为JSON:{\error \:{\code \:403, \message \:\Permission Permission \,\errors \:[{\reason\:\insufficientPermissions \,\domain \ :\global \,\message \:\Permission Permission \}}}}
最终,我想能够访问数据(JSON),还有我的Firebase项目的规则(JSON)。这是我可以创建一个非常基本的前端,我可以在我的本地机器上运行。 $ c> WithAuth()方法需要一个 Func(Of String)
而不是一个普通的 String
。
$ b
A Func(Of String)
是一个委托方法,指向一个返回字符串的函数,所以你可以让它返回 auth.FirebaseToken
,它应该可以工作:
<$ c $ ()()()()()()
I have added these 2 packages to my project: https://github.com/step-up-labs/firebase-database-dotnet and https://github.com/step-up-labs/firebase-authentication-dotnet
I am trying to access JSON data on Firebase from VB.NET, using API key and email/password for authentication. My code:
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
Getting this error on "auth.FirebaseToken": "Value of type 'String' cannot be converted to 'System.Func(Of String)'"
Also tried this method (Google authentication):
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
The error message is: "message": "Cannot parse Google user profile response as JSON: {\"error\":{\"code\":403,\"message\":\"Insufficient Permission\",\"errors\":[{\"reason\":\"insufficientPermissions\",\"domain\":\"global\",\"message\":\"Insufficient Permission\"}]}}"
Ultimately, I want to be able to access the "data" (JSON), and also the "rules" (JSON) for my Firebase project. This is so I can create a very basic front-end that I can run on my local machine.
The WithAuth()
method expects a Func(Of String)
rather than a normal String
.
A Func(Of String)
is a delegate method pointing to a function that returns a string, so you can just have it return auth.FirebaseToken
and it should work:
Dim venues = Await firebase.Child("venues").OrderByKey().WithAuth(DirectCast(Function() auth.FirebaseToken, Func(Of String))).OnceAsync(Of Venue)()
这篇关于用电子邮件/密码进行Firebase身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!