Skip to content

Commit 28b2bfb

Browse files
authored
v3.0 - Replace caching implementation & modernize project (#17)
* Implicit usings & file namespace all the things * Replace cache implementation * Add new build infrastructure * Adjust implementation lifetimes * Modernize Worker example * Adjust log messages * Modernize ASP.NET project * Update README
1 parent 2d245ef commit 28b2bfb

43 files changed

Lines changed: 1236 additions & 810 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/Build_&_Test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ------------------------------------------------------------------------------
2+
# <auto-generated>
3+
#
4+
# This code was generated.
5+
#
6+
# - To turn off auto-generation set:
7+
#
8+
# [GitHubActions (AutoGenerate = false)]
9+
#
10+
# - To trigger manual generation invoke:
11+
#
12+
# nuke --generate-configuration GitHubActions_Build_&_Test --host GitHubActions
13+
#
14+
# </auto-generated>
15+
# ------------------------------------------------------------------------------
16+
17+
name: Build_&_Test
18+
19+
on:
20+
push:
21+
branches:
22+
- main
23+
pull_request:
24+
branches:
25+
- main
26+
27+
jobs:
28+
ubuntu-latest:
29+
name: ubuntu-latest
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
34+
uses: actions/cache@v3
35+
with:
36+
path: |
37+
.nuke/temp
38+
~/.nuget/packages
39+
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
40+
- name: 'Run: Test'
41+
run: ./build.cmd Test
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ------------------------------------------------------------------------------
2+
# <auto-generated>
3+
#
4+
# This code was generated.
5+
#
6+
# - To turn off auto-generation set:
7+
#
8+
# [GitHubActions (AutoGenerate = false)]
9+
#
10+
# - To trigger manual generation invoke:
11+
#
12+
# nuke --generate-configuration GitHubActions_Manual_Nuget_Push --host GitHubActions
13+
#
14+
# </auto-generated>
15+
# ------------------------------------------------------------------------------
16+
17+
name: Manual_Nuget_Push
18+
19+
on: [workflow_dispatch]
20+
21+
jobs:
22+
ubuntu-latest:
23+
name: ubuntu-latest
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
.nuke/temp
32+
~/.nuget/packages
33+
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
34+
- name: 'Run: NugetPush'
35+
run: ./build.cmd NugetPush
36+
env:
37+
NugetApiKey: ${{ secrets.NUGET_API_KEY }}

.github/workflows/main.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,6 @@ MigrationBackup/
359359
.ionide/
360360

361361
# Fody - auto-generated XML schema
362-
FodyWeavers.xsd
362+
FodyWeavers.xsd
363+
364+
.idea

.nuke/build.schema.json

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$ref": "#/definitions/build",
4+
"title": "Build Schema",
5+
"definitions": {
6+
"build": {
7+
"type": "object",
8+
"properties": {
9+
"Continue": {
10+
"type": "boolean",
11+
"description": "Indicates to continue a previously failed build attempt"
12+
},
13+
"Help": {
14+
"type": "boolean",
15+
"description": "Shows the help text for this build assembly"
16+
},
17+
"Host": {
18+
"type": "string",
19+
"description": "Host for execution. Default is 'automatic'",
20+
"enum": [
21+
"AppVeyor",
22+
"AzurePipelines",
23+
"Bamboo",
24+
"Bitbucket",
25+
"Bitrise",
26+
"GitHubActions",
27+
"GitLab",
28+
"Jenkins",
29+
"Rider",
30+
"SpaceAutomation",
31+
"TeamCity",
32+
"Terminal",
33+
"TravisCI",
34+
"VisualStudio",
35+
"VSCode"
36+
]
37+
},
38+
"NoLogo": {
39+
"type": "boolean",
40+
"description": "Disables displaying the NUKE logo"
41+
},
42+
"NugetApiKey": {
43+
"type": "string",
44+
"description": "Nuget Api Key",
45+
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
46+
},
47+
"Partition": {
48+
"type": "string",
49+
"description": "Partition to use on CI"
50+
},
51+
"Plan": {
52+
"type": "boolean",
53+
"description": "Shows the execution plan (HTML)"
54+
},
55+
"Profile": {
56+
"type": "array",
57+
"description": "Defines the profiles to load",
58+
"items": {
59+
"type": "string"
60+
}
61+
},
62+
"Root": {
63+
"type": "string",
64+
"description": "Root directory during build execution"
65+
},
66+
"Skip": {
67+
"type": "array",
68+
"description": "List of targets to be skipped. Empty list skips all dependencies",
69+
"items": {
70+
"type": "string",
71+
"enum": [
72+
"Clean",
73+
"Compile",
74+
"NugetPack",
75+
"NugetPush",
76+
"Restore",
77+
"Test"
78+
]
79+
}
80+
},
81+
"Solution": {
82+
"type": "string",
83+
"description": "Path to a solution file that is automatically loaded"
84+
},
85+
"Target": {
86+
"type": "array",
87+
"description": "List of targets to be invoked. Default is '{default_target}'",
88+
"items": {
89+
"type": "string",
90+
"enum": [
91+
"Clean",
92+
"Compile",
93+
"NugetPack",
94+
"NugetPush",
95+
"Restore",
96+
"Test"
97+
]
98+
}
99+
},
100+
"Verbosity": {
101+
"type": "string",
102+
"description": "Logging verbosity during build execution. Default is 'Normal'",
103+
"enum": [
104+
"Minimal",
105+
"Normal",
106+
"Quiet",
107+
"Verbose"
108+
]
109+
}
110+
}
111+
}
112+
}
113+
}

