Can I get the access token as a string in a Rule or Action?

I have the following rule…

async function (user, context, callback) {
  const axios = require('axios').default;
  const corp = await getCorp(;
  context.accessToken[`https://.../api/corp`] =corp;
  callback(null, user, context);
  async function getCorp(email){
    const token = `Bearer ${context.accessToken}`;
    console.log(`The token is ${token}`);
    const corpResult = await axios.get(`${configuration.domain}/corporate?email=${email}`, {
      headers: {
        "Authorization": token

But the token isn’t a string it is an object. I know this is because things can still be added but I need a way to use it to call the DB to get additional user info for claims. Is there a way to do this without leaving it open?

Does this lead me to believe this isn’t possible?

I had the m2m account working but because I couldn’t cache it used up my access tokens really quick. Also I would prefer to just delegate the token.

Hi @jgleason

The context.accessToken is the access token you are returning to the user. When you are in the middle of the rules, the access token is not yet complete (the user is not fully authorized). Consider: the next rule in the chain could fail the login, so the partial access token is not valid. But you are trying to use it anyway, So, you need your own M2M access token instead.

You can cache M2M tokens in the rule, using the rule config.


@john.gateley Can you provide an example of how to cache the token in the rule? I tried to use global but it still got reset everytime.

How can I request an M2M access token in an action? Do you have any examples?
Thanks in advance!