ASP.NET Core has built-in support for authentication and authorization. Falco includes some prebuilt, configurable handlers for common scenarios.
Review the docs for specific implementation details.
open Falco
let authScheme = "some.secure.scheme"
let secureResourceHandler : HttpHandler =
let handleAuth : HttpHandler =
Response.ofPlainText "hello authenticated user"
Request.ifAuthenticated authScheme handleAuth
open Falco
let anonResourceOnlyHandler : HttpHandler =
let handleAnon : HttpHandler =
Response.ofPlainText "hello anonymous"
Request.ifNotAuthenticated authScheme handleAnon
open Falco
let secureResourceHandler : HttpHandler =
let handleAuthInRole : HttpHandler =
Response.ofPlainText "hello admin"
let rolesAllowed = [ "Admin" ]
Request.ifAuthenticatedInRole authScheme rolesAllowed handleAuthInRole
open Falco
let secureResourceHandler : HttpHandler =
let handleAuthHasScope : HttpHandler =
Response.ofPlainText "user1, user2, user3"
let issuer = "https://oauth2issuer.com"
let scope = "read:users"
Request.ifAuthenticatedWithScope authScheme issuer scope handleAuthHasScope
open Falco
let logOut : HttpHandler =
let authScheme = "..."
let redirectTo = "/login"
Response.signOutAndRedirect authScheme redirectTo