Upgrade policy sample from 1.1 to 2.2
Changed GetExternalAuthenticationSchemes to GetExternalAuthenticationSchemesAsync
but Where needs work.
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
BuildingEntryRequirement requirement)
{
if (context.User.HasClaim(c => c.Type == ClaimTypes.BadgeId &&
c.Issuer == "http://microsoftsecurity"))
{
context.Succeed(requirement);
}
//TODO: Use the following if targeting a version of
//.NET Framework older than 4.6:
// return Task.FromResult(0);
return Task.CompletedTask;
}
ClaimTypes does not contain a definition for TemporaryBadgeId
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@haok would you be able to upgrade PoliciesAuthApp1 to 2.2?
I got stuck on the Where and ClaimTypes
You can use the following (taken from the RCL source) for the Where change:
var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
.Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider))
.ToList();
This also requires a change from AuthenticationDescription to AuthenticationScheme in ManageLoginsViewModel.
Forgive my ignorance here, but it looks to me like ClaimTypes.TemporaryBadgeId would never have compiled. Even if it did, I can't see anywhere in the project where said claim would be issued.
@blowdart can you help get this code working?
I have to get through my preview3 bugs before I can take a look at this, but I would suggest it might be easier to create a new 2.2 app and move the authz controllers + policy handlers over, that might be easier than trying to convert things, since the stuff the samples is demonstrating isn't really related to any of the changes between 1.1 and 2.2
Authentication changed a lot in 2.x, but Authorization policies should be more or less untouched for the purposes of this sample
@serpent5 would you be able to create the new 2.2 app?
@Rick-Anderson Sure. I should be able to put something together within the next couple of days.
@HaoK Rather than moving the authz controllers over, would it be OK to use the default UI in the new project?
That should be fine
@Rick-Anderson Shall I stick to controllers/views in the new version or would you prefer if I switch over to RP as part of this?
Your call. I have a slight preference for RP, but either is fine.
Most helpful comment
That should be fine