当前位置: 首页>>代码示例>>C#>>正文


C# IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication方法代码示例

本文整理汇总了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");
                    }
                }
            });
        }
开发者ID:Xamarui,项目名称:Katana,代码行数:30,代码来源:WaadAuthentication.cs

示例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);
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:25,代码来源:Startup.cs

示例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);
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:30,代码来源:Startup.cs

示例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
                    }
                });
        }
开发者ID:magoroku15,项目名称:azure-iot-predictive-maintenance,代码行数:56,代码来源:Startup.Auth.cs

示例6: ConfigureAuth

 public void ConfigureAuth(IAppBuilder app)
 {
     app.UseWindowsAzureActiveDirectoryBearerAuthentication(
         new WindowsAzureActiveDirectoryBearerAuthenticationOptions
         {
             Audience = SettingsHelper.ClientId,
             Tenant = SettingsHelper.Tenant,
             TokenValidationParameters = new TokenValidationParameters { SaveSigninToken = true }
         });
 }
开发者ID:spmpadmin,项目名称:O365-CORS-VisualStudio,代码行数:10,代码来源:Startup.Auth.cs

示例7: Configuration

 public void Configuration(IAppBuilder app)
 {
     app.UseWindowsAzureActiveDirectoryBearerAuthentication(
                 new WindowsAzureActiveDirectoryBearerAuthenticationOptions
                 {
                     Audience = "https://SalesApplication.onmicrosoft.com/NancyDemoServer",
                     Tenant = "SalesApplication.onmicrosoft.com"
                 })
               .UseNancy();
 }
开发者ID:TheFastCat,项目名称:OWINKatanaExamples,代码行数:10,代码来源:Startup.cs

示例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 }
         });
 }
开发者ID:modulexcite,项目名称:Office-365-AppChrome-Control,代码行数:10,代码来源:Startup.Auth.cs

示例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 }
         });
 }
开发者ID:ThomasMasuth,项目名称:WebAPI-OnBehalfOf-DotNet,代码行数:11,代码来源:Startup.Auth.cs

示例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"
                });
        }
开发者ID:cleancodenz,项目名称:WebAPI,代码行数:11,代码来源:Startup.Auth.cs

示例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,
             },
         });
 }
开发者ID:farukc,项目名称:Dash,代码行数:12,代码来源:Startup.Auth.cs

示例12: Configuration

 public void Configuration(IAppBuilder app)
 {
     app.UseWindowsAzureActiveDirectoryBearerAuthentication(
         new WindowsAzureActiveDirectoryBearerAuthenticationOptions
         {
             TokenValidationParameters = new TokenValidationParameters
             {
                 ValidAudience = ConfigurationManager.AppSettings["ida:AudienceUri"]
             },
             Tenant = ConfigurationManager.AppSettings["AzureADTenant"]
         });
 }
开发者ID:robdmoore,项目名称:AzureAdMvcExample,代码行数:12,代码来源:Startup.cs

示例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"]
         });
 }
开发者ID:modulexcite,项目名称:AzureActiveDirectory-NativeClient,代码行数:12,代码来源:Startup.cs

示例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);
			//		//	}

			//		//}

			//	});
		}
开发者ID:jacobladams,项目名称:AzureADAngularSample,代码行数:53,代码来源:Startup.Auth.cs

示例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"]
             },
         });
 }
开发者ID:crai9,项目名称:MP3-Shortener,代码行数:14,代码来源:Startup.Auth.cs


注:本文中的IAppBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。