Google Cloud Endpoints v2 with firebase 和改造
Google Cloud Endpoints v2 with firebase and retrofit
我想通过用户身份验证来保护我的 API 方法。最适合 Android 应用程序的似乎是我正在使用的 firebase 身份验证。
现在,我该如何调用我的 API 方法,使用经过身份验证的 firebase 用户进行改造甚至卷曲。
我遵循了 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"
}
}
使用改造我不得不添加
@Header("Authorization") String token
到 api 方法参数和代码中
"Bearer " + token
作为纪念。
我想通过用户身份验证来保护我的 API 方法。最适合 Android 应用程序的似乎是我正在使用的 firebase 身份验证。 现在,我该如何调用我的 API 方法,使用经过身份验证的 firebase 用户进行改造甚至卷曲。
我遵循了 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"
}
}
使用改造我不得不添加
@Header("Authorization") String token
到 api 方法参数和代码中
"Bearer " + token
作为纪念。