bugthesystem / FireSharp

An asynchronous cross-platform .Net library for Firebase
The Unlicense
696 stars 147 forks source link

Connect to firebase as a specific user #130

Open tblack2200 opened 6 years ago

tblack2200 commented 6 years ago

During my initial tests, I've connected to firebase, using the firesharp code below, which works fine. How do I connect as a specific user, applying their security rules? I didn't see a way to pass in their identifier and UID.

Private objConfig As IFirebaseConfig
Private objClient As IFirebaseClient

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Try
        objConfig = New FirebaseConfig()
        With objConfig
            .BasePath = "https://<my base url>/"
            .AuthSecret = "<my auth secret>"
        End With

        objClient = New FireSharp.FirebaseClient(objConfig)

    Catch ex As Exception
        MessageBox.Show("Connection Failed")
    End Try
End Sub
arcosmin commented 6 years ago

Hi @tblack2200, for using the firebase rules you would need to authenticate the user first through Firebase Authentication, you can't pass your own 'security context'. I haven't been involved in FireSharp in a while but as far as I know FireSharp only provides access to the Firebase Database.

1Serf commented 4 years ago

You can use firebase-authentication-dotnet to Authenticate your user and get Auth object . from there get the Firebase token Auth.FirebaseToken then use it in FireSharp Config IFirebaseConfig config = new FireSharp.Config.FirebaseConfig { RequestTimeout = TimeSpan.FromDays(1),

                    BasePath = "https://calm-seeker-257120.firebaseio.com/",
                    AuthSecret = auth.FirebaseToken

                };