-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements GitHub authentication for the website mostly based of the model here https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/tree/dev/samples/Mvc.Client
- Loading branch information
Showing
8 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using AspNet.Security.OAuth.GitHub; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Auth | ||
{ | ||
internal static class Extensions | ||
{ | ||
internal static async Task<AuthenticationScheme> GetGitHubAuthenticationSchemeAsync(this HttpContext httpContext) | ||
{ | ||
var provider = httpContext.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>(); | ||
var scheme = await provider.GetSchemeAsync(GitHubAuthenticationDefaults.AuthenticationScheme); | ||
return scheme; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@page | ||
@model SignInModel | ||
|
||
<div class="jumbotron"> | ||
<h1>Authentication</h1> | ||
<p class="lead text-left">Sign in using GitHub</p> | ||
|
||
<form method="post"> | ||
<input type="hidden" name="Provider" value="@Model.AuthenticationScheme.Name" /> | ||
<input type="hidden" name="ReturnUrl" value="@ViewBag.ReturnUrl" /> | ||
|
||
<button class="btn btn-lg btn-success m-1" type="submit">Authenticate</button> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AspNet.Security.OAuth.GitHub; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Auth.Pages | ||
{ | ||
public class SignInModel : PageModel | ||
{ | ||
public AuthenticationScheme AuthenticationScheme { get; set; } | ||
|
||
public async Task OnGetAsync() | ||
{ | ||
AuthenticationScheme = await HttpContext.GetGitHubAuthenticationSchemeAsync(); | ||
} | ||
|
||
public IActionResult OnPost() | ||
{ | ||
return Challenge( | ||
new AuthenticationProperties() | ||
{ | ||
RedirectUri = "/" | ||
}, | ||
GitHubAuthenticationDefaults.AuthenticationScheme); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@page | ||
@model SignOutModel | ||
|
||
<h1>Signing out ...</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AspNet.Security.OAuth.GitHub; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authentication.Cookies; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Auth.Pages | ||
{ | ||
public class SignOutModel : PageModel | ||
{ | ||
public IActionResult OnGet() => | ||
SignOut( | ||
new AuthenticationProperties() | ||
{ | ||
RedirectUri = "/" | ||
}, | ||
CookieAuthenticationDefaults.AuthenticationScheme); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters