Skip to content

Commit

Permalink
Remove unnecessary NuGet dependencies from the ASP.NET 4.8 samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Feb 20, 2024
1 parent 89cdcd8 commit b70997b
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 153 deletions.
4 changes: 0 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@
<PackageVersion Include="Microsoft.Owin.Host.SystemWeb" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Hosting" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.Cookies" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.Google" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.MicrosoftAccount" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.OAuth" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.OpenIdConnect" Version="4.2.2" />
<PackageVersion Include="Microsoft.Owin.Security.Twitter" Version="4.2.2" />
<PackageVersion Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageVersion Include="OpenIddict.EntityFramework" Version="5.2.0" />
<PackageVersion Include="OpenIddict.Owin" Version="5.2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<ActionResult> LogInCallback()
// a few claims like the user identifier. The same approach is used to store the access/refresh tokens.

// Important: if the remote server doesn't support OpenID Connect and doesn't expose a userinfo endpoint,
// result.Principal.Identity will represent an unauthenticated identity and won't contain any claim.
// result.Principal.Identity will represent an unauthenticated identity and won't contain any user claim.
//
// Such identities cannot be used as-is to build an authentication cookie in ASP.NET Core (as the
// antiforgery stack requires at least a name claim to bind CSRF cookies to the user's identity) but
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<ActionResult> LogInCallback()
// a few claims like the user identifier. The same approach is used to store the access/refresh tokens.

// Important: if the remote server doesn't support OpenID Connect and doesn't expose a userinfo endpoint,
// result.Principal.Identity will represent an unauthenticated identity and won't contain any claim.
// result.Principal.Identity will represent an unauthenticated identity and won't contain any user claim.
//
// Such identities cannot be used as-is to build an authentication cookie in ASP.NET Core (as the
// antiforgery stack requires at least a name claim to bind CSRF cookies to the user's identity) but
Expand Down
66 changes: 0 additions & 66 deletions samples/Fornax/Fornax.Server/App_Start/Startup.Auth.cs

This file was deleted.

3 changes: 0 additions & 3 deletions samples/Fornax/Fornax.Server/Fornax.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Owin.Host.SystemWeb" />
<PackageReference Include="Microsoft.Owin.Security.Cookies" />
<PackageReference Include="Microsoft.Owin.Security.Google" />
<PackageReference Include="Microsoft.Owin.Security.MicrosoftAccount" />
<PackageReference Include="Microsoft.Owin.Security.OAuth" />
<PackageReference Include="Microsoft.Owin.Security.Twitter" />
<PackageReference Include="Microsoft.Web.Infrastructure" PrivateAssets="all" />
<PackageReference Include="OpenIddict.EntityFramework" />
<PackageReference Include="OpenIddict.Owin" />
Expand Down
31 changes: 28 additions & 3 deletions samples/Fornax/Fornax.Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Microsoft.Owin;
using System;
using Fornax.Server.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using OpenIddict.Server.Owin;
using OpenIddict.Validation.Owin;
using Owin;
Expand All @@ -7,11 +12,31 @@

namespace Fornax.Server
{
public partial class Startup
public class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
// Register the Entity Framework context and the user/sign-in managers used by ASP.NET Identity.
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

// Register the cookie middleware used by ASP.NET Identity.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

// Register the Autofac scope injector middleware.
app.UseAutofacLifetimeScopeInjector(Global.Provider.ApplicationContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<ActionResult> LogInCallback()
// a few claims like the user identifier. The same approach is used to store the access/refresh tokens.

// Important: if the remote server doesn't support OpenID Connect and doesn't expose a userinfo endpoint,
// result.Principal.Identity will represent an unauthenticated identity and won't contain any claim.
// result.Principal.Identity will represent an unauthenticated identity and won't contain any user claim.
//
// Such identities cannot be used as-is to build an authentication cookie in ASP.NET (as the
// antiforgery stack requires at least a name claim to bind CSRF cookies to the user's identity) but
Expand Down
2 changes: 1 addition & 1 deletion samples/Mortis/Mortis.Client/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Mortis.Client
{
public partial class Startup
public class Startup
{
public void Configuration(IAppBuilder app)
{
Expand Down
66 changes: 0 additions & 66 deletions samples/Mortis/Mortis.Server/App_Start/Startup.Auth.cs

This file was deleted.

3 changes: 0 additions & 3 deletions samples/Mortis/Mortis.Server/Mortis.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Owin.Host.SystemWeb" />
<PackageReference Include="Microsoft.Owin.Security.Cookies" />
<PackageReference Include="Microsoft.Owin.Security.Google" />
<PackageReference Include="Microsoft.Owin.Security.MicrosoftAccount" />
<PackageReference Include="Microsoft.Owin.Security.OAuth" />
<PackageReference Include="Microsoft.Owin.Security.Twitter" />
<PackageReference Include="Microsoft.Web.Infrastructure" PrivateAssets="all" />
<PackageReference Include="OpenIddict.EntityFramework" />
<PackageReference Include="OpenIddict.Owin" />
Expand Down
27 changes: 25 additions & 2 deletions samples/Mortis/Mortis.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using Autofac.Extensions.DependencyInjection;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Mortis.Server.Models;
using OpenIddict.Abstractions;
using OpenIddict.Server.Owin;
Expand All @@ -18,7 +21,7 @@
[assembly: OwinStartup(typeof(Mortis.Server.Startup))]
namespace Mortis.Server
{
public partial class Startup
public class Startup
{
public void Configuration(IAppBuilder app)
{
Expand Down Expand Up @@ -83,7 +86,27 @@ public void Configuration(IAppBuilder app)

var container = builder.Build();

ConfigureAuth(app);
// Register the Entity Framework context and the user/sign-in managers used by ASP.NET Identity.
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

// Register the cookie middleware used by ASP.NET Identity.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

// Register the Autofac scope injector middleware.
app.UseAutofacLifetimeScopeInjector(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<ActionResult> LogInCallback()
// a few claims like the user identifier. The same approach is used to store the access/refresh tokens.

// Important: if the remote server doesn't support OpenID Connect and doesn't expose a userinfo endpoint,
// result.Principal.Identity will represent an unauthenticated identity and won't contain any claim.
// result.Principal.Identity will represent an unauthenticated identity and won't contain any user claim.
//
// Such identities cannot be used as-is to build an authentication cookie in ASP.NET Core (as the
// antiforgery stack requires at least a name claim to bind CSRF cookies to the user's identity) but
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<ActionResult> LogInCallback()
// a few claims like the user identifier. The same approach is used to store the access/refresh tokens.

// Important: if the remote server doesn't support OpenID Connect and doesn't expose a userinfo endpoint,
// result.Principal.Identity will represent an unauthenticated identity and won't contain any claim.
// result.Principal.Identity will represent an unauthenticated identity and won't contain any user claim.
//
// Such identities cannot be used as-is to build an authentication cookie in ASP.NET Core (as the
// antiforgery stack requires at least a name claim to bind CSRF cookies to the user's identity) but
Expand Down

0 comments on commit b70997b

Please sign in to comment.