Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140676

Assigning user roles in a rule

$
0
0

I have auth0 connected to a database in mongodb, I already did the login process from auth0 to my database, but I have a problem, the user created it in my database and until he logs in it doesn’t matter to auth0, so I can’t assign him the role until he exists in auth0, my idea is to create a rule that when the user logs in for the first time that auth0 matters it will fire a rule that assigns him the role, which comes in the data of mongo db, I appreciate your help

function (user, context, callback) {
        const axios = require('axios');
      function getAccessToken() {
        return axios.post(
          "https://" + auth0.domain + "/oauth/token",
          {
            grant_type: "client_credentials",
            client_id: configuration.MGMT_API_ID,
            client_secret: configuration.MGMT_API_SECRET,
            audience: "https://" + auth0.domain + "/api/v2/"
          },
          { headers: { "content-type": "application/json" } }
        );
      }

      function assignRole(userId, roleId, accessToken) {
        return axios.post(
          `https://${auth0.domain}/api/v2/users/${userId}/roles`,
          { roles: [roleId] },
          {
            headers: {
              "cache-control": "no-cache",
              authorization: `Bearer ${accessToken}`,
              "content-type": "application/json"
            }
          }
        );
      }

    }

Viewing all articles
Browse latest Browse all 140676

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>