Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version #1

Merged
merged 11 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
34 changes: 34 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions src/WebFinger.Server.OidcDiscovery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/bin/
**/obj/
**/.idea/
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace WebFinger.Server.OidcDiscovery;

// ReSharper disable once ClassNeverInstantiated.Global
public record OidcIssuer(Uri Endpoint);
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<Title>WebFinger OpenID Connect Discovery 1.0</Title>
<Description>An implementation of OpenID Connect Discovery 1.0 for ASP.NET Core</Description>
<PackageTags>oidc discovery webfinger</PackageTags>
<PackageProjectUrl>https://github.com/bluehands/WebFinger.Server.OidcDiscovery</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- Source link requires git via https -->
<RepositoryUrl>https://github.com/bluehands/WebFinger.Server.OidcDiscovery.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DarkLink.Web.WebFinger.Server" Version="1.0.0" />
</ItemGroup>

<!-- Begin source link config. See: https://devblogs.microsoft.com/dotnet/producing-packages-with-source-link -->
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
<!-- End source link specific -->
</Project>
Original file line number Diff line number Diff line change
@@ -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<JsonResourceDescriptor?> GetResourceDescriptorAsync(
Uri resource,
IReadOnlyList<string> relations,
HttpRequest request,
CancellationToken cancellationToken) => Task.FromResult<JsonResourceDescriptor?>(new JsonResourceDescriptor(
resource,
ImmutableList<Uri>.Empty,
ImmutableDictionary<Uri, string?>.Empty,
relations.Count == 0 || relations.Contains(OidcConstants.OPENID_ISSUER_RELATION)
? ImmutableList.Create(new Link(
OidcConstants.OPENID_ISSUER_RELATION,
default,
issuer.Endpoint,
ImmutableDictionary<string, string>.Empty,
ImmutableDictionary<Uri, string?>.Empty))
: ImmutableList<Link>.Empty
));
}
}
7 changes: 7 additions & 0 deletions src/WebFinger.Server.OidcDiscovery/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}