diff --git a/.github/workflows/dotnet-release.yml b/.github/workflows/dotnet-release.yml new file mode 100644 index 0000000..4b8eb86 --- /dev/null +++ b/.github/workflows/dotnet-release.yml @@ -0,0 +1,32 @@ +name: .NET release + +on: + release: + types: [created] + +jobs: + build: + uses: bluehands/WebFinger.Server.OidcDiscovery/.github/workflows/dotnet.yml@main + publish: + runs-on: ubuntu-latest + needs: build + env: + wd: ./src/WebFinger.Server.OidcDiscovery + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: Restore dependencies + run: dotnet restore + working-directory: ${{ env.wd }} + - name: Build + run: dotnet build --no-restore --configuration Release + working-directory: ${{ env.wd }} + - name: Create the package + run: dotnet pack --configuration Release + working-directory: ${{ env.wd }} + - name: Publish the package to nuget.org + run: dotnet nuget push */bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json + env: + NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..1a8e188 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,34 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_call: + +jobs: + build: + + runs-on: ubuntu-latest + env: + wd: ./src/WebFinger.Server.OidcDiscovery + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: Restore dependencies + run: dotnet restore + working-directory: ${{ env.wd }} + - name: Build + run: dotnet build --no-restore + working-directory: ${{ env.wd }} + - name: Test + run: dotnet test --no-build --verbosity normal + working-directory: ${{ env.wd }} diff --git a/src/WebFinger.Server.OidcDiscovery/.gitignore b/src/WebFinger.Server.OidcDiscovery/.gitignore new file mode 100644 index 0000000..e39563c --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/.gitignore @@ -0,0 +1,3 @@ +**/bin/ +**/obj/ +**/.idea/ \ No newline at end of file diff --git a/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.sln b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.sln new file mode 100644 index 0000000..764a01e --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebFinger.Server.OidcDiscovery", "WebFinger.Server.OidcDiscovery\WebFinger.Server.OidcDiscovery.csproj", "{F04878F5-2433-4574-9851-E8A127887B8D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F04878F5-2433-4574-9851-E8A127887B8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F04878F5-2433-4574-9851-E8A127887B8D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F04878F5-2433-4574-9851-E8A127887B8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F04878F5-2433-4574-9851-E8A127887B8D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcConstants.cs b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcConstants.cs new file mode 100644 index 0000000..ecd97bf --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcConstants.cs @@ -0,0 +1,7 @@ +namespace WebFinger.Server.OidcDiscovery; + +public static class OidcConstants +{ + // ReSharper disable once InconsistentNaming + public const string OPENID_ISSUER_RELATION = "http://openid.net/specs/connect/1.0/issuer"; +} diff --git a/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcIssuer.cs b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcIssuer.cs new file mode 100644 index 0000000..c928c12 --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/OidcIssuer.cs @@ -0,0 +1,4 @@ +namespace WebFinger.Server.OidcDiscovery; + +// ReSharper disable once ClassNeverInstantiated.Global +public record OidcIssuer(Uri Endpoint); \ No newline at end of file diff --git a/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.csproj b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.csproj new file mode 100644 index 0000000..9028981 --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery.csproj @@ -0,0 +1,38 @@ + + + + net6.0 + enable + enable + 1.0.0 + WebFinger OpenID Connect Discovery 1.0 + An implementation of OpenID Connect Discovery 1.0 for ASP.NET Core + oidc discovery webfinger + https://github.com/bluehands/WebFinger.Server.OidcDiscovery + MIT + + https://github.com/bluehands/WebFinger.Server.OidcDiscovery.git + git + + + + + + + + + true + true + embedded + + + true + + + true + + + + + + diff --git a/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFingerOidcExtension.cs b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFingerOidcExtension.cs new file mode 100644 index 0000000..0f80677 --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/WebFinger.Server.OidcDiscovery/WebFingerOidcExtension.cs @@ -0,0 +1,46 @@ +using System.Collections.Immutable; +using DarkLink.Web.WebFinger.Server; +using DarkLink.Web.WebFinger.Shared; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; + +namespace WebFinger.Server.OidcDiscovery; + +// ReSharper disable once UnusedType.Global +public static class WebFingerOidcExtension +{ + // ReSharper disable once UnusedMember.Global + public static IServiceCollection AddOidcWebFinger(this IServiceCollection services, OidcIssuer oidcIssuer) + { + services.AddWebFinger(new OidcResourceDescriptorProvider(oidcIssuer)); + return services; + } + + private class OidcResourceDescriptorProvider : IResourceDescriptorProvider + { + private readonly OidcIssuer issuer; + + public OidcResourceDescriptorProvider(OidcIssuer issuer) + { + this.issuer = issuer; + } + + public Task GetResourceDescriptorAsync( + Uri resource, + IReadOnlyList relations, + HttpRequest request, + CancellationToken cancellationToken) => Task.FromResult(new JsonResourceDescriptor( + resource, + ImmutableList.Empty, + ImmutableDictionary.Empty, + relations.Count == 0 || relations.Contains(OidcConstants.OPENID_ISSUER_RELATION) + ? ImmutableList.Create(new Link( + OidcConstants.OPENID_ISSUER_RELATION, + default, + issuer.Endpoint, + ImmutableDictionary.Empty, + ImmutableDictionary.Empty)) + : ImmutableList.Empty + )); + } +} \ No newline at end of file diff --git a/src/WebFinger.Server.OidcDiscovery/global.json b/src/WebFinger.Server.OidcDiscovery/global.json new file mode 100644 index 0000000..1bcf6c0 --- /dev/null +++ b/src/WebFinger.Server.OidcDiscovery/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.0", + "rollForward": "latestMinor", + "allowPrerelease": false + } +} \ No newline at end of file