I have been working lately a lot on PowerApps portals and this is one interesting requirement that we recently had. So the customer have set up Authentication via Google account and the requirement was whenever a user try to browse the portal, they should be automatically signed in or taken to the sign in provider page. In other words, only users registered with the portal should be allowed to use the portal.
Quite interesting isn’t it? And trust me, it’s quite easy. So let’s see how can we accomplish this task.
For this example, I am going to show with Google account. But this can be achieved with all external providers including the most popular Azure AD B2C login.
So let’s get started.
Step 1 : Create site setting
The first step is to set-up the default authentication provide. In other words, whenever a portal user try to sign in, the default authentication provider should always be used.
Go to Portal Management App and create the site setting – Authentication/Registration/LoginButtonAuthenticationType
As you can see, I have provided the value as https://accounts.google.com. This is because I am using Google as authentication provider here. However if you are using any other external provide, all you need to do is just use the same value provided in Authority site setting while setting up the external provider.
Step 2 : Use Liquid for redirecting to Sign In Page
Here I am using the home page for demo but basically you can use any portal web page.
Make sure you navigate to the Localized Content section of Home Page and open up the desired language content page.
In the Advanced tab in custom JavaScript section, copy and paste the below script.
$(window).on(“load”, function(){
var isLoggedIn = {%if user %} true {% else %} false {% endif %};
var signInEndpoint = “{{ snippets[‘Login_Endpoint’] }}”;
if(!isLoggedIn && window.location.href !== signInEndpoint){
window.location.href = signInEndpoint;
}
});
Here I have used a content snippet to avoid hardcoding. Below is the content snippet I created where I put in the url of the sign-in page.
That’s all. Now when the user browse the home page of the portal, they are automatically redirected to provided login page and signed in.
Hope this helps!
Debajit Dutta
(Dynamics MVP)
For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
Our product offerings:
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.