[英]How to integrate firebase authentication with google app engine endpoints
我正在为移动应用程序编写后端服务器。 后端在谷歌应用引擎上运行,用Java编写。
我希望用户能够使用Facebook等联合身份登录。
我看到谷歌通过firebase身份验证为移动应用程序支持这种身份验证。 将firebase身份验证与我当前的应用引擎端点集成的最佳方法是什么?
我已经使用了云平台的数据存储区,并且不希望使用firebase数据库,只使用身份验证方法。
谢谢。
我也在寻找答案。 到目前为止,我最好的5c是
@Override
public void init(ServletConfig config) {
try{
InputStream in = config.getServletContext().getResourceAsStream("/WEB-INF/firebase-privatekey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(in)
.setDatabaseUrl("YOUR_DATABASE_URL")
.build();
FirebaseApp.initializeApp(options);
log.info("Authentication enabled");
}
catch(Throwable t) {
t.printStackTrace();
log.warning("AUTHENTICATION DISABLED. Only public resources will be available");
}
}
您应该可以在应用前使用Google Cloud Endpoints作为身份验证代理。 端点支持通过配置OpenAPI模板验证Firebase身份验证令牌 :
# Configure Firebase as an AuthN provider
securityDefinitions:
firebase:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
# Replace YOUR-PROJECT-ID with your project ID in the issuer and audiences fields
x-google-issuer: "https://securetoken.google.com/YOUR-PROJECT-ID"
x-google-audiences: "YOUR-PROJECT-ID"
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
# Add Firebase as an authN provider to specific endpoints...
security:
- firebase: []
或者,您可以使用Firebase Admin SDK编写验证令牌的身份验证中间件:
FirebaseAuth.getInstance().verifyIdToken(idToken)
.addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
@Override
public void onSuccess(FirebaseToken decodedToken) {
String uid = decodedToken.getUid();
// ...
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.