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

时间:2017-02-13 03:19:58

标签: google-app-engine authentication firebase-authentication google-cloud-endpoints firebase-security

我正在使用它:

  • 前端与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";
        
        	
        }
&#13;
&#13;
&#13;

  • BackEnd with Google Cloud EndPoint

&#13;
&#13;
@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;
		  }
	  }
&#13;
&#13;
&#13;

  • 使用Firebase进行身份验证

步骤如下:

  • 使用Firebase身份验证登录
  • 在Google Cloud EndPoint中调用java方法,这不会给出麻烦&#34;无效凭据&#34;,这意味着认证
  • 但即使您登录该方法也会出错,
  

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

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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