[英]Google Cloud Endpoints v2 with firebase and retrofit
I want to protect my API methods with user authentication. 我想通过用户身份验证来保护我的API方法。 The best fit for Android app seemed to be a firebase authentication, which I'm using. 最适合Android应用的似乎是我正在使用的firebase身份验证。 Now, how do I call my API methods using retrofit or even curl with authenticated firebase user. 现在,我该如何使用经过身份验证的Firebase用户进行改造甚至卷曲来调用我的API方法。
I've followed the example from here and added following API method: 我从这里开始遵循示例,并添加了以下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();
}
Now, how it should be called? 现在,应该如何称呼它? I've tried 我试过了
curl \
-H "Authorization: my-firebase-user-token-id" \
https://my-api-link.appspot.com/_ah/api/something/v1/firebase_user
but I receive 但我收到
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Invalid credentials"
}
],
"code": 401,
"message": "Invalid credentials"
}
}
使用改造,我必须将@Header("Authorization") String token
到api方法参数中,并在代码"Bearer " + token
为令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.