You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using Owin;
using System.Configuration;
using System.Globalization;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Threading.Tasks;
[assembly:OwinStartup(typeof(BrowserToWebApp.App_Start.Startup))]
Namespace BrowserToWebApp.App_Start
{
public class Startup
{
private static string clientId = ConfigurationManager.AppSettings[“ida:ClientId”];
private static string aaInstance = ConfigurationManager.AppSettings[“ida:AADInstance”];
private static string tenant = ConfigurationManager.AppSettings[“ida:Tenant”];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings[“ida:PostLogoutRedirectUri”];
string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
{
ClientId = clientId;
Authority = authority;
PostLogoutRedirectUri = postLogoutRedirectUri;
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandledResponse();
context.Response.Redirect($“/Error/messsage={context.Exception.Message}”);
return Task.FromResult(0);
}
}
});
}
}
}
In controller
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
Public void SignIn()
{
if(!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties{ RedirectUri = “/“}, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
Public void SignOut()
{
HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
);
}