Rule migration to Actions

I set up a rule some time ago to retrieve email from Twitter.

I’ve now been advised to migrate to Actions.

From what I’ve seen this is not a simple copy and paste and I can’t find an example.

Surely this is not up to each and everyone to develop their own action from scratch?

The only “scaffolding” is

exports.onExecutePostLogin = async (event, api) => {
};

This is the original rule

function (user, context, callback) {
  // additional request below is specific to Twitter
  if (context.connectionStrategy !== 'twitter') {
    return callback(null, user, context);
  }

  const oauth = require('oauth-sign');
  const uuid = require('uuid');

  const url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
  const consumerKey = 'xxx';
  const consumerSecretKey = 'xxx;

  const twitterIdentity = _.find(user.identities, { connection: 'twitter' });
  const oauthToken = twitterIdentity.access_token;
  const oauthTokenSecret = twitterIdentity.access_token_secret;

  const timestamp = Date.now() / 1000;
  const nonce = uuid.v4().replace(/-/g, '');

  const params = {
    include_email: true,
    oauth_consumer_key: consumerKey,
    oauth_nonce: nonce,
    oauth_signature_method: 'HMAC-SHA1',
    oauth_timestamp: timestamp,
    oauth_token: oauthToken,
    oauth_version: '1.0'
  };

  params.oauth_signature = oauth.hmacsign('GET', url, params, consumerSecretKey, oauthTokenSecret);

  const auth = Object.keys(params).sort().map(function (k) {
    return k + '="' + oauth.rfc3986(params[k]) + '"';
  }).join(', ');

  request.get(url + '?include_email=true', {
    headers: {
      'Authorization': 'OAuth ' + auth
    },
    json: true
  }, (err, resp, body) => {
    if (resp.statusCode !== 200) {
      return callback(new Error('Error retrieving email from twitter: ' + body || err));
    }
    user.email = body.email;
    return callback(err, user, context);
  });
}

Hi @CueToDo,

Welcome to the Auth0 Community!

I understand that you have a Retrieve email from Twitter Rule and have questions regarding migrating to Actions.

Currently, there are no equivalent templates in Actions, as you see with the Rules templates. However, we anticipate Action Templates to be available as no-code integrations for your development in the future.

For now, Auth0 will continue to offer support to Rules until the end of 2022, by which time, Rules will have reached its end of life, and you will need to migrate fully into Actions.

Because of this, I recommend waiting until the Action Templates become available and migrate over without any friction.

However, if you decide to develop a Custom Action based on similar logic, I recommend checking out our Post-login Action Triggers documentation.

Please let me know if you have any questions. I would be happy to clarify.

1 Like

Thanks Rueben, that’s great news, I’m happy to continue using the rule and wait for the Action Templates to become available.

Alex

1 Like

That’s great to hear @CueToDo!

Have a great rest of your day.

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

Hi @CueToDo
I wanted to chime in and just mention that this will also help in transitioning from Rules to Actions https://auth0.com/docs/actions/programming-model-changes

Have a great holiday season.
Regards

1 Like

Thanks a lot for sharing that Saqib!

We now have an official guide to migrating from Rules to Actions!

2 Likes