How to setup a custom auth?

Hello

I’m trying to add a custom auth provider (because the Keycloak module looks buggy).

But I always have this error:

error: Cannot destructure property 'validator' of 'req.config.authDataManager.getValidatorForProvider(...)' as it is undefined. {"code":141,"stack":"TypeError: Cannot destructure property 'validator' of 'req.config.authDataManager.getValidatorForProvider(...)' as it is undefined.\n at Object.handleAuthDataValidation (/parse-server/lib/Auth.js:540:9)\n at RestWrite.handleAuthData (/parse-server/lib/RestWrite.js:418:20)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"}

I tried running Parse Server both in a Docker container, and directly from source, the result is the same.

I run it with this config file named configuration.json:

{
  "databaseURI": "postgres://parse:password@localhost/parse",
  "appId":"myapp",
  "masterKey":"my_master_key",
  
  "enableAnonymousUsers":false,
  "auth": {
    "myapp": {
      "enabled": true,
      "config": {
        "realm": "myrealm",
        "auth-server-url": "<HOSTNAME WITHOUT PROTOCOL AND PATH",
        "ssl-required": "none",
        "resource": "parse",
        "public-client": true,
        "confidential-port": 0
      }
    }
  }
}

I copied the file src/Adapters/Auth/keycloak.js into myapp.js, and I will adapt it later.

Then I run it using:

PARSE_SERVER_AUTH_PROVIDERS={“myapp”:{“module”:“myapp.js”}} npm start configuration.json

And I make an Http POST to
with the body:

{
  "authData": {
     "myapp": {
    "access_token": "eyJhbG...",
    "id": "pascal",
    "roles": ["default-role"],
    "groups": []
  }
}}

It looks like the file myapp.js is not found, wherever I place it.
Is it the correct interpretation of the error message?
If so, where should it be located?
Otherwise, what am I doing wrong?

in parse configure

auth: {
   sms: {
            module: SMSAuth,
            enabled: true
        }
}

and

export class SMSAuth {
    constructor() {
    }

    validateAuthData(authData) {
        delete authData.code;
//do something
        return Promise.resolve()
    }

    validateAppId() {
        return Promise.resolve();
    }
}

export default SMSAuth
module.exports = SMSAuth

use

Parse.User.logInWith("sms", {
   authData: {
      id: mobileNumber
}
})
1 Like