We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usually when authenticating, we care about who is authenticated!
However, the current methods in Authentication support this only via context, which has some issues:
Authentication
I propose a new combinator like this:
let authenticateBasicUserAsync (tryAuthenticate : string * string -> Async<'user option>) (makeProtectedPart : 'user -> WebPart) : WebPart = fun ctx -> async { let p = ctx.request match p.header "authorization" with | Choice1Of2 header -> let (typ, username, password) = parseAuthenticationToken header if (typ.Equals("basic")) then let! maybeUser = tryAuthenticate (username, password) match maybeUser with | Some user -> return! makeProtectedPart user (addUserName username ctx) | None -> return! challenge ctx else return! challenge ctx | Choice2Of2 _ -> return! challenge ctx }
The existing combinators can be defined in terms of this:
let authenticateBasicAsync (f : string * string -> Async<bool>) (protectedPart : WebPart) : WebPart = authenticateBasicUserAsync (fun (username, password) -> async { let! isAuthenticated = f (username, password) if isAuthenticated then return Some () else return None }) (fun () -> protectedPart)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Usually when authenticating, we care about who is authenticated!
However, the current methods in
Authentication
support this only via context, which has some issues:I propose a new combinator like this:
The existing combinators can be defined in terms of this:
The text was updated successfully, but these errors were encountered: