Access Denied after Adding/Removing a Rule. Trying to enable user_metadata/app_metadata on idToken

In an attempt to fix user_metadata and app_metadata not returning on the idToken response, I followed the advice of this thread to create a rule like this:

   var namespace = 'https://my-domain.my-company.com/';
   if (context.idToken && user.user_metadata) {
     context.idToken[namespace + 'user_metadata'] = user.user_metadata;
   }
   if (context.idToken && user.app_metadata) {
     context.idToken[namespace + 'app_metadata'] = user.app_metadata;
   }
   callback(null, user, context);
 }```

Which did nothing to solve the original problem. So I removed the new rule, and ever since then (no front-end changes) I have been getting this access_denied error:

![image|639x500](upload://3MrCx3plwmXtxnNTTC7Vb9Jb12U.png)

So the main issue is the access error, and if that gets solved I'll still need help getting user_metadata and app_metadata to show up.

Image upload isn’t working apparently. The error block:
Uncaught (in promise)
{
error: “access_denied”,
errorDescription: “connection to undefined:1433 - failed Error: connect ECONNREFUSED 127.0.0.1:1433”,
state: “8b30N5cH34~Bhp4aGvpa1nCP.kaY4ffu”
}

Hello @ngInit,

Welcome to the Community!

Port 1433 is usually Microsoft SQL Server. Do you have an SQL Server custom database set up? And where is that error being logged? In Auth0? App logs?

For when we get the ECONNREFUSED error solved: Here’s a super basic rule that adds all of user_metadata to the idToken (there are probably better ways to code this … I’m not a dev and far more of a python guy):

From the user profile:

    "user_metadata": {
        "foo": "bar",
        "baz": [
            "fizbin",
            "gandalf",
            "raistlin"
        ]
    },
    "app_metadata": {}

The resulting idToken:

  "accessToken": {},
  "idToken": {
    "https://leanangle.io/claims/user_metadata": {
      "foo": "bar",
      "baz": [
        "fizbin",
        "gandalf",
        "raistlin"
      ]
    }

(looks like your image upload is inside a code block maybe? That might be why it didn’t work.)

The error is being logged in the Javascript console after the Auth0 Universal Login finishes and redirects back to our Vue SPA. This is the redirect URL:

http://localhost:8080/callback#error=access_denied&error_description=connection%20to%20undefined%3A1433%20-%20failed%20Error%3A%20connect%20ECONNREFUSED%20127.0.0.1%3A1433&state=8b30N5cH34~Bhp4aGvpa1nCP.kaY4ffu

This was all working correctly before I started adding new rules, which is why I thought that might’ve been the problem. But after deleting my Rule & Hook changes in Auth0 the error persists.

As for the Microsoft SQL Server, I’m not sure how our databases are currently hooked up (I’ll have to ask someone who knows on Monday). I was able to go into the Connections > Database tab, where we have the single Database Connection. Hitting “Try Connection” on this page gets me the same error as my app, so I don’t think it’s a front-end issue.

(and yeah, looks like the code block didn’t close correctly)

Sounds like you might be using a custom (external) database, and the DB is offline. Mind you, the error is pointing to localhost which wouldn’t gel with using a custom external DB. In that database connection, is “Use my own database” enabled? If so, you should be able to look at the custom DB scripts on the page to see what DB you are using. Once we get that worked out, I’d be happy to help with the rule.

No, that option isn’t enabled. And this is our only Database connection. So based on what I’m reading above that option, that means Auth0 has been hosting our Database, and it was probably already imported before I started looking into it.

Ok, that makes sense. See if you can find out what the app might be talking to locally on 1433. Probably a SQL Server instance that is down. Do you have access to the code? Can you search it for ‘1433’?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.