升级到 V2 端点后,我使用 @peerAuthenticator 的 API 无法验证对等方。我使用@Authenticator 进行了测试并且遇到了同样的问题,忽略了执行。
我在 GitHub 上创建了一个存储库以使用空应用程序进行测试。
该存储库是通过google 文档的步骤创建的。
运行应用程序后,
mvn appengine:run
您可以请求 3 个端点:- http://localhost:8080/_ah/api/myapi/v1/firstApiMethod(没有任何身份验证)
- http://localhost:8080/_ah/api/myapi/v1/b(带
@authenticator
) - http://localhost:8080/_ah/api/myapi/v1/c(带
@peerAuthenticator
)
API
@Api(name = "myapi", version = "v1") public class YourFirstAPI { @ApiMethod(name = "firstApiMethod", path = "firstApiMethod", httpMethod = HttpMethod.GET) public TestObject a() { return new TestObject(); } @ApiMethod(name = "b", path = "b", httpMethod = HttpMethod.GET, authenticators = {Authenticator.class}) public TestObject b() { return new TestObject(); } @ApiMethod(name = "c", path = "c", httpMethod = HttpMethod.GET, peerAuthenticators = PeerAuthenticator.class) public TestObject c() { return new TestObject(); } }
身份验证器
public class Authenticator implements com.google.api.server.spi.config.Authenticator { @Override public User authenticate(HttpServletRequest arg0) throws ServiceException { throw new ServiceException(401, "unauthorized"); } }
对等身份验证器
public class PeerAuthenticator implements com.google.api.server.spi.config.PeerAuthenticator{ @Override public boolean authenticate(HttpServletRequest arg0) { // TODO Auto-generated method stub return true; } }
有没有人有同样的问题?有什么解决方案吗?