【问题标题】:Custom auth (OAuth2) for Parse-server on docker containerdocker 容器上 Parse-server 的自定义身份验证 (OAuth2)
【发布时间】:2019-10-17 12:53:04
【问题描述】:

所以,正如标题所示,我正在寻找一种方法将我自己的自定义身份验证服务集成到解析服务器中,该解析服务器安装在 docker 容器中。这种身份验证基本上是 KeyCloak 的 OpenID 实现。

关键是我没有(我的架构最好不要)在我的本地机器上使用 express 提供解析服务器。

到目前为止,我一直在尝试的是搜索互联网,阅读问题,阅读 JavaScript 的解析服务器文档以及指南和其他东西以找出,我该如何实现它。

似乎我做什么都没关系,在每次测试结束时,我都会收到252 This authentication method is unsupported 错误! (即使我使用facebook、oauth、oauth2 等也会发生这种情况。

所以现在,docker-compose 服务看起来像这样:

    parse-server:
        image: parseplatform/parse-server
        ports:
            - "${SERVER_PORT}:1337"
        restart: "always"
        volumes:
            - ./server/parse/custom-auth:/parse-server/custom-auth
        depends_on: 
            - mongodb
        links:
            - mongodb:mongo
        environment:
            - PARSE_SERVER_APPLICATION_ID=${APP_ID}
            - PARSE_SERVER_MASTER_KEY=${MASTER_KEY}
            - PARSE_SERVER_DATABASE_URI=mongodb://mongo:${MONGO_PORT}/dev
            - PARSE_SERVER_START_LIVE_QUERY_SERVER=1
            - PARSE_SERVER_LIVE_QUERY={"classNames":${LIVE_QUERY_CLASSES}}
            - PARSE_SERVER_MOUNT_GRAPHQL=${GQL_API}
            - PARSE_SERVER_MOUNT_PLAYGROUND=${GQL_PLAYGROUND}
            - PARSE_SERVER_AUTH_PROVIDERS={"swwwan-mail-auth":{"module":"/parse-server/custom-auth/swwwan-mail-auth/index.js"}}

以及登录/注册部分:

export const loginWithParse = async (account: IUserColumnTypes) => {
    if (account.username === null || account.password === null) {
        throw "validation failed";
    }

    // @ts-ignore
    const loggedIn = await Parse.User.logInWith("swwwan.mail-auth", {
        authData: {
            id: "",
            access_token: "",
        },
    });

    console.log({ loggedIn });

    //return await Parse.User.logIn(account.username, account.password);
};

登录/注册的另一种选择:

export const loginWithParse = async (account: IUserColumnTypes) => {
    if (account.username === null || account.password === null) {
        throw "validation failed";
    }

    const u = new Parse.User();

    u._linkWith("swwwan-mail-auth", {
        authData: {
            id: "tester",
            access_token: "sample_access_token",
        },
    })
    .then(res => console.log(res))
    .catch(e => console.log(e));

    //return await Parse.User.logIn(account.username, account.password);
};

更新:通过使用第二种选择,我实际上得到了错误:

error: Parse error: Invalid key name: authData.swwwan-mail-auth.id {"code":105,"stack":"Error: Invalid key name: authData.swwwan-mail-auth.id

有没有办法让它工作?可能我在这里遗漏了一些东西。

tnx :)

【问题讨论】:

    标签: javascript docker parse-platform docker-compose parse-server


    【解决方案1】:
    1. 请注意,链接函数中的“dangle”将在 Parse JS SDK 即将发布的2.9 release 中被弃用

    2. 很抱歉,文档还不够好。将得到更多的工作

    3. 你的尝试是可行的!

    4. 您的最后一个错误给出了一个重要线索:您的适配器名称不能包含任何对 javascript 标识符无效的字符。在这种情况下,- 引起了问题,因为当我们将其保存在数据库中时,适配器名称被用作键。

    单元测试通常是最好的文档,在这种情况下您可能会发现它们很有帮助。

    见:

    【讨论】:

      猜你喜欢
      • 2016-10-30
      • 2015-04-27
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      • 2022-12-10
      • 2012-01-03
      相关资源
      最近更新 更多