I have Cloud Endpoints Framework implemented in my App Engine project, and I'd like to migrate from the deprecated API Explorer to the new Endpoints Portal, but I have an authentication issue.
I have one endpoint with authentication enabled with a Google ID token. But when the user clicks on 'Try This API' in the Endpoints Portal, he is not authenticated. This works with the old API Explorer.
I use the project described in this tutorial: https://cloud.google.com/endpoints/docs/frameworks/java/get-started-frameworks-java.
It has API Management has described in the documentation and I followed these steps to authenticate users
I've added the class below to the sample code to test an API with authentication:
package com.example.echo;
import com.google.api.server.spi.auth.common.User;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.response.UnauthorizedException;
@Api(
name = "authenticatedApi",
title = "Authenticated API",
version = "v1",
description = "Use OAuth 2.0 to authenticate",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
clientIds = {"*"}
)
public class AuthenticatedApi {
@ApiMethod(name = "sayHello")
public Message sayHello(User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
Message message = new Message();
message.setMessage("Hello " + user.getEmail());
return message;
}
}
There is a documentation about how configuring the portal for authentication but nothing about OAuth 2.0
I generate and deploy the openapi.json file using the maven plugin and gcloud:
$ mvn endpoints-framework:openApiDocs
$ gcloud endpoints services deploy target/openapi-docs/openapi.json
What am I missing?
That's a current Feature Request for the Google Cloud Endpoints team: