Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Fixed Startup and Index.cshtml to start working. Simplified appsettings. #10

Merged
merged 1 commit into from Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions B2C-WebApi/Startup.cs
Expand Up @@ -36,16 +36,18 @@ public Startup(IHostingEnvironment env)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddJwtBearer(option => new JwtBearerOptions
{
Authority = string.Format("https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/",
Configuration["Authentication:AzureAd:Tenant"], Configuration["Authentication:AzureAd:Policy"]),
Audience = Configuration["Authentication:AzureAd:ClientId"],
Events = new JwtBearerEvents
{
OnAuthenticationFailed = AuthenticationFailed
}
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
jwtOptions.Authority = $"https://login.microsoftonline.com/tfp/{Configuration["AzureAdB2C:Tenant"]}/{Configuration["AzureAdB2C:Policy"]}/v2.0/";
jwtOptions.Audience = Configuration["AzureAdB2C:ClientId"];
jwtOptions.Events = new JwtBearerEvents
{
OnAuthenticationFailed = AuthenticationFailed
};
});

// Add framework services.
Expand All @@ -58,9 +60,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

ScopeRead = Configuration["Authentication:AzureAd:ScopeRead"];
ScopeWrite = Configuration["Authentication:AzureAd:ScopeWrite"];
ScopeRead = Configuration["AzureAdB2C:ScopeRead"];
ScopeWrite = Configuration["AzureAdB2C:ScopeWrite"];

app.UseAuthentication();

app.UseMvc(routes =>
{
routes.MapRoute(
Expand Down
4 changes: 3 additions & 1 deletion B2C-WebApi/Views/Home/Index.cshtml
@@ -1,5 +1,7 @@
<html>
<headAzure AD B2C API Sample></head>
<head>
<title>Azure AD B2C API Sample</title>
</head>
<body>
Your API will now be available via http://localhost:5000/api/Values

Expand Down
16 changes: 7 additions & 9 deletions B2C-WebApi/appsettings.json
@@ -1,14 +1,12 @@
{
"Authentication": {
"AzureAd": {
"Tenant": "fabrikamb2c.onmicrosoft.com",
"ClientId": "25eef6e4-c905-4a07-8eb4-0d08d5df8b3f",
"Policy": "b2c_1_susi",
"AzureAdB2C": {
"Tenant": "fabrikamb2c.onmicrosoft.com",
"ClientId": "25eef6e4-c905-4a07-8eb4-0d08d5df8b3f",
"Policy": "b2c_1_susi",

"ScopeRead": "demo.read",
"ScopeWrite": "demo.write"
}
},
"ScopeRead": "demo.read",
"ScopeWrite": "demo.write"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
Expand Down