Device Flow: modify a returned claim in the login flow using a custom action

I’m using a device flow scenario to execute some migrations. Those migrations are executed by a given user and the user info is getting stamped on the migrated data. What I’d like to do is to augment one of the user claims, name, to include the fact that it was a device flow/migration. I cannot find any information on how to do that using custom actions. The only sample I’ve seen was using legacy rules that are a) discouraged and b) couldn’t get it working (no IntelliSense to get an idea what’s available on those objects passed in). Is there a way to achieve what I’m looking for that is documented?

Hi @sean.feldman,

Thanks for reaching out to the Auth0 Community.

First, could you please share the samples you found showing how to do this with Rules?

I’d like to take a look and see if it can be implemented in an Action script.

Thank you.

Hi @rueben.tiow,

The documentation for an Auth0 Application setup, under Device Authorization Flow

Hi @sean.feldman,

Thank you for your response.

To accomplish a Device Authorization Flow using Actions, you can implement the following in a Post-Login Action script:

exports.onExecutePostLogin = async (event, api) => {
  if (event.transaction.protocol === 'oauth2-device-code') {
    ...
  }
}

You may also find the Post-Login Event Object and API Object documentation useful.

Please let me know if there’s anything else I can do to help.

Thank you.

@rueben.tiow, thank you so much for digging this information up. I’ll definitely try it out, and if not commenting back then, I’ve had great success, as Borat would say.

Appreciate your help. Any chance this could be added to the documentation when enabling device flow to replace the outdated docs/references?

1 Like

Hi @sean.feldman,

Thank you for your response!

Yes! The Action script sample code will be added to our documentation as we get closer to the end of life of Rules. At that point, all of our documentation will be include examples using Actions instead of Rules.

Please let me know if there are any other questions or concerns.

Thank you.

And it worked. Thank you so much :slightly_smiling_face:

1 Like

Hi @sean.feldman,

I’m happy to hear that it works!

Please don’t hesitate to let me know if there’s anything else I can do to assist.

Thank you.

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