Skip to content

Commit e2151f8

Browse files
authored
Moves use_open_id_auth_with_config to the Saturn.Extensions.Authorization project, obsoletes the old member and forwards it to the new project. (#236)
1 parent 10fd5ce commit e2151f8

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

src/Saturn.Extensions.Authorization/OAuth.fs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
module Saturn
22

3-
open Saturn
4-
open FSharp.Control.Tasks.V2.ContextInsensitive
3+
open System
4+
55
open Microsoft.AspNetCore
66
open Microsoft.Extensions.DependencyInjection
77
open Microsoft.AspNetCore.Builder
8+
open Microsoft.AspNetCore.Authentication
89
open Microsoft.AspNetCore.Authentication.Cookies
9-
open Microsoft.AspNetCore.Http
10-
open System.Threading.Tasks
11-
open System
1210
open Microsoft.AspNetCore.Authentication.Google
13-
open Microsoft.AspNetCore.Authentication
14-
open System.Net.Http
15-
open System.Net.Http.Headers
16-
open Newtonsoft.Json.Linq
11+
open Microsoft.AspNetCore.Authentication.OpenIdConnect
12+
open Microsoft.AspNetCore.Http
13+
14+
open Saturn
1715

1816
let private addCookie state (c : AuthenticationBuilder) = if not state.CookiesAlreadyAdded then c.AddCookie() |> ignore
1917

@@ -185,3 +183,25 @@ type Saturn.Application.ApplicationBuilder with
185183
AppConfigs = middleware::state.AppConfigs
186184
CookiesAlreadyAdded = true
187185
}
186+
187+
/// Enables OpenId authentication with custom configuration
188+
[<CustomOperation("use_open_id_auth_with_config")>]
189+
member __.UseOpenIdAuthWithConfig(state: ApplicationState, (config: Action<OpenIdConnect.OpenIdConnectOptions>)) =
190+
let middleware (app : IApplicationBuilder) =
191+
app.UseAuthentication()
192+
193+
let service (s: IServiceCollection) =
194+
let authBuilder = s.AddAuthentication(fun authConfig ->
195+
authConfig.DefaultScheme <- CookieAuthenticationDefaults.AuthenticationScheme
196+
authConfig.DefaultChallengeScheme <- OpenIdConnectDefaults.AuthenticationScheme
197+
authConfig.DefaultSignInScheme <- CookieAuthenticationDefaults.AuthenticationScheme)
198+
addCookie state authBuilder
199+
authBuilder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, config) |> ignore
200+
201+
s
202+
203+
{ state with
204+
ServicesConfig = service::state.ServicesConfig
205+
AppConfigs = middleware::state.AppConfigs
206+
CookiesAlreadyAdded = true }
207+

src/Saturn.Extensions.Authorization/paket.references

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ group netstandard2.0
33
FSharp.Core framework: netstandard2.0
44
Microsoft.AspNetCore.Authentication.Google framework: netstandard2.0
55
Microsoft.AspNetCore.Authentication.OAuth framework: netstandard2.0
6+
Microsoft.AspNetCore.Authentication.OpenIdConnect framework: netstandard2.0
67

78
group netcoreapp3.1
89
FSharp.Core framework: netcoreapp3.1
910
Microsoft.AspNetCore.Authentication.Google framework: netcoreapp3.1
11+
Microsoft.AspNetCore.Authentication.OpenIdConnect framework: netcoreapp3.1
1012

src/Saturn.Extensions.OpenIdConnect/OpenId.fs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ module OpenId =
1919
type Saturn.Application.ApplicationBuilder with
2020
/// Enables OpenId authentication with custom configuration
2121
[<CustomOperation("use_open_id_auth_with_config")>]
22-
member __.UseOpenIdAuthWithConfig(state: ApplicationState, (config: Action<OpenIdConnect.OpenIdConnectOptions>)) =
23-
let middleware (app : IApplicationBuilder) =
24-
app.UseAuthentication()
25-
26-
let service (s: IServiceCollection) =
27-
let authBuilder = s.AddAuthentication(fun authConfig ->
28-
authConfig.DefaultScheme <- CookieAuthenticationDefaults.AuthenticationScheme
29-
authConfig.DefaultChallengeScheme <- OpenIdConnectDefaults.AuthenticationScheme
30-
authConfig.DefaultSignInScheme <- CookieAuthenticationDefaults.AuthenticationScheme)
31-
addCookie state authBuilder
32-
authBuilder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, config) |> ignore
33-
34-
s
35-
36-
{ state with
37-
ServicesConfig = service::state.ServicesConfig
38-
AppConfigs = middleware::state.AppConfigs
39-
CookiesAlreadyAdded = true }
22+
[<Obsolete("This operation has been moved to the Saturn.Extensions.Authorization project.")>]
23+
member this.UseOpenIdAuthWithConfig_Obsolete(state: ApplicationState, (config: Action<OpenIdConnect.OpenIdConnectOptions>)) =
24+
this.UseOpenIdAuthWithConfig(state, config)

src/Saturn.Extensions.OpenIdConnect/Saturn.Extensions.OpenIdConnect.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ProjectReference Include="..\Saturn\Saturn.fsproj">
1212
<Name>Saturn.fsproj</Name>
1313
</ProjectReference>
14+
<ProjectReference Include="..\Saturn.Extensions.Authorization\Saturn.Extensions.Authorization.fsproj" />
1415
</ItemGroup>
1516
<ItemGroup>
1617
<Compile Include="OpenId.fs" />

0 commit comments

Comments
 (0)