SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
708 stars 108 forks source link

identityserver integration #190

Closed nodew closed 4 years ago

nodew commented 5 years ago

Can saturn work with identityserver? If can, is there some demos?

isaacabraham commented 5 years ago

There's no reason why it can't, Saturn is just a wrapper over ASP .NET. However, it could be nice to have a sample application showing a basic identity server example. Most of the time you can use the service_config command inside application to add custom middleware etc.

Pryrda commented 5 years ago

Hello everybody, can please someone provide sample solution with identity server integration? :) THX

yurotor commented 4 years ago

If this is still relevant, here's the solution:

  1. Add IdentityServer4.AccessTokenValidation NuGet to your entry point project.

  2. Write a function that adds identity server authentication capabilities to your application builder: let identityServer (services:IServiceCollection) = let auth (options:IdentityServerAuthenticationOptions) = options.Authority <- "yourIdentyServerURL" options.ApiName <- "yourApiName" options.ApiSecret <- "yourApiSecret" () let authBuilder = services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) authBuilder.AddIdentityServerAuthentication(auth) |> ignore services.AddAuthorization()

  3. Write a function that adds the authentication feature to the application builder: let authentication (app:IApplicationBuilder) = app.UseAuthentication()

  4. Add a pipe_through operation into any router where you wish to authorize the role of the request sender: let appRouter = router { pipe_through (Auth.requireRole JWT "yourRoleName") }

  5. And finally, configure your application computation expression like this: let app = application { service_config identityServer app_config authentication use_router appRouter }

Krzysztof-Cieslak commented 4 years ago

@yurotor thanks for this guide. ❤️