[英]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.