繁体   English   中英

使用Google App Engine中的Firebase进行Google EndPoint身份验证 - HTTP请求中不包含身份验证令牌

[英]Google EndPoint Authentication with Firebase from Google App Engine - No auth token is contained in the HTTP request

我用这个:

  • 前端与谷歌应用引擎(GAE)的JavaScript部分

 <script src="https://www.gstatic.com/firebasejs/3.6.8/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: "XXXXX", authDomain: "id-aplication.firebaseapp.com", databaseURL: "https://id-aplication.firebaseio.com", storageBucket: "id-aplication.appspot.com", messagingSenderId: "00000" }; firebase.initializeApp(config); </script> function init(){ var apiRoot = "//id-aplication.appspot.com/_ah/api"; gapi.client.load('Api', "v1", callback, apiRoot); } function createUserFirebase(){ var user = firebase.auth().currentUser; var request = gapi.client.Api.createUserFirebase(user); request.execute(callBackResponse); } function callback(){ btn = document.getElementById("input_create_user_firebase"); btn.onclick=function(){createUserFirebase();}; btn.value="Click me for Create User Firebase"; } 

  • BackEnd与Google Cloud EndPoint

 @Api(name = "Api", version = "v1", namespace = @ApiNamespace( ownerDomain = "api.example.com", ownerName = "api.example.com", packagePath = "" ), issuers = { @ApiIssuer( name = "firebase", issuer = "https://securetoken.google.com/id-aplication", jwksUri = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com") }, issuerAudiences = { @ApiIssuerAudience(name = "firebase", audiences = "id-aplication")} ) public class SharedRoadApi { @ApiMethod( name = "firebase_user", httpMethod = ApiMethod.HttpMethod.GET, authenticators = {EspAuthenticator.class}, issuerAudiences = {@ApiIssuerAudience(name = "firebase", audiences = {"id-aplication"})} ) public Email firebase_user(User user) throws UnauthorizedException { if (user == null) { throw new UnauthorizedException("Invalid credentials"); } Email response = new Email(); response.setEmail(user.getEmail()); return response; } } 

  • 使用Firebase进行身份验证

步骤是:

  • 使用Firebase身份验证登录
  • 在Google Cloud EndPoint中调用java方法,这不会给Messae“无效凭据”,这意味着验证
  • 但即使你登录该方法给出错误,

com.google.api.server.spi.auth.EspAuthenticator authenticate:身份验证失败:com.google.api.auth.UnauthenticatedException:HTTP请求中不包含身份验证令牌(EspAuthenticator.java:86)

如果有人能告诉我我应该做什么或添加,我将不胜感激,非常感谢。

您需要对客户端进行身份验证:端点服务器期望从客户端进行身份验证,但不会收到任何身份验证。 可以在JavaScript客户端文档中的“ 使用端点”中找到更细粒度的信息,特别是在“使用OAuth 2.0添加身份验证支持”小节中。

对gapi.client.Api.createUserFirebase(用户)的任何引用? 我找不到此方法的任何文档或代码实现。

顺便说一句,由于我没有足够的声誉来添加评论,我们将使用此线程收集更多详细信息以帮助解决此问题。 我们很快就会用一个真正的答案取而代之。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM