I am using this :
<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"; }
@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; } }
The steps are:
com.google.api.server.spi.auth.EspAuthenticator authenticate: Authentication failed: com.google.api.auth.UnauthenticatedException: No auth token is contained in the HTTP request (EspAuthenticator.java:86)
I would appreciate it if anyone can tell me what I should do specifically or add, thank you very much.
You need to authenticate the client: the endpoints server is expecting authentication from the client, but receives none. More fine-grained information is to be found in the Using Endpoints in a JavaScript Client document, specifically in the subsection “Adding authentication support with OAuth 2.0”.
any reference to gapi.client.Api.createUserFirebase(user)? I couldn't find any document or code implementation of this method.
BTW, since I don't have enough reputations to add a comment, we will use this thread to collect more details to help troubleshoot this issue. We will replace this with a real answer soon.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.