Actions with async metadata/custom claims

We’re using actions to add custom claims to the accessToken and the content of the claims are coming from either an API request or a MySQL query, but the problem is, I believe due to the async nature of the requests they’re not actually getting applied. I’ve got the following:

await runquery(event.user.user_metadata.i_account, async (acl_meta) => {

        console.log(acl_meta);

        if (acl_meta) {

            await api.accessToken.setCustomClaim(`https://metadata.client/acl`, acl_meta);

            return;

        }

    });

    var req = unirest('GET', 'https://jsonplaceholder.typicode.com/todos/1')

    .end(function (res) { 

        if (res.error) throw new Error(res.error); 

        console.log(res.raw_body);

        var json = JSON.parse(res.raw_body)

        api.accessToken.setCustomClaim("https://metadata.client/acls/",json);

        return;

    });

Where runquery is a callback function of a MySQL query, though doing the same in the callback from the MySQL query i.e.:


await connection.query('SELECT bitflag FROM acl_accounts WHERE i_account=' + i_accont, function (error, results, fields) {    
       //ADD CUSTOM CLAIMS HERE
});

Does not work either. I’ve tried with and without await, Anybody got any advice?

Regards,
Joe

1 Like

Hi Joe,
have solved your problem? I think I might get a similar issue.

Best regards,
Greg

1 Like