Last active
February 13, 2022 21:58
-
-
Save xperiandri/736c7e0e0d39844953eb7838542f507e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AllowedGroupRequierment (groups : string seq) = | |
member val Groups = groups.ToImmutableHashSet () | |
interface IAuthorizationRequirement | |
type AllowedGroupHandler (graphService : IMicrosoftGraphService, userIdResult : Lazy<Result<GraphQLUser, Errors.ErrorMessage>>) = | |
inherit AuthorizationHandler<AllowedGroupRequierment> () | |
override _.HandleRequirementAsync (context, requirement) = task { | |
match userIdResult.Value with | |
| Result.Error _ -> return () // user not authenticated / пользователь не аутентифицирован | |
| Result.Ok user -> | |
let! userGroups = graphService.AsyncGetUserGroupNames user.Id | |
let requiredGroups = requirement.Groups | |
let allowed = not <| requiredGroups.Intersect(userGroups).IsEmpty | |
if allowed | |
then context.Succeed requirement | |
else () | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment