You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.4 KiB
28 lines
1.4 KiB
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
|
using Microsoft.AspNetCore.Http.Authentication;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Mvc.Client.Controllers {
|
|
public class AuthenticationController : Controller {
|
|
[HttpGet("~/signin")]
|
|
public ActionResult SignIn() {
|
|
// Instruct the OIDC client middleware to redirect the user agent to the identity provider.
|
|
// Note: the authenticationType parameter must match the value configured in Startup.cs
|
|
return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties {
|
|
RedirectUri = "/"
|
|
});
|
|
}
|
|
|
|
[HttpGet("~/signout"), HttpPost("~/signout")]
|
|
public async Task SignOut() {
|
|
// Instruct the cookies middleware to delete the local cookie created when the user agent
|
|
// is redirected from the identity provider after a successful authorization flow.
|
|
await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
|
|
// Instruct the OpenID Connect middleware to redirect the user agent to the identity provider to sign out.
|
|
await HttpContext.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
|
|
}
|
|
}
|
|
}
|