I am using the below code for verifying the google id token. It always giving me the below error. But with the same headers i am able to do the verification in POST MAN tool. Please help me to resolve this.
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service =
client.resource("https://www.googleapis.com/oauth2/v3/userinfo");
try {
ClientResponse response = service.header("Authorization",
"Bearer ya29.Glt6BGkbIzLEjeeQ5Q8O51Jh7-PFD3hVLM7PORixSTVFY-
iduKE8HmK8KMtzYz-
yJ9rUqo_xY9yVKl5b6CAiTNAtFErb0bZJB3vX6vPZVRPwbY6kVCIDbukDc9FA")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept",
"Accept=text/html,application/xhtml+xml,
application/xml;q=0.9,*/*;q=0.8").get(ClientResponse.class);
} catch (Exception e) {
e.printStackTrace();
}
Error:
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET https://www.googleapis.com/oauth2/v3/userinfo returned a response status of 401 Unauthorized