簡體   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