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

Declare all console clients as native applications and update the Fornax client to target .NET Framework 4.8 #295

Merged
merged 1 commit into from
Feb 20, 2024
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
7 changes: 6 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
<PackageVersion Include="Microsoft.AspNet.Web.Optimization.WebForms" Version="1.1.3" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Owin" Version="5.3.0" />
<PackageVersion Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="4.1.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.14" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="2.1.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.8.0" />
<PackageVersion Include="Microsoft.Owin.Diagnostics" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Host.HttpListener" Version="4.2.2" />
Expand All @@ -42,7 +44,10 @@
<PackageVersion Include="Microsoft.Owin.Security.Cookies" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.OAuth" Version="4.2.2" />
<PackageVersion Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageVersion Include="OpenIddict.Client.SystemIntegration" Version="5.2.0" />
<PackageVersion Include="OpenIddict.Client.SystemNetHttp" Version="5.2.0" />
<PackageVersion Include="OpenIddict.EntityFramework" Version="5.2.0" />
<PackageVersion Include="OpenIddict.EntityFrameworkCore" Version="5.2.0" />
<PackageVersion Include="OpenIddict.Owin" Version="5.2.0" />
<PackageVersion Include="WebGrease" Version="1.6.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This repository contains samples demonstrating **how to use [OpenIddict](https:/
- [Sorgan](samples/Sorgan): Windows Forms, Windows Presentation Foundation and Blazor Hybrid clients using GitHub for user authentication.

## OWIN/ASP.NET 4.8 samples
- [Fornax](samples/Fornax): authorization code flow demo using ASP.NET Web Forms 4.8 and OWIN/Katana, with a .NET console acting as the client.
- [Fornax](samples/Fornax): authorization code flow demo using ASP.NET Web Forms 4.8 and OWIN/Katana, with a .NET Framework 4.8 console acting as the client.
- [Mortis](samples/Mortis): authorization code flow demo, with an ASP.NET MVC 5.2 application acting as the client.
- [Kalarba](samples/Kalarba): resource owner password credentials demo using OWIN/Katana, ASP.NET Web API and the OpenIddict degraded mode.

Expand Down
4 changes: 2 additions & 2 deletions samples/Fornax/Fornax.Client/Fornax.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" />
<PackageReference Include="OpenIddict.Client.SystemIntegration" />
<PackageReference Include="OpenIddict.Client.SystemNetHttp" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" />
Expand Down
21 changes: 18 additions & 3 deletions samples/Fornax/Fornax.Client/InteractiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Fornax.Client;

public class InteractiveService : BackgroundService
{
private readonly IHostApplicationLifetime _lifetime;
private readonly IApplicationLifetime _lifetime;
private readonly OpenIddictClientService _service;

public InteractiveService(
IHostApplicationLifetime lifetime,
IApplicationLifetime lifetime,
OpenIddictClientService service)
{
_lifetime = lifetime;
Expand All @@ -31,7 +31,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}

Console.WriteLine("Press any key to start the authentication process.");
await Task.Run(Console.ReadKey).WaitAsync(stoppingToken);
await WaitAsync(Task.Run(Console.ReadKey, stoppingToken), stoppingToken);

try
{
Expand Down Expand Up @@ -76,5 +76,20 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Console.WriteLine("An error occurred while trying to authenticate the user.");
}

static async Task<T> WaitAsync<T>(Task<T> task, CancellationToken cancellationToken)
{
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);

using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}

return await task;
}
}
}
}
7 changes: 5 additions & 2 deletions samples/Fornax/Fornax.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

// Add the operating system integration.
options.UseSystemIntegration()
.SetAllowedEmbeddedWebServerPorts(7891);
.SetApplicationDiscriminator("4N494SXGMTWQLZE");

// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
Expand All @@ -57,7 +57,7 @@
Issuer = new Uri("https://localhost:44387/", UriKind.Absolute),

ClientId = "console_app",
RedirectUri = new Uri("http://localhost:7891/", UriKind.Absolute)
RedirectUri = new Uri("/", UriKind.Relative)
});
});

Expand All @@ -69,6 +69,9 @@

// Register the background service responsible for handling the console interactions.
services.AddHostedService<InteractiveService>();

