We have two simple rules that run on all our tenants when a user logs in. However, since AUTH-PIPELINE-RULES is not available in the newly created tenants, I want to know how I can convert them into custom action and achieve the same function. I have tried reading the documentation, but I still can’t grasp it. I hope someone can provide me with some assistance.
Rule # 1
function (user, context, callback) {
const namespace = ‘https://myapp.com/ ’;
context.accessToken[namespace + ‘email’] = user.email;
callback(null, user, context);
}
Rule #2
The value configuration.intercom_key is defined under the rules as an encrypted key object currently on AUTH0 old tenant.
function (user, context, callback) {
const namespace = ‘https://myapp.com/ ’;
const crypto = require(‘crypto’);
const hmac = crypto.createHmac(‘sha256’, configuration.intercom_key);
hmac.update(user.email);
const hash = hmac.digest(‘hex’);
context.idToken[namespace + ‘intercom_hash’] = hash;
context.accessToken[namespace + ‘intercom_hash’] = hash;
callback(null, user, context);
}
Thanks in advance!
tyf
December 12, 2023, 1:36am
3
Hey there @raymond.lee !
You’ll want to test these thoroughly, but I’ve converted these to Actions you can go off of:
Action # 1
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.com/';
api.accessToken.setCustomClaim(namespace + 'email', event.user.email);
};
Action # 2
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.com/';
const crypto = require('crypto');
const hmac = crypto.createHmac('sha256', event.secrets.intercom_key);
hmac.update(event.user.email);
const hash = hmac.digest('hex');
api.idToken.setCustomClaim(namespace + 'intercom_hash', hash);
api.accessToken.setCustomClaim(namespace + 'intercom_hash', hash);
};
A couple things to note with Action # 2 is that I have added intercom
to event.secrets and had to suppress errors associated with passing event.user.email
to hmac.update()
- These were just in relation to event.user.email
potentially being undefined
.
2 Likes
Hi tyf, Thanks for your help and definitely will try it out.
1 Like
tyf
December 12, 2023, 4:11pm
5
No problem @raymond.lee happy to help! Keep us posted
Hi Tyf,
It works like a charm after I added those two new create actions inside the FLOWS - LOGIN. I missed that at the beginning.
Thank you so much for your help; it’s greatly appreciated!!!
1 Like
tyf
December 12, 2023, 9:56pm
7
That’s great news - Happy to help!
system
Closed
December 26, 2023, 9:56pm
8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.