.nuke/parameters.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./build.schema.json",
3+
"Solution": "Auth0Net.DependencyInjection.sln"
4+
}

Auth0Net.DependencyInjection.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.AspNetCore", "sample
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Auth0Net.DependencyInjection.Tests", "tests\Auth0Net.DependencyInjection.Tests\Auth0Net.DependencyInjection.Tests.csproj", "{021A8A83-5A9E-4727-B081-ADFA1EDB0F0F}"
1313
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{3E86C014-A0D0-49B2-90A8-2432D6CD6CF8}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8D0ACD6E-8A79-46DB-86F3-3F075F401CAF}"
17+
ProjectSection(SolutionItems) = preProject
18+
README.md = README.md
19+
EndProjectSection
20+
EndProject
1421
Global
1522
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1623
Debug|Any CPU = Debug|Any CPU
1724
Release|Any CPU = Release|Any CPU
1825
EndGlobalSection
1926
GlobalSection(ProjectConfigurationPlatforms) = postSolution
27+
{3E86C014-A0D0-49B2-90A8-2432D6CD6CF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{3E86C014-A0D0-49B2-90A8-2432D6CD6CF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
2029
{1688937B-298C-42C7-81B9-1091418B2A93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2130
{1688937B-298C-42C7-81B9-1091418B2A93}.Debug|Any CPU.Build.0 = Debug|Any CPU
2231
{1688937B-298C-42C7-81B9-1091418B2A93}.Release|Any CPU.ActiveCfg = Release|Any CPU

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ public class MyAuth0Service : IAuth0Service
9696

9797
#### Handling Custom Domains
9898

99-
If you're using a custom domain with your Auth0 tenant, you may run into a problem whereby the `audience` of the Management API is being incorrectly set. You can override this via the following:
99+
If you're using a custom domain with your Auth0 tenant, you may run into a problem whereby the `audience` of the Management API is being incorrectly set. You can override this via the `Audience` property:
100100

101101
```cs
102102
services.AddAuth0ManagementClient()
103103
.AddManagementAccessToken(c =>
104104
{
105-
c.AudienceDomainOverride = "my-tenant.au.auth0.com";
105+
c.Audience = "my-tenant.au.auth0.com";
106106
});
107107
```
108108

@@ -141,18 +141,24 @@ services.AddHttpClient<MyHttpService>(x=> x.BaseAddress = new Uri("https://MySer
141141
.AddAccessToken(config => config.AudienceResolver = request => request.RequestUri.GetLeftPart(UriPartial.Authority));
142142
```
143143

144+
### Client Lifetimes
144145

146+
Both the authentication and authorization clients are registered as singletons and are suitable for injection into any other lifetime.
145147

146148
### Samples
147149

148150
Both a .NET Generic Host and ASP.NET Core example are available in the [samples](https://github.com/Hawxy/Auth0Net.DependencyInjection/tree/main/samples) directory.
149151
150152
### Internal Cache
151153

152-
The `Auth0TokenCache` will cache a token for a given audience until 30 minutes before expiry. You can increase or decrease this by setting the `TokenExpiryBuffer` on the `Auth0Configuration`.
154+
The `Auth0TokenCache` will cache a token for a given audience until at least 95% of the expiry time. If a request to the cache is made between 95% and 99% of expiry, the token will be refreshed in the background before expiry is reached.
155+
156+
An additional 1% of lifetime is removed to protect against clock drift between distributed systems.
153157

154158
In some situations you might want to request an access token from Auth0 manually. You can achieve this by injecting `IAuth0TokenCache` into a class and calling `GetTokenAsync` with the audience of the API you're requesting the token for.
155159

160+
An in-memory-only instance of [FusionCache](https://github.com/ZiggyCreatures/FusionCache) is used as the caching implementation. This instance is _named_ and will not impact other usages of FusionCache.
161+
156162
### Utility
157163

158164
This library exposes a simple string extension, `ToHttpsUrl()`, that can be used to format the naked Auth0 domain sitting in your configuration into a proper URL.

build.cmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/build.sh "$@"
4+
:; exit $?
5+
6+
@ECHO OFF
7+
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

build.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4+
[string[]]$BuildArguments
5+
)
6+
7+
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
8+
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
10+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
11+
12+
###########################################################################
13+
# CONFIGURATION
14+
###########################################################################
15+
16+
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
17+
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
18+
19+
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
20+
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
21+
$DotNetChannel = "STS"
22+
23+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
24+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
26+
27+
###########################################################################
28+
# EXECUTION
29+
###########################################################################
30+
31+
function ExecSafe([scriptblock] $cmd) {
32+
& $cmd
33+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
34+
}
35+
36+
# If dotnet CLI is installed globally and it matches requested version, use for execution
37+
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
38+
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
39+
$env:DOTNET_EXE = (Get-Command "dotnet").Path
40+
}
41+
else {
42+
# Download install script
43+
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
44+
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
45+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
46+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
47+
48+
# If global.json exists, load expected version
49+
if (Test-Path $DotNetGlobalFile) {
50+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
51+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
52+
$DotNetVersion = $DotNetGlobal.sdk.version
53+
}
54+
}
55+
56+
# Install by channel or version
57+
$DotNetDirectory = "$TempDirectory\dotnet-win"
58+
if (!(Test-Path variable:DotNetVersion)) {
59+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
60+
} else {
61+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
62+
}
63+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
64+
}
65+
66+
Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"
67+
68+
if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
69+
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
70+
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
71+
}
72+
73+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
74+
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

0 commit comments

Comments
 (0)