Skip to content

Commit

Permalink
.NET8, dependencies and az cli updates
Browse files Browse the repository at this point in the history
  • Loading branch information
et1975 committed Apr 12, 2024
1 parent 8b88b45 commit 257ba3d
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 105 deletions.
7 changes: 3 additions & 4 deletions AAD.Giraffe/AAD.Giraffe.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
Expand All @@ -12,9 +12,8 @@
<Compile Include="Noop.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Include="Giraffe" Version="5.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.7.0" />
<PackageReference Include="Giraffe" Version="6.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.*" />
</ItemGroup>
</Project>
9 changes: 4 additions & 5 deletions AAD.Giraffe/PartProtector.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace AAD
open Microsoft.AspNetCore.Http
open System.Threading.Tasks
open Giraffe
open FSharp.Control.Tasks.V2.ContextInsensitive
open System.IdentityModel.Tokens.Jwt
open Microsoft.IdentityModel.Protocols.OpenIdConnect
open Microsoft.Extensions.Caching.Memory
Expand Down Expand Up @@ -53,7 +52,7 @@ module PartProtector =
member __.Verify (getDemand: HttpContext -> Task<Demand>)
(onSuccess: JwtSecurityToken -> HttpHandler) =
fun next (ctx:HttpContext) ->
task {
backgroundTask {
let handleSuccess,handleMissing,result =
ResultHandler.mkDefault onSuccess
let! demand = getDemand ctx
Expand All @@ -67,7 +66,7 @@ module PartProtector =
(onSuccess: JwtSecurityToken -> HttpHandler)
(onError: JwtSecurityToken option -> WWWAuthenticate -> HttpHandler) =
fun next (ctx:HttpContext) ->
task {
backgroundTask {
let handleSuccess,handleMissing,result =
ResultHandler.mkNew onError onSuccess
let! demand = getDemand ctx
Expand All @@ -84,10 +83,10 @@ module PartProtector =
let mkDefault (httpClient: HttpClient)
(audiences: #seq<Audience>)
(authority: System.Uri) =
task {
backgroundTask {
let getConfiguration =
let cache = new MemoryCache(new MemoryCacheOptions(SizeLimit = 1L))
fun () -> cache.GetOrCreateAsync(1, fun e -> task {
fun () -> cache.GetOrCreateAsync(1, fun e -> backgroundTask {
let! r = OpenIdConnectConfigurationRetriever
.GetAsync(sprintf "%O/.well-known/openid-configuration" authority, httpClient, System.Threading.CancellationToken.None)
.ConfigureAwait false
Expand Down
5 changes: 2 additions & 3 deletions AAD.Suave/AAD.Suave.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
Expand All @@ -12,8 +12,7 @@
<Compile Include="Noop.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.7.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Suave" Version="2.6.*" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions AAD.Suave/PartProtector.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Suave.Operators
open System.IdentityModel.Tokens.Jwt
open Microsoft.IdentityModel.Protocols.OpenIdConnect
open Microsoft.Extensions.Caching.Memory
open FSharp.Control.Tasks.V2.ContextInsensitive

/// PartProtector is the interface for a stateful protector instance.
/// Use PartProtector module to create the instances implementing this interface.
Expand Down Expand Up @@ -86,7 +85,7 @@ module PartProtector =
let getConfiguration =
let cache = new MemoryCache(new MemoryCacheOptions(SizeLimit = 1L))
fun () ->
cache.GetOrCreateAsync(1, fun e -> task {
cache.GetOrCreateAsync(1, fun e -> backgroundTask {
let! r = OpenIdConnectConfigurationRetriever
.GetAsync(sprintf "%O/.well-known/openid-configuration" authority, httpClient, System.Threading.CancellationToken.None)
.ConfigureAwait false
Expand Down
27 changes: 12 additions & 15 deletions AAD.Test/AAD.Test.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId>
</PropertyGroup>
<ItemGroup>
Expand All @@ -19,25 +19,22 @@
<Compile Include="ResourceOwnerTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="1.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.5" />
<PackageReference Include="Suave" Version="2.6.*" />
<PackageReference Include="unquote" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
<PackageReference Include="unquote" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.6.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.*" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.5.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<ProjectReference Include="..\AAD.fs\AAD.fs.fsproj" />
<ProjectReference Include="..\AAD.Suave\AAD.Suave.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions AAD.Test/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module AADTests.Logging
open System.Threading
open System.Threading.Tasks
open System.Net.Http
open FSharp.Control.Tasks

type Log = string -> (string*obj) list -> unit

Expand All @@ -12,7 +11,7 @@ type HttpClientLogger(innerHandler, log:Log) =
member private __.baseImpl (request, cancellationToken) = base.SendAsync (request, cancellationToken)
override this.SendAsync(request:HttpRequestMessage, cancellationToken:CancellationToken):Task<HttpResponseMessage> =

task {
backgroundTask {
if isNull request.Content then
log "Request: {req}" ["req", box request]
else
Expand Down
12 changes: 5 additions & 7 deletions AAD.fs.tasks/AAD.fs.tasks.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DefineConstants>TASKS</DefineConstants>
</PropertyGroup>
Expand All @@ -12,11 +12,9 @@
<Compile Include="../AAD.fs/Requestor.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.6.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.7.0" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.6.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.5.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
</ItemGroup>
</Project>
12 changes: 5 additions & 7 deletions AAD.fs/AAD.fs.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
Expand All @@ -11,11 +11,9 @@
<Compile Include="ResourceOwner.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.6.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.7.0" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.6.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.5.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
</ItemGroup>
</Project>
7 changes: 3 additions & 4 deletions AAD.fs/Awaitable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ open System
module internal AwaitableBuilder =
open System.Threading.Tasks
#if TASKS
open FSharp.Control.Tasks
let awaitable = task
let awaitable = backgroundTask
type Awaitable<'r> = Task<'r>

[<RequireQualifiedAccess>]
Expand All @@ -16,8 +15,8 @@ module internal AwaitableBuilder =
let inline awaitTask x = x
let inline awaitUnitTask (x:Task) = x.ContinueWith<unit>(fun _ -> ())
let inline awaitAsync x = Async.StartAsTask x
let inline map f (x:Task<_>) = task { let! v = x in return f v }
let inline bind f (x:Task<_>) = task { let! v = x in return! f v }
let inline map f (x:Task<_>) = backgroundTask { let! v = x in return f v }
let inline bind f (x:Task<_>) = backgroundTask { let! v = x in return! f v }
let inline whenAll (xs:#seq<Task<'t>>) = Task.WhenAll<'t> (Array.ofSeq xs)
#else
let awaitable = async
Expand Down
6 changes: 2 additions & 4 deletions AAD.fs/ResourceOwner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ open System.IdentityModel.Tokens.Jwt
module internal TokenCache =
open System.Threading.Tasks
open Microsoft.Extensions.Caching.Memory
open FSharp.Control.Tasks

let mkNew options =
let cache = new MemoryCache(options)
let getOrAdd key (mkEntry: string -> Task<Result<JwtSecurityToken,_>>) =
cache.GetOrCreateAsync(key, fun e -> task {
cache.GetOrCreateAsync(key, fun e -> backgroundTask {
let! r = mkEntry key
match r with
| Ok entry ->
Expand All @@ -37,15 +36,14 @@ module internal Introspector =
open YoLo
open Microsoft.IdentityModel.Tokens
open Microsoft.IdentityModel.Protocols.OpenIdConnect
open FSharp.Control.Tasks.V2.ContextInsensitive

let mkNew (cache:string -> (string -> Task<_>) -> Task<_>)
(audiences: #seq<Audience>)
(getConfig: unit -> Awaitable<OpenIdConnectConfiguration>) =
let handler = JwtSecurityTokenHandler()

let local (jwtEncodedString: string) =
task {
backgroundTask {
try
let! oidcConfig = getConfig()
let vparams = TokenValidationParameters
Expand Down
25 changes: 11 additions & 14 deletions AAD.tasks.Test/AAD.tasks.Test.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId>
</PropertyGroup>
<ItemGroup>
Expand All @@ -18,23 +18,20 @@
<Compile Include="ResourceOwnerTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="1.0.6" />
<PackageReference Include="unquote" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.5" />
<PackageReference Include="unquote" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<ProjectReference Include="..\AAD.fs.tasks\AAD.fs.tasks.fsproj" />
<ProjectReference Include="..\AAD.Giraffe\AAD.Giraffe.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
</ItemGroup>
</Project>
11 changes: 5 additions & 6 deletions AAD.tasks.Test/ResourceOwnerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open System.Threading
open System.Threading.Tasks
open Xunit
open Swensen.Unquote
open FSharp.Control.Tasks.V2.ContextInsensitive
open AAD
open AADTests.TestsCommon

Expand All @@ -14,7 +13,7 @@ open AADTests.TestsCommon
type Parties() =
let mutable last = None
let init httpClient =
task {
backgroundTask {
match last with
| Some args -> return args
| _ ->
Expand Down Expand Up @@ -47,7 +46,7 @@ type ThreeBodyProblem(output: Xunit.Abstractions.ITestOutputHelper, fixture: Par

[<Fact>]
member __.``Admin can write and read`` () =
task {
backgroundTask {
let _, proxy = fixture.Init httpClient
let requestor =
proxy |> TaskRequestor.mkNew (ResourceProxy.authenticate ([settings.Scope], ClientId settings.AdminAppId, Secret settings.AdminSecret, settings.Authority))
Expand All @@ -59,7 +58,7 @@ type ThreeBodyProblem(output: Xunit.Abstractions.ITestOutputHelper, fixture: Par

[<Fact>]
member __.``Writer can write but not read`` () =
task {
backgroundTask {
let _, proxy = fixture.Init httpClient
let requestor =
proxy |> TaskRequestor.mkNew (ResourceProxy.authenticate ([settings.Scope], ClientId settings.WriterAppId, Secret settings.WriterSecret, settings.Authority))
Expand All @@ -74,7 +73,7 @@ type ThreeBodyProblem(output: Xunit.Abstractions.ITestOutputHelper, fixture: Par

[<Fact>]
member __.``Reader can read`` () =
task {
backgroundTask {
let _, proxy = fixture.Init httpClient
let requestor =
proxy |> TaskRequestor.mkNew (ResourceProxy.authenticate ([settings.Scope], ClientId settings.ReaderAppId, Secret settings.ReaderSecret, settings.Authority))
Expand All @@ -84,7 +83,7 @@ type ThreeBodyProblem(output: Xunit.Abstractions.ITestOutputHelper, fixture: Par

[<Fact>]
member __.``Forbidden`` () =
task {
backgroundTask {
let _, proxy = fixture.Init httpClient
let! response = proxy.provision() // should always succeed

Expand Down
7 changes: 3 additions & 4 deletions AAD.tasks.Test/ResourceProxy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace AADTests
open System
open System.Threading.Tasks
open System.Net.Http
open FSharp.Control.Tasks
open AAD
open Microsoft.Identity.Client

Expand All @@ -26,7 +25,7 @@ module ResourceProxy =
member __.httpClient = httpClient
member __.address = address
member __.provision() =
task {
backgroundTask {
use r = new HttpRequestMessage(Method = HttpMethod.Head,
RequestUri = address)
withHeaders r.Headers
Expand All @@ -35,7 +34,7 @@ module ResourceProxy =
raise (ProxyException response.StatusCode)
} :> Task
member __.read() =
task {
backgroundTask {
use r = new HttpRequestMessage(Method = HttpMethod.Get,
RequestUri = address)
withHeaders r.Headers
Expand All @@ -46,7 +45,7 @@ module ResourceProxy =
return content
}
member __.write() =
task {
backgroundTask {
use r = new HttpRequestMessage(Method = HttpMethod.Put,
RequestUri = address)
withHeaders r.Headers
Expand Down
Loading

0 comments on commit 257ba3d

Please sign in to comment.