Skip to content

Commit

Permalink
add OpenId Saturn extension from #139 and talbottmike
Browse files Browse the repository at this point in the history
  • Loading branch information
gfritz authored and Krzysztof-Cieslak committed Aug 29, 2019
1 parent 46daf80 commit ce38617
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Saturn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "gRpcSample", "sample\gRpcSa
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "gRpcSample.Client", "sample\gRpcSample.Client\gRpcSample.Client.fsproj", "{8D89C30B-FF70-4906-A0E3-122B33CF568C}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Saturn.Extensions.OpenIdConnect", "src\Saturn.Extensions.OpenIdConnect\Saturn.Extensions.OpenIdConnect.fsproj", "{E4420975-2F85-4F2B-915D-9B957B376A96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -246,6 +248,18 @@ Global
{8D89C30B-FF70-4906-A0E3-122B33CF568C}.Release|x64.Build.0 = Release|Any CPU
{8D89C30B-FF70-4906-A0E3-122B33CF568C}.Release|x86.ActiveCfg = Release|Any CPU
{8D89C30B-FF70-4906-A0E3-122B33CF568C}.Release|x86.Build.0 = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|x64.ActiveCfg = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|x64.Build.0 = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|x86.ActiveCfg = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Debug|x86.Build.0 = Debug|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|Any CPU.Build.0 = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|x64.ActiveCfg = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|x64.Build.0 = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|x86.ActiveCfg = Release|Any CPU
{E4420975-2F85-4F2B-915D-9B957B376A96}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8DBA089A-7C24-4E87-870B-E0774654F376} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
Expand All @@ -264,5 +278,6 @@ Global
{D1EBD6BB-95B7-4D13-B5AD-C5A5B9D730ED} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
{0747E16C-C06A-4FAE-BBA1-25430A45929D} = {511FB392-5714-4028-97F3-F883F81B43DB}
{8D89C30B-FF70-4906-A0E3-122B33CF568C} = {511FB392-5714-4028-97F3-F883F81B43DB}
{E4420975-2F85-4F2B-915D-9B957B376A96} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nuget Microsoft.AspNetCore.Authentication.Google >= 2.2
nuget Microsoft.AspNetCore.Authentication.OAuth >= 2.2
nuget Microsoft.AspNetCore.Authorization >= 2.2
nuget Microsoft.AspNetCore.Antiforgery >= 2.2
nuget Microsoft.AspNetCore.Authentication.OpenIdConnect >= 2.2
nuget Microsoft.AspNetCore.Server.HttpSys >= 2.2
nuget Microsoft.AspNetCore.WebSockets >= 2.2
nuget FSharp.Control.Websockets
Expand Down
3 changes: 3 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ NUGET
Microsoft.AspNetCore.Authentication.OAuth (2.2)
Microsoft.AspNetCore.Authentication (>= 2.2) - restriction: >= netstandard2.0
Newtonsoft.Json (>= 11.0.2) - restriction: >= netstandard2.0
Microsoft.AspNetCore.Authentication.OpenIdConnect (2.2)
Microsoft.AspNetCore.Authentication.OAuth (>= 2.2) - restriction: >= netstandard2.0
Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 5.3) - restriction: >= netstandard2.0
Microsoft.AspNetCore.Authorization (2.2)
Microsoft.Extensions.Logging.Abstractions (>= 2.2) - restriction: >= netstandard2.0
Microsoft.Extensions.Options (>= 2.2) - restriction: >= netstandard2.0
Expand Down
17 changes: 17 additions & 0 deletions src/Saturn.Extensions.OpenIdConnect/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("Saturn.Extensions.OpenIdConnect")>]
[<assembly: AssemblyProductAttribute("Saturn")>]
[<assembly: AssemblyDescriptionAttribute("Opinionated, web development framework for F# which implements the server-side, functional MVC pattern")>]
[<assembly: AssemblyVersionAttribute("0.9.0")>]
[<assembly: AssemblyFileVersionAttribute("0.9.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Saturn.Extensions.OpenIdConnect"
let [<Literal>] AssemblyProduct = "Saturn"
let [<Literal>] AssemblyDescription = "Opinionated, web development framework for F# which implements the server-side, functional MVC pattern"
let [<Literal>] AssemblyVersion = "0.9.0"
let [<Literal>] AssemblyFileVersion = "0.9.0"
39 changes: 39 additions & 0 deletions src/Saturn.Extensions.OpenIdConnect/OpenId.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Saturn

open Saturn

open Microsoft.AspNetCore.Authentication
open Microsoft.AspNetCore.Authentication.Cookies
open Microsoft.AspNetCore.Authentication.OpenIdConnect
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection

open System

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

// Extend Saturn's application { ... } computation expression
type ApplicationBuilder with
/// Enables OpenId authentication with custom configuration
[<CustomOperation("use_open_id_auth_with_config")>]
member __.UseOpenIdAuthWithConfig(state: ApplicationState, (config: Action<OpenIdConnect.OpenIdConnectOptions>)) =
let middleware (app : IApplicationBuilder) =
app.UseAuthentication()

let service (s: IServiceCollection) =
let authBuilder = s.AddAuthentication(fun authConfig ->
authConfig.DefaultScheme <- CookieAuthenticationDefaults.AuthenticationScheme
authConfig.DefaultChallengeScheme <- OpenIdConnectDefaults.AuthenticationScheme
authConfig.DefaultSignInScheme <- CookieAuthenticationDefaults.AuthenticationScheme)
addCookie state authBuilder
authBuilder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, config) |> ignore

s

{ state with
ServicesConfig = service::state.ServicesConfig
AppConfigs = middleware::state.AppConfigs
CookiesAlreadyAdded = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>portable</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Saturn\Saturn.fsproj">
<Name>Saturn.fsproj</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="OpenId.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
2 changes: 2 additions & 0 deletions src/Saturn.Extensions.OpenIdConnect/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FSharp.Core
Microsoft.AspNetCore.Authentication.OpenIdConnect
16 changes: 16 additions & 0 deletions src/Saturn.Extensions.OpenIdConnect/paket.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type project
id Saturn.Extensions.gRPC
description
Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
authors
Krzysztof Cieslak
copyright
Copyright 2017 Lambda Factory
summary
Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
licenseurl https://github.com/Krzysztof-Cieslak/Saturn/blob/master/LICENSE.md
projecturl https://github.com/Krzysztof-Cieslak/Saturn
iconurl https://avatars0.githubusercontent.com/u/35305523?s=200&v=4
include-pdbs true
tags
F#, web, framework, ASP.Net, Core, HTTP, Service, MVC, functional, gRPC

0 comments on commit ce38617

Please sign in to comment.