-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStartup.cs
executable file
·107 lines (88 loc) · 4.32 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
namespace MvcClient
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
// Add framework services
services.AddMvc();
// Add authentication services
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("Authentiq", options => {
// Set the authority to the Authentiq Provider
options.Authority = "https://connect.authentiq.io";
// Configure the Authentiq Client ID and Client Secret
options.ClientId = Configuration["Authentiq:ClientId"];
options.ClientSecret = Configuration["Authentiq:ClientSecret"];
// Set response type to: code id_token
options.ResponseType = "code id_token";
// Configure the Claims Issuer to be Authentiq
options.ClaimsIssuer = "Authentiq";
// Configure the scopes requested from user
// Check the supported Identity Claims for Authentiq at http://developers.authentiq.io/#identity-claims
options.Scope.Add("openid");
options.Scope.Add("aq:push");
// email shall be required and verified (signed)
options.Scope.Add("email~rs");
options.Scope.Add("profile");
// Request additional scopes which can be opted out by the user
//options.Scope.Add("phone");
//options.Scope.Add("address");
//options.Scope.Add("aq:location");
//options.Scope.Add("profile");
// Set the callback path, so that Authentiq will call back to http://localhost:5002/signin-authentiq
// check that you have added this full URL in the Authentiq dashboard at "Redirect URIs"
options.CallbackPath = new PathString("/signin-authentiq");
options.SignedOutCallbackPath = new PathString("/signout-callback-authentiq");
options.RemoteSignOutPath = new PathString("/signout-authentiq");
// The UserInfo endpoint does not return any additional claims next to the ones returned in the id_token
options.GetClaimsFromUserInfoEndpoint = false;
options.SaveTokens = true;
});
}
// Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
}
}