Blog Posts for: Aspnet5

Resolve your DbContext as an interface using the ASP.NET 5 dependency injection framework

19 May 2015

When developing ASP.NET applications, I prefer to have my database context implement an interface and then inject the interface, as this allows me to more easily mock the database context during unit tests. So in a typical application, I would do something like this: public interface IApplicationDbContext { DbSet<Episode> Episodes { get; set; } DbSet<ApplicationUser> Users { get; set; } int SaveChanges(); Task<int> SaveChangesAsync(CancellationToken cancellationToken); } public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IApplicationDbContext { public virtual DbSet<Episode> Episodes { get; set; } public ApplicationDbContext() { .

Advanced configuration in the ASP.NET 5 Generic OAuth Provider

21 April 2015

Introduction In my previous blog post I introduced the new generic OAuth 2 authentication provider which has been added to ASP.NET 5 by showing you how to configure it to authenticate with GitHub. In this blog post I will discuss two more advanced configuration options, namely requesting extra permissions via the Scope, and retrieving user information after authorization. The code I use in this blog post is mostly a straight forward copy-and-paste exercise from the sample in the ASP.

An introduction to the ASP.NET 5 Generic OAuth Provider

14 April 2015

Introduction Over the past 2 years I have been involved in the OWin Authentication Providers project, which enables developers to allow users of their ASP.NET applications to sign in with a wide range of services such as GitHub, LinkedIn, Yahoo and others. It started off with a blog post on how to allow users to sign in with their Google+ accounts via OAuth, and then it went on to LinkedIn and Yahoo and before long a Nuget package was born and the number of providers grew to where it stands at 23 today.