Skip to content

Michal Chmielus Blog

Microsoft Technology Passion Blog

Menu
Menu

Authenticate Azure App Service with Azure AD Security Group

Posted on 2019-01-172019-01-17 by michalchmielus

If you’re developing Azure App Service i.e. ASP.NET MVC application and there is a requirement to authenticate current user against Azure AD Security Group you need to consider some steps:

In th Startup.cs as the part of UseOpenIdConnectAuthentication add/change Notifications

Notifications = new OpenIdConnectAuthenticationNotifications()
{
 RedirectToIdentityProvider = (context) =>
 {
  string appBaseUrl = ConvertToSsl(context.Request.Scheme) + “://” +
  context.Request.Host + context.Request.PathBase;
  context.ProtocolMessage.RedirectUri = appBaseUrl;
  context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
  return Task.FromResult(0);
 }
}

ConvertToSsl helps ensuring appBaseUrl starts with https protocol.

The Azure AD Application provided as a ClientId in OpenIdConnectAuthenticationOptions should have some adjustement in the manifest. Please refer to manifest guideline.

The change in the manifest is by adding / replacing line:

“groupMembershipClaims” : “SecurityGroup”

This is crutial to have desired authentication working properly.

Obviously, there is one action pending – how to auhtorize user. Let’s commit we’re going to use a filter approach by creating custom attribute class which inherits from AuthorizeAttribute, i.e.:

public class AuthorizeBySg: AuthorizeAttribute

and override AuthorizeCore function, i.e.:

protected override bool AuthorizeCore(HttpContextBase context)
{
 if (!base.AuthorizeCore(context)) return false;
 return ClaimsPrincipal.Current.Claims.Any(c => c.Type == “groups” && mygroupId == c.Value);
}

mygroupId is an object ID of restricted Azure AD Security Group.

Finally, decorate your Controller or methods in your Controller with newly created AuthorizeBySg attribute class.

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Unit Testing Dynamics 365 plugin code
  • Bulk load into Dynamics 365
  • Authenticate Azure App Service with Azure AD Security Group

Categories

  • Azure
  • Dynamics 365
  • Integrate Dynamics 365

Ratings

  • Unit Testing Dynamics 365 plugin code 1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5 (5.00 out of 5)
  • How to bind Dynamics 365 with Azure Logic Apps 1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5 (5.00 out of 5)
  • Utilize Data Export Service as data replication service in Dynamics 365 1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5 (5.00 out of 5)
  • Call Dynamics 365 from Azure App Service 0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0.00 out of 5)
  • Authenticate Azure App Service with Azure AD Security Group 0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0.00 out of 5)
  • Bulk load into Dynamics 365 0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0.00 out of 5)
©2026 Michal Chmielus Blog | Built using WordPress and Responsive Blogily theme by Superb