我正在尝试使用Spring Boot验证Google令牌ID。 我一步一步地遵循this link
在
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
// Specify the CLIENT_ID of the app that accesses the backend:
.setAudience(Collections.singletonList(CLIENT_ID))
// Or, if multiple clients access the backend:
//.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
.build();
我在评估人CLIENT_ID
的Google 应用中使用我的客户ID
但是当我添加
GoogleIdToken idToken = verifier.verify("someText");
我遇到以下错误
Caused by: java.lang.IllegalArgumentException: null
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:108) ~[google-http-client-1.24.1.jar:1.24.1]
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:37) ~[google-http-client-1.24.1.jar:1.24.1]
at com.google.api.client.json.webtoken.JsonWebSignature$Parser.parse(JsonWebSignature.java:602) ~[google-http-client-1.24.1.jar:1.24.1]
at com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.parse(GoogleIdToken.java:57) ~[google-api-client-1.24.1.jar:1.24.1]
at com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier.verify(GoogleIdTokenVerifier.java:191) ~[google-api-client-1.24.1.jar:1.24.1]
at org.sid.InwiBoApplication.run(InwiBoApplication.java:59) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:818) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
... 10 common frames omitted
答案 0 :(得分:1)
我不必在 "someText"
GoogleIdToken idToken = verifier.verify("someText");
我必须使用 String ,其中格式与 IdToken格式类似。