Search code examples
javascriptdockerparse-platformdocker-composeparse-server

Custom auth (OAuth2) for Parse-server on docker container


So, as the title suggests, I'm looking for a way to integrate my own custom authentication service into the parse server, which is installed inside a docker container. This authentication is basically an OpenID implementation of KeyCloak.

The point is that I don't (and it would be best for my architecture not to) have parse server served with express on my local machine.

What I've been trying so far, was to search the internet, read the issues, read the parse server documents for JavaScript and the guide and other stuff to find out, how can I achieve it.

It seems that it doesn't matter what I do, at the end of each test, I get a 252 This authentication method is unsupported error! (this happens even if I use facebook, oauth, oauth2, etc).

So right now, the docker-compose service looks like this:

    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"}}

and the login/signup part:

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

another alternative for login/signup:

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

UPDATE: by using the second alternative, I actually get the error:

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

Is there a way to make it work? probably I'm missing something here.

tnx :)


Solution

    1. note that the 'dangle' in the link functions will be deprecated in the forthcoming 2.9 release of the Parse JS SDK

    2. Sorry that the documentation isn't better yet. Will be getting some more work

    3. What you're attempting is doable!

    4. Your final error is giving one big clue: the name of your adapter can't have any characters that aren't valid for a javascript identifier. In this case, the - is causing a problem since when we save it in the database, the adapter name is used as a key.

    The unit tests are often the best documentation and you may find them helpful in this case.

    See: