首页 文章

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

提问于
浏览
4

我用这个:

  • 前端与Google App Engine(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 "Invalid credentials",这意味着验证

  • 但即使你登录方法给出错误,

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

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

2 回答

  • 1

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

  • 0

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

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

相关问题