Java 在云端点和API Explorer上对用户进行身份验证(同时使用Firebase和Google身份验证)

Java 在云端点和API Explorer上对用户进行身份验证(同时使用Firebase和Google身份验证),java,google-app-engine,firebase-authentication,google-cloud-endpoints,google-authentication,Java,Google App Engine,Firebase Authentication,Google Cloud Endpoints,Google Authentication,使用AppEngine的云端点框架,除了使用Google帐户进行身份验证外,我还添加了使用Firebase Auth进行身份验证 一切都很好,我可以使用Firebase Auth授权客户端请求,但现在我不能再使用API Explorer了,因为它使用Google的身份验证并导致401无效凭据响应 我通过以下操作添加了Firebase Auth: @原料药 名称=测试, 版本=v1, //验证器={EspAuthenticator.class}, 发行人={ @蜂鸟 name=firebase,

使用AppEngine的云端点框架,除了使用Google帐户进行身份验证外,我还添加了使用Firebase Auth进行身份验证

一切都很好,我可以使用Firebase Auth授权客户端请求,但现在我不能再使用API Explorer了,因为它使用Google的身份验证并导致401无效凭据响应

我通过以下操作添加了Firebase Auth:

@原料药 名称=测试, 版本=v1, //验证器={EspAuthenticator.class}, 发行人={ @蜂鸟 name=firebase, 发行人=https://securetoken.google.com/PROJECT-ID, jwksUri=https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com }, issuerAudiences={ @APIssuserAudienceName=firebase,受众=PROJECT-ID }, scopes={Constants.EMAIL_SCOPE}, clientId={Constants.WEB_CLIENT_ID,Constants.ANDROID_CLIENT_ID,Constants.IOS_CLIENT_ID,Constants.API_EXPLORER}, 观众={Constants.ANDROID_观众}, namespace=@ApiNamespaceownerDomain=XXX,ownerName=XXX,packagePath= 使用Google身份验证和API Explorer的方法是:

在API Explorer上使用Firebase Auth但不使用OAuth 2.0的方法是:

此代码段似乎建议EspAuthenticator.class应与Google身份验证一起使用:

但是,只要将EspAuthenticator.class设置为验证器,API Explorer请求就会失败,并出现401无效凭据响应

我有没有办法让Google和Firebase认证在同一种方法上工作?这两种方法之间的唯一区别是EspAuthenticator.class,根据上面链接中的官方代码片段,谷歌身份验证似乎仍然可以与EspAuthenticator.class身份验证程序一起使用

更新: 我从Stackdriver得到的错误是:

com.google.api.server.spi.auth.EspAuthenticator身份验证: 身份验证失败: com.google.common.util.concurrent.UncheckedExecutionException: com.google.api.auth.unauthenticated异常: org.jose4j.jwt.consumer.InvalidJwtException:无法处理JOSE 对象原因:org.jose4j.lang.JoseException:无效 序列化。JWS或JWE需要3或5个部件 但分别为2: ya29.GMAKBDWFSFYOCL7KQSLELSHPOB9LJLYEEWTPFPEH1A4T12I8MmZHBNLIMER9DATOSARG2O-QlZEHisfEPYbA-Wb-Eh36zugIufmVbDe4E2TP9StAOjub8nsrhAzuGbolE EspAuthenticator.java:86

这里还提出了一个问题:

您应该添加GoogleOAuth2Authenticator或EndpointsAuthenticator

EndpointsAuthenticator是GoogleJwtAuthenticator、GoogleAppEngineAuthenticator、GoogleOAuth2Authenticator的包装

你的authenticators参数应该是

authenticators = {EspAuthenticator.class, GoogleOAuth2Authenticator.class},

更简单的是,你需要通行证才能通行

一旦您拥有firebase令牌,您就必须使用EspAuthenticator.class方法进行身份验证

下面是使用firebase令牌的身份验证

验证JSON WEB令牌Firebase用户
哇,我没想到会有人通过,但它成功了!对于一个没有任何帖子但已经成为会员3年的用户来说,你就像我的守护天使。谢谢你,我绝对不认为这对我来说是件容易的事。对于使用GoogleOAuth2Authenticator进行身份验证的请求,我显然仍然从EspAuthenticator获得了上面发布的相同警告日志。有办法吗?还有,您知道上的示例代码如何使用EspAuthenticator进行Google身份验证吗?EspAuthenticator仅适用于JWT令牌。出现警告是因为EspAuthenticator不验证令牌类型并尝试将OAuth令牌解析为JWT令牌,但GoogleOAuth2Authenticator执行此检查。要避免警告,只需更改验证器顺序验证器={GoogleOAuth2Authenticator.class,EspAuthenticator.class}
@ApiMethod(
        authenticators = {EspAuthenticator.class}
)
public User getTestUserFirebase(User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException("Invalid credentials");
    }

    return user;
}
authenticators = {EspAuthenticator.class, GoogleOAuth2Authenticator.class},
curl \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer ${firebase_token}" \
 -X GET \
 "https://$PROJECT_ID.appspot.com/_ah/api/echo/v1/firebase_user"