Skip to content

Instantly share code, notes, and snippets.

@xperiandri
Last active February 13, 2022 21:55
Show Gist options
  • Save xperiandri/32a6878b4d95f6c40cf2cc98b60f5d81 to your computer and use it in GitHub Desktop.
Save xperiandri/32a6878b4d95f6c40cf2cc98b60f5d81 to your computer and use it in GitHub Desktop.
type WebJobsHttpExtensionStartup () =
interface IWebJobsStartup with
member __.Configure (builder : IWebJobsBuilder) =
builder.Services
.AddScoped<Lazy<Result<GraphQLUser, Errors.ErrorMessage>>>(
fun provider -> Control.Lazy.Create(fun () -> WebJobsHttpExtensionStartup.GetUserIdResultFromClaims provider))
.AddAuthorizationWithReflection (fun options ->
options.AddPolicy(Policies.EditBooks,
fun policy -> policy.Requirements.Add(
AllowedGroupRequierment (Seq.singleton ActiveDirectoryGroups.BookEditors)))
options.AddPolicy(Policies.ViewBooks,
fun policy -> policy.Requirements.Add(
AllowedGroupRequierment (seq {
yield ActiveDirectoryGroups.BookEditors
yield ActiveDirectoryGroups.BooksViewers
})))
options.AddPolicy(Policies.ViewUsers,
fun policy -> policy.Requirements.Add(
AllowedGroupRequierment (Seq.singleton ActiveDirectoryGroups.UserViewers))))
.AddScoped<IAuthorizationHandler, AllowedGroupHandler>()
.AddScoped<IAuthorizationHandler, AllowedGroupAdminHandler>()
|> ignore
()
[<assembly: WebJobsStartup(typeof<WebJobsHttpExtensionStartup>, "Http Extension")>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment