Auth0: passing custom fields in getAccessTokenSilently in order to be used in rules

We are using Auth0 SDK and trying to include a custom option to rule/access-token after login. The purpose is to be able to inject dynamic params into payload from rules. Client is a react.js app and we use @auth0/auth0-react library. Noticed that getAccessTokenSilently is extensible to include custom params:

const { getAccessTokenSilently } = useAuth0();
const accessToken = await getAccessTokenSilently({
        audience: 'myaudience',
        scope: 'read:read_users',
        'foo': 'bar'
    });

The question is, how do we get access to foo=bar from inside the rules? Thanks

P.S: solution this could not help solve our problem.

Hi @sharbel.shuker,

Welcome to the Auth0 Community!

You should be able to see the request params in the context.request.query object.

Are you not seeing them in your rule?

Hi @dan.woda
no, unfortunately, I can not see these variables in the rules.
only if this variable is specified within the Auth0Provider.
is it possible to pass it while requesting a token?

Hi @sharbel.shuker,

After some testing, I can’t seem to get them to show up either. Let me reach out to our team and see if I can get to the bottom of it. I’ll report back when I have an answer.

Hi @dan.woda ,

That would be great, many thanks in advance :slight_smile:

Hey @dan.woda , what was the outcome of your investigations?

I’m facing the same issue - custom params passed to getAccessTokenSilently function are not appearing in the context.request.query…

I’m using version 1.12.0 of @auth0/auth0-react
And version 1.21.1 of @auth0/auth0-spa-js

Thanks

@richlee
for me, i am using “@auth0/auth0-react”: “^1.8.0”,
adding ignoreCache: true as follow should work
getAccessTokenSilently({
ignoreCache: true,
‘foo’: ‘bar’
})

1 Like

Thanks for sharing your solution @sharbel.shuker

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