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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,110 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,458 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
17,536 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 22,651 Reputation points Microsoft Employee
    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