Hello,
I try to implement Firebase Server backend auth. I have a jRDC server up and running correctly. I want to add this verification too. I followed all steps as @Erel mentions. Can i add tutorial's code at seperate server handler in order to call this verification before every post/get call, or i have to add it at main module of jRDC. If i have to add this app start(server start) how it can verify tokens from all users? I think that i am really comfused
My code:
If i try to reach this verify handler with Postman with a random token(not from firebase, just random numbers), first time i get nothing as response and if i try to send this call again i get this as response:
In jRDC log file i find this:
I try to implement Firebase Server backend auth. I have a jRDC server up and running correctly. I want to add this verification too. I followed all steps as @Erel mentions. Can i add tutorial's code at seperate server handler in order to call this verification before every post/get call, or i have to add it at main module of jRDC. If i have to add this app start(server start) how it can verify tokens from all users? I think that i am really comfused
My code:
B4X:
'Handler class
Sub Class_Globals
Private fs As FirebaseServer
End Sub
Public Sub Initialize
fs.Initialize("fs", File.OpenInput(File.DirAssets, "se-eida-*****.json"))
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
If req.Method <> "POST" Then
resp.SendError(500, "Method not supported!")
Return
End If
Dim reqName As String = req.GetParameter("token")
If reqName = "" Then
resp.SendError(500,"Missing parameter!")
Return
End If
fs.VerifyToken(reqName)
Wait For fs_TokenVerified (TokenId As String, Success As Boolean, Token As FirebaseToken)
If Success Then
resp.Write(Token.DisplayName)
resp.Write(Token.Email)
resp.Write(Token.Uid)
Else
resp.SendError(500,LastException.Message)
End If
End Sub
If i try to reach this verify handler with Postman with a random token(not from firebase, just random numbers), first time i get nothing as response and if i try to send this call again i get this as response:
B4X:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 java.lang.reflect.InvocationTargetException</title>
</head>
<body>
<h2>HTTP ERROR 500</h2>
<p>Problem accessing /verify. Reason:
<pre> java.lang.reflect.InvocationTargetException</pre>
</p>
<hr>
<a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a>
<hr/>
</body>
</html>
In jRDC log file i find this:
B4X:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:62)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:128)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
at anywheresoftware.b4j.object.JServlet.doPost(JServlet.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:531)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: FirebaseApp name [DEFAULT] already exists!
at com.google.firebase.internal.Preconditions.checkState(Preconditions.java:173)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:180)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:160)
at anywheresoftware.b4j.objects.FirebaseServer.Initialize(FirebaseServer.java:29)
at b4j.example.verify._initialize(verify.java:173)
... 38 more
Last edited: