L lip Active Member Licensed User Longtime User Feb 8, 2023 #1 Code: Sub Auth_TokenAvailable (User As FirebaseUser, Success As Boolean, TokenId As String) This fires when the App is launched and the Google user is logged in. I get the TokenId and store it as a string in Process_Globals in the Starter service. I include the JWT as a parameter in all Posts to my server. I use the Firebase SDK to validate the JWT in the server, which includes a check that the validity date/times in the claims are current, which initially they are, but after a couple of hours they have timed-out. Should I periodically (or just before using) check the dates in my stored TokenId in my B4A app and if they are old, refresh the TokenId? I don't really want to get a new TokenId every time I call the API. Also - how do I get the claims from the TokenId from within the B4A App (so that I can check the valid times and get a new Token if necessary)? I guess that there is a JWT parser in a B4A library somewhere but I've not found it. Thanks in advance to anyone who can help Last edited: Feb 8, 2023
Code: Sub Auth_TokenAvailable (User As FirebaseUser, Success As Boolean, TokenId As String) This fires when the App is launched and the Google user is logged in. I get the TokenId and store it as a string in Process_Globals in the Starter service. I include the JWT as a parameter in all Posts to my server. I use the Firebase SDK to validate the JWT in the server, which includes a check that the validity date/times in the claims are current, which initially they are, but after a couple of hours they have timed-out. Should I periodically (or just before using) check the dates in my stored TokenId in my B4A app and if they are old, refresh the TokenId? I don't really want to get a new TokenId every time I call the API. Also - how do I get the claims from the TokenId from within the B4A App (so that I can check the valid times and get a new Token if necessary)? I guess that there is a JWT parser in a B4A library somewhere but I've not found it. Thanks in advance to anyone who can help
Erel B4X founder Staff member Licensed User Longtime User Feb 9, 2023 #2 I haven't tried it myself but the jFirebaseServer will probably work on Android as well. Try it. Upvote 0
L lip Active Member Licensed User Longtime User Feb 13, 2023 #3 Erel said: jFirebaseServer Click to expand... Code: Compiling resources (0.10s) Linking resources (0.80s) Compiling generated Java code. (0.07s) Convert byte code - optimized dex. Error Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseApp; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseApp$1; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseAppLifecycleListener; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseException; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions$1; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions$Builder; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/auth/FirebaseAuth; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/auth/FirebaseAuthException; UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.RuntimeException: Translation has been interrupted at com.android.dx.command.dexer.Main.processAllFiles(Main.java:692) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315) at com.android.dx.command.dexer.Main.runDx(Main.java:293) at com.android.dx.command.dexer.Main.main(Main.java:249) at com.android.dx.command.Main.main(Main.java:94) Caused by: java.lang.InterruptedException: Too many errors at com.android.dx.command.dexer.Main.processAllFiles(Main.java:684) ... 4 more Upvote 0
Erel said: jFirebaseServer Click to expand... Code: Compiling resources (0.10s) Linking resources (0.80s) Compiling generated Java code. (0.07s) Convert byte code - optimized dex. Error Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseApp; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseApp$1; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseAppLifecycleListener; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseException; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions$1; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseOptions$Builder; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/auth/FirebaseAuth; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/firebase/auth/FirebaseAuthException; UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.RuntimeException: Translation has been interrupted at com.android.dx.command.dexer.Main.processAllFiles(Main.java:692) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315) at com.android.dx.command.dexer.Main.runDx(Main.java:293) at com.android.dx.command.dexer.Main.main(Main.java:249) at com.android.dx.command.Main.main(Main.java:94) Caused by: java.lang.InterruptedException: Too many errors at com.android.dx.command.dexer.Main.processAllFiles(Main.java:684) ... 4 more
L lip Active Member Licensed User Longtime User Feb 13, 2023 #4 Not sure if I've put this in the right place: Starter: Service_Create Code: Dim FirebaseJSON As InputStream = File.OpenInput(File.DirAssets,"xxxx-firebase-adminsdk-xxxxa.json") jFirebaseServer.Initialize("FirebaseServer",FirebaseJSON) Upvote 0
Not sure if I've put this in the right place: Starter: Service_Create Code: Dim FirebaseJSON As InputStream = File.OpenInput(File.DirAssets,"xxxx-firebase-adminsdk-xxxxa.json") jFirebaseServer.Initialize("FirebaseServer",FirebaseJSON)
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2023 #5 You can parse the JWT token with this code: https://www.b4x.com/android/forum/threads/get-the-expiration-time-from-firebase-jwt-token.146137/ Upvote 0
You can parse the JWT token with this code: https://www.b4x.com/android/forum/threads/get-the-expiration-time-from-firebase-jwt-token.146137/