# Access user.oid from Action

**URL:** <https://community.auth0.com/t/access-user-oid-from-action/75253>\
**Category:** Get Help\
**Tags:** azure-ad\
**Created:** [December 21, 2021, 2:14am UTC](https://community.auth0.com/t/access-user-oid-from-action/75253 "2021-12-21T02:14:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![developer14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/developer14/32/30398_2.png) [@developer14](https://community.auth0.com/u/developer14)\
**Post date:** [December 21, 2021, 2:14am UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/1 "2021-12-21T02:14:46Z")

</div>

Hi, I was wondering if it is possible to access the user.oid from within an action login flow.  
I can access the user.oid if I use rules, but as it’s deprecated I’m trying to migrate it to actions, I’m authenticating against an Azure AD.

using rules I can do this  
context.accessToken[‘my\_claim’] = user.oid;

How could I do the same thing using actions?

thanks

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 21, 2021, 8:39pm UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/3 "2021-12-21T20:39:07Z")

</div>

Hi @developer14,

Thanks for reaching out to the Auth0 Community!

I am not sure about the `user.oid` in Actions since this attribute is not in our documentation, but it may be worth trying the `event.user.oid` property in Actions and seeing if that works in retrieving the previously called user.oid information. See below:

```auto
/**
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
 */
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.accessToken.setCustomClaim(`${namespace}/user_oid`, event.user.oid);
  }
}

```

You may find [this example Action use case for adding roles to claims](https://auth0.com/docs/actions/triggers/post-login#add-user-roles-to-id-and-access-tokens) helpful.

Please let me know how this works for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![developer14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/developer14/32/30398_2.png) [@developer14](https://community.auth0.com/u/developer14)\
**Post date:** [December 22, 2021, 12:39am UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/4 "2021-12-22T00:39:06Z")

</div>

> [@rueben.tiow](#):
>
> ```auto
> exports.onExecutePostLogin = async (event, api) => {
> const namespace = 'https://my-app.example.com';
> if (event.authorization) {
> api.accessToken.setCustomClaim(`${namespace}/user_oid`, event.user.oid);
> }
> 
> ```

Hi Rueben,  
thank you for your help!!!  
the solution you’ve suggested was the first thing I’ve tried to do, however when I write ''event.user.oid", the environment shows an erros saying

```auto
"Property 'oid' does not exist on type 'User & { multifactor?: string[] | undefined; } & { identities: UserIdentity[]; }'.(2339)".

```

That’s why Im not using it. Also, even if I try to use it, it doesn’t bring anything.

When I use rules I can have something like this

```auto
function activeDirectoryGroups(user, context, callback) {
  
  context.accessToken[`my_namespace/user_oid`] = user.oid;

  callback(null, user, context);
}

```

and it works, I just don’t know how to do the same with actions.

thanks.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 6, 2022, 12:40am UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/5 "2022-01-06T00:40:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 12, 2022, 4:27pm UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/6 "2022-01-12T16:27:07Z")

</div>



---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 12, 2022, 6:37pm UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/7 "2022-01-12T18:37:10Z")

</div>

Hi @developer14,

Thank you for your response and for testing this for me.

In this scenario, I recommend that you continue using Rules to append the user\_oid as a custom claim.

I understand that there have been warnings and notifications about migrating from Rules to Action, but I can confirm that all of the features in Rules will be available in Actions as we get closer to the end of life of Rules.

Please let me know if you have any further questions.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 27, 2022, 6:37pm UTC](https://community.auth0.com/t/access-user-oid-from-action/75253/8 "2022-01-27T18:37:43Z")

</div>

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