The advantage of the rest API of Firebase auth is that it can be used cross platform. The downside is, we have to take care of the user access tokens ourselves. That's why I wrote this class, it works with the "FirebaseAuthREST" class.
The class was inspired by @Erel oauth2 class, adapted to my class
For the attached example you need the FirebaseAuthREST class.
The class were tested in B4A.
FirebaseAuthRESTHelper
Author: Alexander Stolte
Version: 1.0
Changelog
The class was inspired by @Erel oauth2 class, adapted to my class
[class][B4X] Google OAuth2
GoogleOAuth2 class is compatible with B4A, B4i and B4J (new). It is no longer possible to use WebView to implement Google's OAuth2 authentication. The solution is to open the default browser and set the redirection uri in such a way that the browser will redirect the response back to our app...
www.b4x.com
[B4X] Firebase Auth REST API
Not all API commands I have implemented and tested, if you have problems, then ask in the comments or in a new thread. With this class you can register and log in your users via email and password. And a lot more... Setup: put your API Key in the Class_Globals Private const API_KEY As String...
www.b4x.com
FirebaseAuthRESTHelper
Author: Alexander Stolte
Version: 1.0
- FirebaseAuthRESTHelper
- Events:
- AccessTokenAvailable (Success As Boolean, Token As String)
- Authenticate
- RefreshToken (RefreshToken As String)
- Functions:
- Class_Globals As String
- GetAccessToken As String
- Initialize (Target As Object, EventName As String) As String
Initializes the object. You can add parameters to this method if needed. - IsInitialized As Boolean
Tests whether the object has been initialized. - ResetToken As String
- TokenInformationFromResponse (m As Map) As String
- Events:
- TokenInformations
- Fields:
- AccessExpiry As Long
- AccessToken As String
- IsInitialized As Boolean
Tests whether the object has been initialized. - RefreshToken As String
- Valid As Boolean
- Functions:
- Initialize
Initializes the fields to their default value.
- Initialize
- Fields:
Usage Example:
Dim farh As FirebaseAuthRESTHelper
Dim far As FirebaseAuthREST
farh.Initialize(Me,"farh")
far.Initialize
farh.GetAccessToken
Private Sub farh_AccessTokenAvailable (Success As Boolean, Token As String)
Log("farh_AccessTokenAvailable")
Log("Success: " & Success)
Log("Token: " & Token)
End Sub
Private Sub farh_Authenticate
Log("farh_Authenticate")
Wait For (far.signInEmailPW("myemail@lol.de","Test123",True)) complete (root As Map)
If root.Get("success") = True Then
farh.TokenInformationFromResponse(root)
End If
End Sub
Private Sub farh_RefreshToken (RefreshToken As String)
Log("farh_RefreshToken")
Log("RefreshToken: " & RefreshToken)
Wait For (far.refreshToken("refresh_token",RefreshToken)) complete (root As Map)
If root.Get("success") = True Then
farh.TokenInformationFromResponse(root)
End If
End Sub
Changelog
- 1.00
- Release
- 1.01
- Add GetEmail - gets the email-address from the user
- 1.02
- Add tag to TokenInformations
Attachments
Last edited: