本文整理汇总了C#中IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication方法的具体用法?C# IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication怎么用?C# IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaadAuthenticationWithProviderConfiguration
public void WaadAuthenticationWithProviderConfiguration(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters() { ValidAudience = "http://localhost/redirectUri" },
Tenant = "4afbc689-805b-48cf-a24c-d4aa3248a248",
BackchannelCertificateValidator = new WaadCertificateValidator(),
BackchannelHttpHandler = new WaadChannelHttpHandler(),
});
app.Run(async context =>
{
if (context.Authentication.User == null || !context.Authentication.User.Identity.IsAuthenticated)
{
context.Authentication.Challenge("Bearer");
await context.Response.WriteAsync("Unauthorized");
}
else
{
if (!context.Get<bool>("OnRequestToken") || !context.Get<bool>("OnValidateIdentity"))
{
await context.Response.WriteAsync("Provider not invoked");
}
else
{
await context.Response.WriteAsync("Bearer");
}
}
});
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
string audience = ConfigurationManager.AppSettings["ida:Audience"];
string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
if (!string.IsNullOrWhiteSpace(audience))
{
string metadataAddress = string.Format(aadInstance, tenant) + "/federationmetadata/2007-06/federationmetadata.xml";
app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = audience,
ValidateIssuer = true,
IssuerValidator = (string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters) => { return issuer; }
},
Tenant = tenant,
MetadataAddress = metadataAddress
});
}
app.Run(Invoke);
}
示例3: Configuration
public void Configuration(IAppBuilder app)
{
if (!HasNoSecurityConfigured())
{
Trace.TraceInformation("Using AAD middleware");
string audience = _configurationService.Get("ida.Audience");
string tenant = _configurationService.Get("ida.Tenant");
string aadInstance = _configurationService.Get("ida.AADInstance");
string metadataAddress = string.Format(aadInstance, tenant) + "/federationmetadata/2007-06/federationmetadata.xml";
app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true,
ValidAudience = audience,
ValidateIssuer = true,
IssuerValidator = (string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters) => { return issuer; }
},
Tenant = tenant,
MetadataAddress = metadataAddress
});
}
Initialize();
app.Run(Invoke);
}
示例4: ConfigureAuth
public void ConfigureAuth(IAppBuilder app) {
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
});
}
开发者ID:pastrywhipped,项目名称:active-directory-javascript-singlepageapp-dotnet-webapi,代码行数:9,代码来源:Startup.Auth.cs
示例5: 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
}
});
}
示例6: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = SettingsHelper.ClientId,
Tenant = SettingsHelper.Tenant,
TokenValidationParameters = new TokenValidationParameters { SaveSigninToken = true }
});
}
示例7: Configuration
public void Configuration(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = "https://SalesApplication.onmicrosoft.com/NancyDemoServer",
Tenant = "SalesApplication.onmicrosoft.com"
})
.UseNancy();
}
示例8: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters() { ValidateIssuer = false }
});
}
示例9: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters{ SaveSigninToken = true }
});
}
示例10: ConfigAuth
public void ConfigAuth(IAppBuilder app)
{
// Asks for the bearer token issed by http://AzureADOpenIdWebApi.JohnsonAzureAD.onmicrosoft.com
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions()
{
Audience = "http://AzureADOpenIdWebApi.JohnsonAzureAD.onmicrosoft.com",
Tenant = "JohnsonAzureAD.onmicrosoft.com"
});
}
示例11: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = DashConfiguration.Tenant,
TokenValidationParameters = new TokenValidationParameters {
ValidAudience = DashConfiguration.ClientId,
},
});
}
示例12: Configuration
public void Configuration(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = ConfigurationManager.AppSettings["ida:AudienceUri"]
},
Tenant = ConfigurationManager.AppSettings["AzureADTenant"]
});
}
示例13: ConfigureAuth
private void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters()
{
ValidAudience = ConfigurationManager.AppSettings["Audience"] ,
},
Tenant = ConfigurationManager.AppSettings["Tenant"]
});
}
示例14: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
});
//app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
//app.UseCookieAuthentication(new CookieAuthenticationOptions());
//app.UseOpenIdConnectAuthentication(
// new OpenIdConnectAuthenticationOptions
// {
// ClientId = clientId,
// Authority = Authority,
// //PostLogoutRedirectUri = postLogoutRedirectUri,
// //Notifications = new OpenIdConnectAuthenticationNotifications()
// //{
// // //
// // // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
// // //
// // AuthorizationCodeReceived = (context) =>
// // {
// // var code = context.Code;
// // ClientCredential credential = new ClientCredential(clientId, appKey);
// // string userObjectID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
// // //AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
// // AuthenticationContext authContext = new AuthenticationContext(Authority);
// // //AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
// // return Task.FromResult(0);
// // },
// // AuthenticationFailed = context =>
// // {
// // context.HandleResponse();
// // context.Response.Redirect("/Home/Error?message=" + context.Exception.Message);
// // return Task.FromResult(0);
// // }
// //}
// });
}
示例15: ConfigureAuth
//Confgire the authentication for the controllers.
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
//Use the AD details to define how users are authenticated.
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});
}