我收到以下错误:
tuple(my_list)
我意识到堆栈不是很有帮助。我在Admin SDK中进行了调试。它正确读取我的服务json,java.lang.IllegalArgumentException
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:111)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:37)
at com.google.api.client.json.webtoken.JsonWebSignature$Parser.parse(JsonWebSignature.java:599)
at com.google.firebase.auth.FirebaseToken.parse(FirebaseToken.java:44)
at com.google.firebase.auth.FirebaseAuth$4.execute(FirebaseAuth.java:456)
at com.google.firebase.auth.FirebaseAuth$4.execute(FirebaseAuth.java:449)
at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
at com.google.firebase.auth.FirebaseAuth.verifyIdToken(FirebaseAuth.java:413)
at d.d.pamper.test.ApplicationTest.testFire2(ApplicationTest.java:46)
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:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
不为空,我可以看到我的项目ID设置正确。
这就是我正在初始化的方式:
FirebaseAuth.getInstance()
这就是我测试我的令牌的方式:
if(FirebaseApp.getApps().size() > 0) {
System.out.println("initialized already ");
return;
}
FirebaseOptions options = null;
try {
System.out.println("try initializing");
options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(gservicesConfig.getInputStream()))
.setDatabaseUrl("https://pamperanywhere.firebaseio.com")
.build();
} catch (IOException e) {
e.printStackTrace();
}
FirebaseApp.initializeApp(options);
return;
我不确定为什么抛出@Test
public void testFire2() {
String idToken = "REFRESH TOKEN FROM FIREBASE";
if(!StringUtils.isEmpty(idToken)) {
FirebaseToken firebaseToken = null;
if(FirebaseAuth.getInstance() == null) {
System.out.println("FirebaseAuth.getInstance() == null");
}
try {
firebaseToken = FirebaseAuth.getInstance().verifyIdToken(idToken, true);
} catch (IllegalArgumentException e) {
System.out.println("exception+IllegalArgumentException");
e.printStackTrace();
} catch (FirebaseAuthException e) {
System.out.println("exception+FirebaseAuthException");
e.printStackTrace();
}
if (firebaseToken == null) {
System.out.println("firebaseToken == null");
}
}
}
。我能够正常登录应用程序(前端),我看到我的刷新令牌(前端),但在管理员方面它给我这个问题。我确信我正在传递正确的令牌,因为我可以登录并查看令牌(前端)。
Maven是:
IllegalArgumentException
感谢您的帮助。
答案 0 :(得分:1)
ID令牌应该是有效的JWT,包含3个段(以点分隔)。刷新令牌肯定不是那样。因此,基础令牌解析器失败并出现上述断言错误。以下是Google API客户端的相关代码。基本上它在给定的标记字符串中找不到任何点。
public JsonWebSignature parse(String tokenString) throws IOException {
// split on the dots
int firstDot = tokenString.indexOf('.');
Preconditions.checkArgument(firstDot != -1);
...
答案 1 :(得分:0)
有一个听众:
firebase.auth().onIdTokenChanged((user: firebase.User) => {
console.log("onIdTokenChanged");
if(user && user.uid) {
user.getIdToken(false)
.then((data: any) => {
console.log("data: ", data);
this.idToken = data;
});
}
});
每隔一小时调用一次。我以为我必须自己实现这个逻辑! https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onIdTokenChanged
来自官方;上面是来自Ionic2 / Angular2,我在dataServiceProvider的构造函数中有这个。
firebase.auth().onIdTokenChanged(function(user) {
if (user) {
// User is signed in or token was refreshed.
}
});