Last logged in Capture B2C Authentication in Portal Custom Code


Portal Last logged in B2C Authentication page


The Last Successful Login field on the Contact record has stopped updating. It may be version related - the portals on 9.3.4 don't work whereas those on 9.3.3. do work.


I understand that this feature is deprecated and should be replaced with Azure Application Insights.


B2C Authentication: -

Azure Active Directory B2C (Azure AD B2C) is a cloud identity management solution for web and mobile apps. The service provides authentication for apps hosted in the cloud and on-premises. Authentication types include individual accounts, social network accounts, and federated enterprise accounts.




If your portal is configured with Azure B2C Authentication for this I have implemented the functionality by adding jQuery code and calling Power Automate Flow in the Header web template to update the Last Login field to (almost) replicate the old behavior.  


Step 1: In the Header web template add below script

<script>

       var B2CSignInLink = "{{settings['B2CSignInLink']}}";

 

       if(B2CSignInLink!=null && B2CSignInLink!=undefined &&

        document.referrer.indexOf(B2CSignInLink)!= -1)

       {

              {% if user %}

                      {% assign userEmail= user.emailaddress1 %}

                             var useremail = '{{ userEmail }}';

                             var userObject= '{"userEmailId": "' + useremail + '"}';

                             var req = new XMLHttpRequest();

                             var url = Url;//Here you need to copy paste the Power Automate Http flow URL from the below flow..

                             req.open("POST", url, true);

                             req.setRequestHeader('Content-Type', 'application/json');

                             req.send(userObject);

              {% endif %}

       }

</script>



Step 2: Create a site setting
Name:  
B2CSignInLink

Value: Issuer URL in azure b2C Authentication page (Run the sign in user flow in Azure B2C, we will get URL).


Step 3We need to create Power Automate Flow to Update contact record

 

Select trigger as when a HTTP request is Received.



Request Body JSON Schema add this below schema:

{

    "type""object",

    "properties": {

        "userEmailId": {

            "type""string"

        }

    }

}



In the next stage we need to get contacts and filter the contact who is logging into the portal by using User email Id.



In the next step loop the above contacts and update the filtered contact record.




In the next step loop the above contacts and update the filtered contact record.



Here Last logged in is custom date field updating with current date and time.

By this whenever a user logged into the portal, it will trigger the flow and update the contact.

 

Thank You………. cheers๐Ÿ˜Š๐Ÿ˜Š๐Ÿ˜Š


Comments

Popular posts from this blog

Last Successful Login on Contact record - PowerApps Portal Custom Code

Get Dynamics 365 free trial