ASP.NET Monsters #26: GitHub Authentication in ASP.NET Core

Download this episode

Download Video

Description

When your primary market is fellow developers, having GitHub authentication is a great way to allow your users to engage with your site without requiring them to sign up on yours, while still providing a means to create and manage user-specific data in your application.

In this episode, Monster James walks us through the process of getting GitHub authentication working in an ASP.NET Core application using the OAuth authentication provider. 

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      TheJayMann

      I see you mentioned that you cannot specify custom scopes using the OAuthOptions.  However, looking at the definition of Scope, it is defined as ICollection<string>.  This class has a method defined as Add(string item), which you can use to add scopes to the options.  This means, once you have created your OAuthOptions object, you can simply use options.Scopes.Add(scope1), options.Scopes.Add(scope2), etc.  You can even wrap this in an extension method, along the lines:

      public OAuthOptions WithScopes(this OAuthOptions options, params string[] scopes) {
      foreach(var scope in scopes) {
      options.Scopes.Add(scope);
      }
      }

      Or, if you prefer to fully use object initializers, you can still use a collection initializer without specifying the new portion, i.e.:

      new OAuthOptions() {
      ClientId = GetClientId(),
      ClientSecret = GetClientSecret(),
      // Set other important properties here
      Scopes = {
      "scope1",
      "scope2",
      "etc",
      }
      }

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.