Auth0 Rules: access to access token from inside Rule code

I need to use the user access token to access a third party API in the rule snippet. Is this possible?

Hey there @zaid.huda!

It should be as you can access Context object property access_token using rules syntax. Here’s more on that:

Let me know if you have any more questions down the road!

I tried context.access_token and context.accessToken. Their values are undefined and the token object respectively. I needed the actual access token to be used as Bearer token to access the 3rd party API.

Any luck getting a context.accessToken?

1 Like

Negative. Can’t get it to work

Zaid,

I got it working! An Auth0 rule that acts on first time sign in user. It makes an API call to get a machine to machine token. It uses the token to call my API so it can register the new user in our database.

I found this example that was a big help in getting the Rule to work.

https://github.com/auth0/rules/blob/master/src/rules/parse.js

Ignore the context.access_token. You need to create your own. Make sure you use the client_id, client_secret and audience of your machine to machine definition.

Good luck.

David

2 Likes

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