Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 54 forks source link

Adding Full auth example #229 #230

Closed Dzoukr closed 3 years ago

Dzoukr commented 3 years ago

I hope this helps, my friend.

Dzoukr commented 3 years ago

Please feel free to reword, cleanup, whatever fits your needs!

Zaid-Ajaj commented 3 years ago

Instead of reviewing here I will merge first, make some changes and ask you to review the changes later if it still looks good 😘

chengh42 commented 2 years ago

Hi @Dzoukr, thanks a lot for the tutorial!

I've been following the instructions on building an app that uses JWT for authentication. Works smoothly in local development; however in production (or locally run dotnet run publish and then navigate to .\publish\app to do dotnet Server.dll), the app only shows the unauthenticated error message "User not logged in". Couldn't figure out what went wrong... would it be possible to get some hints from you on how to fix this?

// Server/WebApp.fs

let private mustBeLoggedIn : HttpHandler =
    requiresAuthentication (RequestErrors.UNAUTHORIZED JwtBearerDefaults.AuthenticationScheme "" "User not logged in")

let webApp (cfg:Jwt.JwtConfiguration): HttpHandler =
    choose [
        Anonymous.anonymousAPI cfg
        mustBeLoggedIn >=> choose [
            Secured.securedAPI
        ]
        htmlFile "public/index.html"
    ]

Link to full codebase here: https://github.com/chengh42/safe-auth-jwt