// Prevent the console lifetime manager from writing status messages to the output stream.
services.Configure<ConsoleLifetimeOptions>(options => options.SuppressStatusMessages = true);
})
.UseConsoleLifetime()
.Build();
Expand Down
4 changes: 3 additions & 1 deletion samples/Fornax/Fornax.Server/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ void Application_Start(object sender, EventArgs e)
{
await manager.CreateAsync(new OpenIddictApplicationDescriptor
{
ApplicationType = ApplicationTypes.Native,
ClientId = "console_app",
ClientType = ClientTypes.Public,
ConsentType = ConsentTypes.Explicit,
DisplayName = "Console application",
RedirectUris =
{
new Uri("http://localhost:7891/")
new Uri("http://localhost/")
},
Permissions =
{
Expand Down
2 changes: 1 addition & 1 deletion samples/Fornax/Fornax.Server/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=(localdb)\mssqllocaldb;Database=openiddict-fornax-sample;Trusted_Connection=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Server=(localdb)\mssqllocaldb;Database=openiddict-fornax-server;Trusted_Connection=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="None" />
Expand Down
1 change: 0 additions & 1 deletion samples/Matty/Matty.Client/Matty.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion samples/Mimban/Mimban.Client/Mimban.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions samples/Mimban/Mimban.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
.AddDevelopmentSigningCertificate();

// Add the operating system integration.
options.UseSystemIntegration()
.SetAllowedEmbeddedWebServerPorts(8914);
options.UseSystemIntegration();

// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
Expand All @@ -57,7 +56,7 @@
Issuer = new Uri("https://localhost:44383/", UriKind.Absolute),

ClientId = "console_app",
RedirectUri = new Uri("http://localhost:8914/", UriKind.Absolute)
RedirectUri = new Uri("/", UriKind.Relative)
});
});

Expand Down
4 changes: 3 additions & 1 deletion samples/Mimban/Mimban.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@
{
await manager.CreateAsync(new OpenIddictApplicationDescriptor
{
ApplicationType = ApplicationTypes.Native,
ClientId = "console_app",
ClientType = ClientTypes.Public,
RedirectUris =
{
new Uri("http://localhost:8914/")
new Uri("http://localhost/")
},
Permissions =
{
Expand Down
5 changes: 2 additions & 3 deletions samples/Weytta/Weytta.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
.AddDevelopmentSigningCertificate();

// Add the operating system integration.
options.UseSystemIntegration()
.SetAllowedEmbeddedWebServerPorts(7890);
options.UseSystemIntegration();

// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
Expand All @@ -57,7 +56,7 @@
Issuer = new Uri("https://localhost:44319/", UriKind.Absolute),

ClientId = "console_app",
RedirectUri = new Uri("http://localhost:7890/", UriKind.Absolute)
RedirectUri = new Uri("/", UriKind.Relative)
});
});

Expand Down
1 change: 0 additions & 1 deletion samples/Weytta/Weytta.Client/Weytta.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion samples/Weytta/Weytta.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
await manager.CreateAsync(new OpenIddictApplicationDescriptor
{
ApplicationType = ApplicationTypes.Native,
ClientId = "console_app",
ClientType = ClientTypes.Public,
ConsentType = ConsentTypes.Implicit,
DisplayName = "Console application",
RedirectUris =
{
new Uri("http://localhost:7890/")
new Uri("http://localhost/")
},
Permissions =
{
Expand Down
5 changes: 2 additions & 3 deletions samples/Zirku/Zirku.Client1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
.AddDevelopmentSigningCertificate();

// Add the operating system integration.
options.UseSystemIntegration()
.SetAllowedEmbeddedWebServerPorts(8739);
options.UseSystemIntegration();

// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
Expand All @@ -58,7 +57,7 @@
Issuer = new Uri("https://localhost:44319/", UriKind.Absolute),

ClientId = "console_app",
RedirectUri = new Uri("http://localhost:8739/", UriKind.Absolute),
RedirectUri = new Uri("/", UriKind.Relative),
Scopes = { Scopes.OpenId, "api1", "api2" }
});
});
Expand Down
1 change: 0 additions & 1 deletion samples/Zirku/Zirku.Client1/Zirku.Client1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion samples/Zirku/Zirku.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ async Task CreateApplicationsAsync()
{
await manager.CreateAsync(new OpenIddictApplicationDescriptor
{
ApplicationType = ApplicationTypes.Native,
ClientId = "console_app",
ClientType = ClientTypes.Public,
RedirectUris =
{
new Uri("http://localhost:8739/")
new Uri("http://localhost/")
},
Permissions =
{
Expand Down
Loading