@@ -10,10 +10,11 @@ public class Startup
1010{
1111 public void ConfigureServices ( IServiceCollection services )
1212 {
13- AddCapWithOpenIdAuthorization ( services ) ;
13+ // AddCapWithOpenIdAuthorization(services);
1414 // AddCapWithAnonymousAccess(services);
1515 // AddCapWithCustomAuthorization(services);
16-
16+ AddCapWithOpenIdAndCustomAuthorization ( services ) ;
17+
1718 services . AddCors ( x =>
1819 {
1920 x . AddDefaultPolicy ( p =>
@@ -41,10 +42,10 @@ public void Configure(IApplicationBuilder app)
4142 private IServiceCollection AddCapWithOpenIdAuthorization ( IServiceCollection services )
4243 {
4344 const string DashboardAuthorizationPolicy = "DashboardAuthorizationPolicy" ;
44-
45+
4546 services
4647 . AddAuthorization ( options =>
47- {
48+ {
4849 options . AddPolicy ( DashboardAuthorizationPolicy , policy => policy
4950 . AddAuthenticationSchemes ( OpenIdConnectDefaults . AuthenticationScheme )
5051 . RequireAuthenticatedUser ( ) ) ;
@@ -64,11 +65,12 @@ private IServiceCollection AddCapWithOpenIdAuthorization(IServiceCollection serv
6465 options . Scope . Add ( "openid" ) ;
6566 options . Scope . Add ( "profile" ) ;
6667 } ) ;
67-
68+
6869 services . AddCap ( cap =>
6970 {
7071 cap . UseDashboard ( d =>
7172 {
73+ d . AllowAnonymousExplicit = false ;
7274 d . AuthorizationPolicy = DashboardAuthorizationPolicy ;
7375 } ) ;
7476 cap . UseInMemoryStorage ( ) ;
@@ -77,21 +79,21 @@ private IServiceCollection AddCapWithOpenIdAuthorization(IServiceCollection serv
7779
7880 return services ;
7981 }
80-
82+
8183 private IServiceCollection AddCapWithCustomAuthorization ( IServiceCollection services )
8284 {
8385 const string MyDashboardAuthenticationPolicy = "MyDashboardAuthenticationPolicy" ;
84-
86+
8587 services
8688 . AddAuthorization ( options =>
87- {
89+ {
8890 options . AddPolicy ( MyDashboardAuthenticationPolicy , policy => policy
8991 . AddAuthenticationSchemes ( MyDashboardAuthenticationSchemeDefaults . Scheme )
9092 . RequireAuthenticatedUser ( ) ) ;
9193 } )
9294 . AddAuthentication ( )
93- . AddScheme < MyDashboardAuthenticationSchemeOptions , MyDashboardAuthenticationHandler > ( MyDashboardAuthenticationSchemeDefaults . Scheme , null ) ;
94-
95+ . AddScheme < MyDashboardAuthenticationSchemeOptions , MyDashboardAuthenticationHandler > ( MyDashboardAuthenticationSchemeDefaults . Scheme , null ) ;
96+
9597 services . AddCap ( cap =>
9698 {
9799 cap . UseDashboard ( d =>
@@ -104,7 +106,49 @@ private IServiceCollection AddCapWithCustomAuthorization(IServiceCollection serv
104106
105107 return services ;
106108 }
107-
109+
110+ private IServiceCollection AddCapWithOpenIdAndCustomAuthorization ( IServiceCollection services )
111+ {
112+ const string DashboardAuthorizationPolicy = "DashboardAuthorizationPolicy" ;
113+
114+ services
115+ . AddAuthorization ( options =>
116+ {
117+ options . AddPolicy ( DashboardAuthorizationPolicy , policy => policy
118+ . AddAuthenticationSchemes ( OpenIdConnectDefaults . AuthenticationScheme , MyDashboardAuthenticationSchemeDefaults . Scheme )
119+ . RequireAuthenticatedUser ( ) ) ;
120+ } )
121+ . AddAuthentication ( opt => opt . DefaultScheme = CookieAuthenticationDefaults . AuthenticationScheme )
122+ . AddScheme < MyDashboardAuthenticationSchemeOptions , MyDashboardAuthenticationHandler > ( MyDashboardAuthenticationSchemeDefaults . Scheme , null )
123+ . AddCookie ( )
124+ . AddOpenIdConnect ( options =>
125+ {
126+ options . RequireHttpsMetadata = false ;
127+ options . Authority = "https://demo.duendesoftware.com/" ;
128+ options . ClientId = "interactive.confidential" ;
129+ options . ClientSecret = "secret" ;
130+ options . ResponseType = "code" ;
131+ options . UsePkce = true ;
132+
133+ options . Scope . Clear ( ) ;
134+ options . Scope . Add ( "openid" ) ;
135+ options . Scope . Add ( "profile" ) ;
136+ } ) ;
137+
138+ services . AddCap ( cap =>
139+ {
140+ cap . UseDashboard ( d =>
141+ {
142+ d . AllowAnonymousExplicit = false ;
143+ d . AuthorizationPolicy = DashboardAuthorizationPolicy ;
144+ } ) ;
145+ cap . UseInMemoryStorage ( ) ;
146+ cap . UseInMemoryMessageQueue ( ) ;
147+ } ) ;
148+
149+ return services ;
150+ }
151+
108152 private IServiceCollection AddCapWithAnonymousAccess ( IServiceCollection services )
109153 {
110154 services . AddCap ( cap =>
0 commit comments