How to implement social login using Azure AD B2C in Node.js with Axios

Sridhar Renganathan 0 Reputation points
2023-11-08T06:19:06.23+00:00

I am trying to implement social login (Google, Facebook) using Azure AD B2C in Node.js and Angular. I have already configured the client ID and client secret in Azure and created a user flow. However, I'm having trouble finding documentation on how to integrate this in Node.js and Angular to store user information in a database and call the Azure social login API for registration and login. Can someone provide me with a sample using Axios in Node.js?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,426 Reputation points Microsoft Employee Moderator
    2023-11-22T07:35:54.8466667+00:00

    Hi @Sridhar Renganathan ,

    Thanks for reaching out.

    To configure any social idP in your Azure AD B2C application, require you to create userflow or custom policy that you want to use for social login.

    You can create user flow/custom policy to setup Google IdP as mentioned here https://learn.microsoft.com/en-us/azure/active-directory-b2c/identity-provider-google?pivots=b2c-user-flow

    Facebook Idp - https://learn.microsoft.com/en-us/azure/active-directory-b2c/identity-provider-facebook?pivots=b2c-user-flow

    Then you can configure authentication in Node.js by passing user flow/custom policy in the configration file in node sample which automatically allow social idp on signup/sign in page.

    
    
    SIGN_UP_SIGN_IN_POLICY_AUTHORITY=https://<your-tenant-name>.b2clogin.com/<your-tenant-name>.onmicrosoft.com/<sign-in-sign-up-user-flow-name>
     
    

    Reference sample - https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-a-sample-node-web-app

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.