本文整理汇总了C#中IAppBuilder.UseWsFederationAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseWsFederationAuthentication方法的具体用法?C# IAppBuilder.UseWsFederationAuthentication怎么用?C# IAppBuilder.UseWsFederationAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseWsFederationAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public override void Configure(IAppBuilder app)
{
if (String.IsNullOrEmpty(FederationSettings.MetadataAddress))
{
throw new ArgumentException("Missing federation declaration in config", "FederationMetadataAddress");
}
if (String.IsNullOrEmpty(FederationSettings.Realm))
{
throw new ArgumentException("Missing federation declaration in config", "FederationRealm");
}
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = FederationSettings.MetadataAddress,
Wtrealm = FederationSettings.Realm,
Notifications = new WsFederationAuthenticationNotifications()
{
RedirectToIdentityProvider = (context) =>
{
if (context.OwinContext.Response.StatusCode == (int)HttpStatusCode.Unauthorized && context.Request.Headers.ContainsKey("AuthNoRedirect"))
{
context.HandleResponse();
}
return Task.FromResult(0);
}
}
});
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider()
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = String.Format("https://{0}/wsfed/{1}/FederationMetadata/2007-06/FederationMetadata.xml",
ConfigurationManager.AppSettings["auth0:Domain"],
ConfigurationManager.AppSettings["auth0:ClientId"]),
Wtrealm = "urn:" + ConfigurationManager.AppSettings["auth0:ApplicationName"],
Notifications = new WsFederationAuthenticationNotifications
{
SecurityTokenValidated = notification =>
{
notification.AuthenticationTicket.Identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "Auth0"));
return Task.FromResult(true);
}
}
});
}
示例3: ConfigureAuth
public void ConfigureAuth(IAppBuilder app, IConfigurationProvider configProvider)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
// Primary authentication method for web site to Azure AD via the WsFederation below
app.UseCookieAuthentication(new CookieAuthenticationOptions());
string federationMetadataAddress = configProvider.GetConfigurationSettingValue("ida.FederationMetadataAddress");
string federationRealm = configProvider.GetConfigurationSettingValue("ida.FederationRealm");
if (string.IsNullOrEmpty(federationMetadataAddress) || string.IsNullOrEmpty(federationRealm))
{
throw new ApplicationException("Config issue: Unable to load required federation values from web.config or other configuration source.");
}
// check for default values that will cause app to fail to startup with an unhelpful 404 exception
if (federationMetadataAddress.StartsWith("-- ", StringComparison.Ordinal) ||
federationRealm.StartsWith("-- ", StringComparison.Ordinal))
{
throw new ApplicationException("Config issue: Default federation values from web.config need to be overridden or replaced.");
}
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = federationMetadataAddress,
Wtrealm = federationRealm
});
string aadTenant = configProvider.GetConfigurationSettingValue("ida.AADTenant");
string aadAudience = configProvider.GetConfigurationSettingValue("ida.AADAudience");
if (string.IsNullOrEmpty(aadTenant) || string.IsNullOrEmpty(aadAudience))
{
throw new ApplicationException("Config issue: Unable to load required AAD values from web.config or other configuration source.");
}
// check for default values that will cause failure
if (aadTenant.StartsWith("-- ", StringComparison.Ordinal) ||
aadAudience.StartsWith("-- ", StringComparison.Ordinal))
{
throw new ApplicationException("Config issue: Default AAD values from web.config need to be overridden or replaced.");
}
// Fallback authentication method to allow "Authorization: Bearer <token>" in the header for WebAPI calls
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = aadTenant,
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = aadAudience,
RoleClaimType = "http://schemas.microsoft.com/identity/claims/scope" // Used to unwrap token roles and provide them to [Authorize(Roles="")] attributes
}
});
}
示例4: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
}
示例5: ConfigureWsFederationAuth
public void ConfigureWsFederationAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
AuthenticationType = FedAuth,
Wtrealm = ConfigurationManager.AppSettings["app:URI"],
MetadataAddress = ConfigurationManager.AppSettings["wsFederation:MetadataEndpoint"],
});
}
示例6: ConfigureIdentityProviders
private void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
{
var wsFederation = new WsFederationAuthenticationOptions
{
AuthenticationType = "windows",
Caption = "Windows",
SignInAsAuthenticationType = signInAsType,
MetadataAddress = "https://localhost:44333/windows",
Wtrealm = "urn:idsrv3"
};
app.UseWsFederationAuthentication(wsFederation);
}
示例7: ConfigureAdditionalIdentityProviders
public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType)
{
var windowsAuthentication = new WsFederationAuthenticationOptions
{
AuthenticationType = "windows",
Caption = "Windows",
SignInAsAuthenticationType = signInAsType,
MetadataAddress = GlobalConfiguration.WinAdMetadataUri.ToString(),
Wtrealm = "urn:idsrv3",
Wreply = $"{GlobalConfiguration.AuthorityRoute}/callback",
Notifications = GetWsFedAuthNotifications()
};
app.UseWsFederationAuthentication(windowsAuthentication);
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = "http://localhost:29702/FederationMetadata",
Wtrealm = "urn:SupaDoopaRealm",
Wreply = "http://localhost:16635/"
}
);
}
示例9: Configuration
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = MVC_Owin_WsFederation.Configuration.CFS_METADATA,
Wtrealm = MVC_Owin_WsFederation.Configuration.CFS_RP_REALM,
SignInAsAuthenticationType = "Cookies"
});
}
示例10: Configuration
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = Constants.BaseAddress + "/wsfed/metadata",
Wtrealm = "urn:owinrp",
SignInAsAuthenticationType = "Cookies"
});
}
示例11: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = UserAccountType.External,
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = UserAccountType.Twitter,
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
});
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active
});
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = ConfigurationManager.AppSettings["FederationMetadataAddress"],
Wtrealm = ConfigurationManager.AppSettings["FederationWtrealm"],
SignInAsAuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
});
app.UseTwitterAuthentication(
new TwitterAuthenticationOptions
{
ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"],
Provider = new Microsoft.Owin.Security.Twitter.TwitterAuthenticationProvider
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new Claim("urn:twitter:accesstoken", context.AccessToken));
context.Identity.AddClaim(new Claim("urn:twitter:accesstokensecret", context.AccessTokenSecret));
}
},
SignInAsAuthenticationType = UserAccountType.External
});
}
示例12: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
var notifications = new WsFederationAuthenticationNotifications
{
SecurityTokenReceived = (context) =>
{
Debug.WriteLine("SecurityTokenReceived");
return Task.CompletedTask;
},
AuthenticationFailed = (context) =>
{
Debug.WriteLine("AuthenticationFailed");
return Task.CompletedTask;
},
MessageReceived = (context) =>
{
Debug.WriteLine("MessageReceived");
return Task.CompletedTask;
},
RedirectToIdentityProvider = (context) =>
{
Debug.WriteLine("RedirectToIdentityProvider");
return Task.CompletedTask;
},
SecurityTokenValidated = (context) =>
{
Debug.WriteLine("SecurityTokenValidated");
return Task.CompletedTask;
}
};
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Notifications = notifications,
Wtrealm = _realm,
MetadataAddress = _adfsMetadata
});
}
示例13: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType =
CookieAuthenticationDefaults.AuthenticationType
});
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = "https://login.microsoftonline.com/2c2a63d4-465c-464d-b7f5-6ccfd0dce5b8/federationmetadata/2007-06/federationmetadata.xml",
Wtrealm = "https://testService.local/",
});
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
}
示例14: Configuration
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = IdentityUrl + "/wsfed/metadata",
Wtrealm = ServerUrl,
SignOutWreply = ServerUrl,
SignInAsAuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
UseTokenLifetime = false,
Notifications = new WsFederationAuthenticationNotifications
{
RedirectToIdentityProvider = ctx =>
{
if (ctx.OwinContext.Response.StatusCode == 401 &&
ctx.OwinContext.Authentication.User.Identity.IsAuthenticated)
{
ctx.OwinContext.Response.StatusCode = 403;
ctx.HandleResponse();
}
return Task.FromResult(0);
},
SecurityTokenValidated = ctx =>
{
//ctx.AuthenticationTicket.Properties.IsPersistent = true; //Always False. Will remember when closing browser, but should only happen when user ticks Remember Me
var isPersistent = ctx.AuthenticationTicket.Properties.IsPersistent;//Should vary based on remember me-checkbox?
var redirectUri = new Uri(ctx.AuthenticationTicket.Properties.RedirectUri, UriKind.RelativeOrAbsolute);
if (redirectUri.IsAbsoluteUri)
ctx.AuthenticationTicket.Properties.RedirectUri = redirectUri.PathAndQuery;
return Task.FromResult(0);
}
}
});
app.UseStageMarker(PipelineStage.Authenticate);
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;
}
示例15: Configuration
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions {AuthenticationType = "cookies"});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
Wtrealm = "urn:encryptedrealmV2",
MetadataAddress = "https://localhost:44388/wsfed/metadata",
Wreply = "https://localhost:44344/",
SignInAsAuthenticationType = "cookies",
TokenValidationParameters = new TokenValidationParameters
{
AuthenticationType = "cookies",
ClientDecryptionTokens =
new ReadOnlyCollection<SecurityToken>(new List<SecurityToken>
{
new X509SecurityToken(Cert.LoadEncrypting())
})
}
});
}