带有Firebase和改造的Google Cloud Endpoints v2

问题描述:

我想通过用户身份验证来保护我的API方法。最适合Android应用的应用似乎是我正在使用的Firebase身份验证。 现在,如何使用改进或调用验证过的Firebase用户来调用我的API方法。带有Firebase和改造的Google Cloud Endpoints v2

我已经按照从here的例子,并添加下列API方法:

@ApiMethod(
      path = "firebase_user", 
      httpMethod = ApiMethod.HttpMethod.GET, 
      authenticators = {EspAuthenticator.class}, 
      issuerAudiences = {@ApiIssuerAudience(name = "firebase", audiences = {PROJECT_ID})} 
    ) 
    public Translation getUserEmailFirebase(User user) throws UnauthorizedException { 
     if (user == null) { 
      throw new UnauthorizedException("Invalid credentials"); 
     } 
     return new Translation(); 
    } 

现在,那应该怎么叫?我试过

curl \ 
    -H "Authorization: my-firebase-user-token-id" \ 
    https://my-api-link.appspot.com/_ah/api/something/v1/firebase_user 

,但我收到

{ 
    "error": { 
     "errors": [ 
     { 
     "domain": "global", 
     "reason": "required", 
     "message": "Invalid credentials" 
     } 
     ], 
     "code": 401, 
     "message": "Invalid credentials" 
    } 
    } 
+0

来吧。 auth头文件应该是什么样子的?他们没有提到它的文档和API库中的任何地方android是在alpha ... –

使用改装我不得不 @Header("Authorization") String token 添加到API方法PARAM并在代码 "Bearer " + token 作为标记。