Android Question Firebase authentication problem

Matrix

Member
Licensed User
Hello,

I have a Firebase authentication problem - but I do not know what is the problem
I followed the instructions

1. Register with Firebase and create a new project
2. Add Android app under project setting
3. the package name matches my app's package name -> b4a.firebase
4. Create a private Key with B4A / Tools/Private-Key and copy the SHA1 Key
5. I use thecreate SHA1 Key for Fingerprint to register the APP at Firebase
6. Download the google-services.json in the b4a project root

after programstart
-> auth.CurrentUser.IsInitialized get false return !?

Where is the problem now?
I hope someone has an idea
Thank you


B4X:
Region Project Attributes
#ApplicationLabel: B4A Firebase Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False

#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
Private auth As FirebaseAuth
End Sub

Sub Globals
Private lblName As Label
Private btnSignIn As Button
Private btnSignOut As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
auth.Initialize("auth")
End If

Activity.LoadLayout("layout1")

If auth.CurrentUser.IsInitialized Then
Auth_SignedIn(auth.CurrentUser)
Else
Msgbox("connection error " ,"Firebase")
End If

End Sub

Sub btnSignIn_Click
auth.SignInWithGoogle
End Sub

Sub btnSignOut_Click
auth.SignOutFromGoogle
lblName.Text = "Goodbye!"
End Sub

Sub Auth_SignedIn (User As FirebaseUser)
Log("SignedIn: " & User.DisplayName)
lblName.Text = "Hello: " & User.DisplayName
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


the manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
 

Matrix

Member
Licensed User
Hello Erel,

I can start the program without any errors
I click the sign in button and than I get the message from msgbox "connection error"

in the debug mode step by step :

If auth.CurrentUser.IsInitialized Then
Auth_SignedIn(auth.CurrentUser)
Else
Msgbox("connection error " ,"Firebase")
End If

I think I have a configuration problem between b4a and google??
but woh?

packed name is the same : b4a.firebase
SHA1 Key is copied to Firebase project
google-services.json is copied from firebase to b4a root

I have to adjust something else under firebase?
is there any way to find out more about the mistake, what is wrong. via a special debug function

Thank you
Timo
 
Upvote 0

Matrix

Member
Licensed User
Sorry, I have to correct myself!
I just started the project again

the problem occurs at the start before clicking sign in button

if start the project and I debug the code step by step

here is my problem => auth.CurrentUser.IsInitialized


Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
auth.Initialize("auth")
End If

Activity.LoadLayout("layout1")

If auth.CurrentUser.IsInitialized Then
Auth_SignedIn(auth.CurrentUser)
Else
Msgbox("conecting error " ,"Firebase")
End If

End Sub



again sorry for my mistake!!
 
Upvote 0

Matrix

Member
Licensed User
OK
if the problem occurs at Sub Activity_Create
so I think it is an initialization error ??

or it may also be an installation problem of the development environment?


B4X:
Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
auth.Initialize("auth")
End If

Activity.LoadLayout("layout1")

If auth.CurrentUser.IsInitialized Then
Auth_SignedIn(auth.CurrentUser)
Else
Msgbox("conecting error " ,"Firebase")
End If

End Sub
 
Upvote 0

Matrix

Member
Licensed User
sometimes I'm blind - since I had problems with the configuration all the time, I did not test any further back ... I saw only the mistake in the beginning, which is actually no one ... super

If I cklick so open a google Login or user selection window. I can choose a user and then I get the User infos. - so far ok! thank you

question:
you can specify a user so that the selection window does not appear?


my next question
for access to the Firebase database , I need the TokenID
this TokenID can I read with auth.GetuserTokenid(User,False)
- is this correct ?


What is the best way/function to access the database?
can I use download2 from library OkHttpUtils2
for example

B4X:
Dim j As HttpJob
    j.Initialize("", Me)
    'full list of features available: person.addresses,person.age_ranges,person.biographies,person.birthdays,person.bragging_rights,person.cover_photos,person.email_addresses,person.events,person.genders,person.im_clients,person.interests,person.locales,person.memberships,person.metadata,person.names,person.nicknames,person.occupations,person.organizations,person.phone_numbers,person.photos,person.relations,person.relationship_interests,person.relationship_statuses,person.residences,person.skills,person.taglines,person.urls
    j.Download2("https://people.googleapis.com/v1/people/me", _
         Array As String("access_token", TokenID, "requestMask.includeField", "person.email_addresses,person.birthdays,person.names"))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ParsePersonData(j.GetString)
    Else
        oauth2.ResetToken
        ToastMessageShow("Online data not available.", True)
    End If
    j.Release

or is there still a way?


Thank you
Timo
 
Upvote 0
Top