0
votes

Here is my code in Startup.Auth.cs

 public void ConfigureAuth(IAppBuilder app)        {

       JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,
                TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer=false,
                    NameClaimType = "upn",
                   RoleClaimType ="roles"   
                }                   
            });
    }

And in My MVC View I am checking the @User.IsInRole("CBUser") which returns True since the user is having the role as CBUSer . All this code works fine in Visual Studio with Azure AD Authentication and Authorization . But When I move the application to Azure ,@User.IsInRole("CBUser") always returns false. How can Can I read the User Roles either in MVC View or in Controller .I tried below code to read the user roles which is working fine in while debugging in VS2015 .But does not work once application moved to Azure environment

            var appRoles = new List<string>();
        foreach (Claim claim in ClaimsPrincipal.Current.FindAll("roles"))
                appRoles.Add(claim.Value);
1
Are you using the same clientId value for the app deployed to Azure? - Philippe Signoret

1 Answers

0
votes

The code you posted seems fine. Maybe you can take the official sample for a look: Authorization in a web app using Azure AD application roles & role claims

Also, you can remote debug your web application: Troubleshoot a web app in Azure App Service using Visual Studio