如何将Firebase身份验证与Google应用程序引擎终结点集成 [英] How to integrate firebase authentication with google app engine endpoints

查看:147
本文介绍了如何将Firebase身份验证与Google应用程序引擎终结点集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为移动应用程序编写一个后端服务器。
后端在谷歌应用程序引擎上运行,并以Java编写。



我希望用户能够以facebook等联合身份登录。



我看到Google支持通过Firebase身份验证为移动应用程序进行这种身份验证。将firebase身份验证与我当前的应用程序引擎端点集成的最佳方式是什么?



我已经使用云平台的数据存储,不希望使用Firebase数据库,只使用认证方法。



谢谢。

解决方案

我也在寻找答案。到目前为止,我的最好的5c是


  • 使用FireBase从控制台设置登录方法等。
  • 使用适用于Web的iOS联合身份验证提供程序集成的FireBase UI(用于测试版)以设置身份验证流程

  • 在您的Web / iOS上回收令牌/身份验证详细信息/ Android客户端,并将其传递到您的云终端,例如HTTP请求头

  • 将javax.servlet.http.HttpServletRequest注入您的端点方法(只需添加一个参数,请求对象自动)
  • 创建一个端点将调用每个请求(需要身份验证)的方法,该方法将处理您作为HTTP请求头传递的凭据的验证
  • li>
  • 使用FireBase Java SDK调用FireBase验证凭据(为此,需要从Firebase控制台导出json配置),并使用它们加载SDK,例如,你的服务器



    $ b $ p $ @覆盖
    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(启用身份验证);

    catch(Throwable t){
    t.printStackTrace();
    log.warning(AUTHENTICATION DISABLED。只有公共资源可用);
    }
    }


    I am writing a backend server for mobile applications. The backend is running on google app engine and written in Java.

    I want users to be able to login with federated identity such as facebook.

    I saw that google supports this kind of authentication for mobile apps via firebase authentication. What would be the best way to integrate firebase authentication with my current app engine endpoints?

    I already use the cloud platform's datastore and don't wish to work with the firebase database, only use the authentication method.

    Thanks.

    解决方案

    I'm also looking for an answer to this. My best 5c so far is to

    • Use FireBase to set up sign in methods etc. from the console
    • Use FireBase UI (in beta) for web or "Federated identity provider integration" for iOS/Android to set up the authentication flow
    • Retrive token/authentication details on your web/iOS/Android client and pass it on to your Cloud Endpoints as e.g., HTTP Request Headers
    • Inject the javax.servlet.http.HttpServletRequest to your endpoint methods (just add an argument and Google with inject the request object automatically)
    • Create a method that your Endpoint will call for each request (that needs authentication) that will handle the validation of the credentials you have passed on as HTTP Request Headers
    • Use FireBase Java SDK to call FireBase to validate the credentials (in order to do this, you need to export the json configuration from the Firebase console) and load the SDK with them, e.g., in one of your servlets:

    @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");
            }
        }
    

    这篇关于如何将Firebase身份验证与Google应用程序引擎终结点集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