本文整理汇总了C#中IApplicationBuilder.UseOAuthBearerAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseOAuthBearerAuthentication方法的具体用法?C# IApplicationBuilder.UseOAuthBearerAuthentication怎么用?C# IApplicationBuilder.UseOAuthBearerAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseOAuthBearerAuthentication方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var builder = new ContainerBuilder();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
//app.UseCookieAuthentication(options =>
//{
// options.AuthenticationScheme = "Temp";
// options.AutomaticAuthentication = false;
//}, "external");
// Configure the HTTP request pipeline.
//app.UseStaticFiles();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseOAuthBearerAuthentication(options =>
{
options.Authority = "https://localhost:44333/core";
//options.Authority = "https://karamaidentityserver.azurewebsites.net/core";
options.Audience = "https://karama.com/resources";
options.AutomaticAuthentication = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "api3" });
app.UseCors("AllowSpecificOrigins");
// Add MVC to the request pipeline.
app.UseMvc();
}
示例2: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseOAuthBearerAuthentication(options =>
{
options.AutomaticAuthentication = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateLifetime = false
};
options.Audience = Configuration.Get("ClientId");
options.Authority = String.Format(Configuration.Get("AadInstance"), Configuration.Get("TenantId"));
});
//app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
//Configure AutoMapper
Mapper.CreateMap<ScampResource, ScampResourceSummary>();
Mapper.CreateMap<User, UserSummary>();
Mapper.CreateMap<User, ScampUserReference>();
}
示例3: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Configure the app to use OAuth Bearer Authentication
app.UseOAuthBearerAuthentication(options =>
{
options.Audience = Configuration.Get("Auth0:ClientId");
options.Authority = "https://" + Configuration.Get("Auth0:Domain");
options.Notifications = new OAuthBearerAuthenticationNotifications
{
// OPTIONAL: you can read/modify the claims that are populated based on the JWT
// Check issue status: https://github.com/aspnet/Security/issues/140
/*SecurityTokenValidated = context =>
{
var claimsIdentity = context.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
// ensure name claim
claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, claimsIdentity.FindFirst("name").Value));
return Task.FromResult(0);
}*/
};
});
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例4: ConfigureAuth
public void ConfigureAuth(IApplicationBuilder app)
{
// Configure the app to use OAuth Bearer Authentication
app.UseOAuthBearerAuthentication(options =>
{
options.Audience = Configuration.Get("AzureAd:Audience");
options.Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
});
}
开发者ID:vansonvinhuni,项目名称:active-directory-dotnet-webapp-webapi-openidconnect-aspnet5,代码行数:9,代码来源:Startup.Auth.cs
示例5: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Configure the HTTP request pipeline.
app.UseStaticFiles();
app.UseOAuthBearerAuthentication();
// Add MVC to the request pipeline.
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
}
示例6: Configure
public void Configure(IApplicationBuilder app)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Temp";
options.AutomaticAuthentication = false;
}, "external");
app.UseMyGoogleAuthentication(options =>
{
options.ClientId = "405547628913-afp6rob22l602dembl7eqnseb9vmrbqs.apps.googleusercontent.com";
options.ClientSecret = "ENxb5ZPcOl_BHSWfUTUQecxw";
options.AuthenticationScheme = "Google";
options.SignInScheme = "Temp";
});
app.UseMyGoogleAuthentication(options =>
{
options.ClientId = "405547628913-afp6rob22l602dembl7eqnseb9vmrbqs.apps.googleusercontent.com";
options.ClientSecret = "ENxb5ZPcOl_BHSWfUTUQecxw";
options.AuthenticationScheme = "Google";
options.SignInScheme = "Temp";
});
MyFacebookAppBuilderExtensions.UseFacebookAuthentication(app, options =>
{
options.AppId = "1617509121824168";
options.AppSecret = "dc36301f5ec7a3e30adf3cb6a1a8fddc";
options.AuthenticationScheme = "Facebook";
options.SignInScheme = "Temp";
});
app.UseOAuthBearerAuthentication(options =>
{
options.Authority = "https://localhost:44333/core";
options.Audience = "https://karama.com/resources";
options.AutomaticAuthentication = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "api2" });
app.UseCors("AllowSpecificOrigins");
app.UseMvc();
}
示例7: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Register a simple error handler to catch token expiries and change them to a 401,
// and return all other errors as a 500.
app.UseErrorHandler(appBuilder =>
{
appBuilder.Use(new Func<RequestDelegate, RequestDelegate>((RequestDelegate next) =>
{
return async (HttpContext context) =>
{
var error = context.GetFeature<IErrorHandlerFeature>();
// This should be much more intelligent - at the moment only expired
// security tokens are caught - might be worth checking other possible
// exceptions such as an invalid signature.
if (error != null && error.Error is SecurityTokenExpiredException)
{
context.Response.StatusCode = 401;
// What you choose to return here is up to you, in this case a simple
// bit of JSON to say you're no longer authenticated.
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(
JsonConvert.SerializeObject(new { authenticated = false, tokenExpired = true }));
}
else if (error != null && error.Error != null)
{
context.Response.StatusCode = 500;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(
JsonConvert.SerializeObject(new { success = false, error = error.Error.Message }));
}
// We're not trying to handle any other errors so just let the default
// handler handle.
else await next(context);
};
}));
});
// ***
// NOTE: OAuthBearerAuthentication will be renamed to JwtBearerAuthentication in
// ASP.NET 5 Beta 8 - be ready to change this then!!
// ***
app.UseOAuthBearerAuthentication();
// Configure the HTTP request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc();
}
示例8: Configure
public void Configure(IApplicationBuilder app)
{
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseOAuthBearerAuthentication(options =>
{
options.Authority = "https://localhost:44300";
options.Audience = "https://localhost:44300/resources";
options.AutomaticAuthentication = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "api1" });
app.UseMvc();
}
示例9: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
app.UseStaticFiles();
var authority = Configuration["IDP_AUTHORITY"] ?? "http://localhost:44002";
var audience = $"{authority}/resources";
app.UseOAuthBearerAuthentication(options =>
{
options.Authority = authority;
options.Audience = audience;
options.AutomaticAuthentication = true;
});
app.UseMiddleware<RequiredScopesMiddleware>(new List<string> { "testapi" });
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
}
示例10: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Configure the app to use OAuth Bearer Authentication
app.UseOAuthBearerAuthentication(options =>
{
options.Audience = Configuration.Get("AzureAd:Audience");
options.Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
});
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例11: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Configure the HTTP request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
// Use OAuth bearer token
app.UseOAuthBearerAuthentication();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
//TODO: Remove this when seeding is native
var seeder = ActivatorUtilities.CreateInstance<DbSeeder>(app.ApplicationServices);
seeder.Seed();
}
示例12: Configure
public void Configure(IApplicationBuilder app)
{
app.UseOAuthBearerAuthentication(options =>
{
options.AuthenticationScheme = OAuthBearerAuthenticationDefaults.AuthenticationScheme;
});
app.UseStaticUrl(options =>
{
options.HtmlFileToMapTo = "index.html";
options.FilePathsToIgnore = new string[]
{
"/api",
"/assets",
"/fonts",
"/tests",
"/testem.js",
"/robots.txt",
"/crossdomain.txt"
};
});
app.UseStaticFiles();
app.UseMvc();
}