Trigger azure function on user registration in b2c
Asked Answered
T

2

5

I want to trigger a function when a user registers in my azure AD B2C. But I can't find any examples on this. Is the user added to any queue or stored in any table? Or do I need to look at the respons back when the user clicks the "register" button in my app?

I followed this guide to create my B2C. What I want is to eg. send a welcome mail.

Tullus answered 24/2, 2018 at 11:26 Comment(1)
B2C gives you newUser: true in the claims if you configure it to include it. Maybe you could receive that in your app and send the email from there?Secondguess
E
9

Azure AD B2C does not have any support for custom emails events or custom triggers through its built-in policies.

However, you can use Azure AD B2C custom policies to call out to a REST API that sends an email as part of the authentication flow. You can easily implement this REST API using an Http Triggered Azure Function.

Check out the sample code for such Azure function in the sample SendMailWebHook function.

You can also request support for custom email events in the Azure AD B2C feedback forum

Excrete answered 26/2, 2018 at 6:49 Comment(1)
i tried to understand this but ended up with those xml files and referencing errors to something and so on... :( I just want to trigger an azure function when a user signs up or logs in.. are there any tutorials on this? (i already have a working built-in sign_in_up poilcy i want to modify)Stack
E
0

Azure AD B2C provides an in-built user attribute called 'User is new'. You can leverage this attribute to trigger specific actions, like sending a welcome email, upon user registration.

To achieve this:

  1. Enable 'User is new' attribute in your application claims:

    • In your Azure AD B2C policy, include the 'User is new' attribute in the claims that your application receives. This attribute will be set to true for new user registrations and can be utilized as a signal for triggering actions.
  2. Set up an API Connector:

    • You can use an API Connector in your B2C user flow. Specifically, configure the API Connector to be triggered 'Before including application claims in the token'. This step ensures that your custom logic (such as sending a welcome email) runs during user registration.
  3. Use an Azure Function or other APIs:

    • The API Connector can invoke an Azure Function or any custom API to execute further actions. For instance, your Azure Function can send a welcome email, log the registration, or perform other tasks.
    • In your Azure Function, check the 'User is new' claim from the token, and if it’s true, proceed with sending the email.

This approach ensures that your action (such as sending an email) only triggers for new users during their registration.

Endowment answered 1/10, 2024 at 5:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.