11using System . Runtime . InteropServices ;
22using EPiServer . Cms . Shell ;
33using EPiServer . Cms . UI . AspNetIdentity ;
4+ using EPiServer . ContentApi . Cms ;
45using EPiServer . ContentApi . Core . DependencyInjection ;
6+ using EPiServer . ContentDefinitionsApi ;
57using EPiServer . Core ;
68using EPiServer . Data ;
79using EPiServer . DependencyInjection ;
10+ using EPiServer . OpenIDConnect ;
811using EPiServer . Web ;
912using EPiServer . Web . Routing ;
1013
@@ -36,7 +39,7 @@ public void ConfigureServices(IServiceCollection services)
3639 User=sa;Password=Admin123!;
3740 Trust Server Certificate=True;Connect Timeout=30" ;
3841 var connectionstring = _configuration . GetConnectionString ( "EPiServerDB" )
39- ?? ( isMacOs ? macOsConnString : localDBConnString ) ;
42+ ?? ( isMacOs ? macOsConnString : localDBConnString ) ;
4043 services . Configure < DataAccessOptions > ( o =>
4144 {
4245 o . SetConnectionString ( connectionstring ) ;
@@ -59,13 +62,64 @@ public void ConfigureServices(IServiceCollection services)
5962 . Add ( "narrow" , "Narrow" , "u-md-size1of3" , string . Empty , "epi-icon__layout--one-third" ) ;
6063 } ) ;
6164
62- services . AddContentDefinitionsApi ( ) ;
63- services . AddContentDeliveryApi ( ) ;
64- services . AddContentManagementApi ( options =>
65+ // services.AddOpenIddict();
66+
67+ Console . WriteLine ( "Adding OpenID Connect" ) ;
68+ services . AddOpenIDConnect < ApplicationUser > (
69+ useDevelopmentCertificate : true ,
70+ signingCertificate : null ,
71+ encryptionCertificate : null ,
72+ createSchema : true ,
73+ options =>
74+ {
75+ var baseUri = new Uri ( _frontendUri ) ;
76+ options . RequireHttps = ! _webHostingEnvironment . IsDevelopment ( ) ;
77+ options . DisableTokenPruning = true ;
78+ options . DisableSlidingRefreshTokenExpiration = true ;
79+
80+ options . Applications . Add ( new OpenIDConnectApplication
81+ {
82+ ClientId = "frontend" ,
83+ Scopes = { "openid" , "offline_access" , "profile" , "email" , "roles" , ContentDeliveryApiOptionsDefaults . Scope } ,
84+ PostLogoutRedirectUris = { baseUri } ,
85+ RedirectUris =
86+ {
87+ new Uri ( baseUri , "/" ) ,
88+ new Uri ( baseUri , "/login-callback" ) ,
89+ new Uri ( baseUri , "/login-renewal" ) ,
90+ } ,
91+ } ) ;
92+
93+ options . Applications . Add ( new OpenIDConnectApplication
94+ {
95+ ClientId = "cli" ,
96+ ClientSecret = "cli" ,
97+ Scopes = { ContentDefinitionsApiOptionsDefaults . Scope } ,
98+ } ) ;
99+ } ) ;
100+
101+ services . AddOpenIDConnectUI ( ) ;
102+
103+ // No encrypt the token so it's easier to debug, not recommend for production.
104+ services . AddOpenIddict ( )
105+ . AddServer ( options => options . DisableAccessTokenEncryption ( ) ) ;
106+
107+ services . AddContentDefinitionsApi ( OpenIDConnectOptionsDefaults . AuthenticationScheme ) ;
108+
109+ services . AddContentDeliveryApi ( OpenIDConnectOptionsDefaults . AuthenticationScheme ) ;
110+
111+ services . AddContentManagementApi ( OpenIDConnectOptionsDefaults . AuthenticationScheme , options =>
65112 {
66113 options . DisableScopeValidation = false ;
67114 options . RequiredRole = "WebAdmins" ;
68115 } ) ;
116+ // services.AddContentManagementApi(string.Empty);
117+
118+ services . AddOpenIddict ( )
119+ . AddServer ( options =>
120+ {
121+ options . DisableAccessTokenEncryption ( ) ;
122+ } ) ;
69123
70124 services . ConfigureForContentDeliveryClient ( ) ;
71125
@@ -79,7 +133,7 @@ public void ConfigureServices(IServiceCollection services)
79133 o . IncludeNumericContentIdentifier = true ;
80134 } ) ;
81135
82- services . AddContentGraph ( options =>
136+ services . AddContentGraph ( OpenIDConnectOptionsDefaults . AuthenticationScheme , options =>
83137 {
84138 options . EnablePreviewTokens = true ;
85139 } ) ;
@@ -96,7 +150,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
96150 app . UseStaticFiles ( ) ;
97151 app . UseRouting ( ) ;
98152 app . UseCors ( b => b
99- . WithOrigins ( new [ ] { $ "{ _frontendUri } "} )
153+ . WithOrigins ( new [ ] { $ "{ _frontendUri } " } )
100154 . WithExposedContentDeliveryApiHeaders ( )
101155 . WithExposedContentDefinitionApiHeaders ( )
102156 . WithHeaders ( "Authorization" )
0 commit comments