Parse Server Custom Auth

#1

I’m trying to use a custom authentication module and having zero success with it. I’m not sure if my configuration is wrong or if there’s a problem somewhere else.

The docs don’t really show a full example of how to create a custom auth other than bits and pieces spread out between the Server guide and the Javascript guide.

I’m sure I’m missing something somewhere, just have no clue what.

From what I can tell, Parse Server isn’t even trying to use my auth module.

Node: 11.9.0
Parse Server: 3.1.3

Here’s the error I’m getting:

    error: This authentication method is unsupported. message=This authentication method is unsupported., stack=Error: This authentication method is unsupported.
        at RestWrite.validateAuthData (/xxxxxxxxxxx/node_modules/parse-server/lib/RestWrite.js:260:9)
        at Promise.resolve.then.then.then.then.then (/xxxxxxxxxxx/node_modules/parse-server/lib/RestWrite.js:91:17)
        at process.internalTickCallback (internal/process/next_tick.js:77:7), code=252

Here’s what I have:

// config
{
   "appId":"xxxxxxxxxxx",
   "appName":"xxxxxxxxxxx",
   "masterKey":"xxxxxxxxxxx",
   "sessionLength":31536000000,
   "databaseURI":"xxxxxxxxxxx",
   "cloud":"xxxxxxxxxxx",
   "serverURL":"xxxxxxxxxxx",
   "publicServerURL":"xxxxxxxxxxx",
   "auth":{
      "myauth":{
         "module":MyAuthModule,
         "option1":"id"
      }
   }
}
// auth module
function validateAuthData(authData) {
    return Promise.resolve();
}

function validateAppId(appIds, authData) {
    return Promise.resolve(); 
}

module.exports = {
    validateAuthData,
    validateAppId,
};
#2

Did you register your provider?

Parse.User._registerAuthenticationProvider(provider);

Here is a test I just wrote.

You are right the docs are lacking

#3

No, didn’t know anything about _registerAuthenticationProvider() I’ll give it a try, thanks!

#4

Improvements have been made in the latest JS SDK release.

A PR for the Docs repo is pending

#5

you also should try on node 10. we don’t support 11 yet and it’d be a pity if you had everything else right but the version of node.

#6

I came across the similar problem about 1 week ago. Without knowing anything about _registerAuthenticationProvider() either, I somehow sorted this thing out, at least user register/login part(with JS SDK in nodejs mode).

IMHO, you server-side setup is correct, including the configuration and authModule code. Please check the client code, especially the parameters you give to user._linkWIth(assuming you are using JS SDK), and see if :

  1. the 1st paramter given to _linkWith, is ‘myauth’, so it matches you server setup;
  2. the 2nd parameter given to _linkWith, is an object like: { authData: {id:‘xxx’}} . Note that the “id” field in authData is implicitly required(I didn’t find this out before getting the same error and looking thru RestWrite.prototype.validateAuthData in parse-server).

so, it should look like

        user = await user._linkWith('myauth', { authData: {
            id: "xxx",
        }}); 

That’s how I figured out. Please correct me if I made anything wrong…

btw, Thank you @dplewis and @acinader, for your generous contribute to this community.

#7

Is the underscore _ not implying that this is an internal private method?

#8

I’d agree… It is kind of weird for _linkWIth being the public interface for linking 3rd party accounts and appearing in official guides like: https://docs.parseplatform.org/js/guide/#linking-1

I guess it is a temporary workaround that should be removed later, any ideas?

#9

Thanks for all the feedback and help. I haven’t had a chance to give any of it a try because I ended up doing a different flow for authenticating with our oauth server and of course, we now don’t have time to revisit it because it’s working and we were able to move on from the issue.

I’ll give it a try when I get some free time myself.

#10

I thought that was the problem at first, I moved down to 10 and it wasn’t working.