@@ -115,6 +115,42 @@ services.AddOptions<CookieAuthenticationOptions>(CookieAuthenticationDefaults.Au
115115```
116116You can find the CookieOidcRefresher [ here] ( https://github.com/dotnet/blazor-samples/blob/main/9.0/BlazorWebAppOidc/BlazorWebAppOidc/CookieOidcRefresher.cs ) .
117117
118+ Before ` app.Run ` , add the following:
119+ ``` csharp
120+ {
121+ var group = endpoints .MapGroup (" /authentication" );
122+
123+ group .MapGet (" /login" , (string ? returnUrl ) => TypedResults .Challenge (GetAuthProperties (returnUrl )))
124+ .AllowAnonymous ();
125+
126+ // Sign out of the Cookie and OIDC handlers. If you do not sign out with the OIDC handler,
127+ // the user will automatically be signed back in the next time they visit a page that requires authentication
128+ // without being able to choose another account.
129+ group .MapPost (" /logout" , ([FromForm ] string ? returnUrl ) => TypedResults .SignOut (GetAuthProperties (returnUrl ), [CookieAuthenticationDefaults .AuthenticationScheme , SCHEMENAME ]));
130+
131+ static AuthenticationProperties GetAuthProperties (string ? returnUrl )
132+ {
133+ // TODO: Use HttpContext.Request.PathBase instead.
134+ const string pathBase = " /" ;
135+
136+ // Prevent open redirects.
137+ if (string .IsNullOrEmpty (returnUrl ))
138+ {
139+ returnUrl = pathBase ;
140+ }
141+ else if (! Uri .IsWellFormedUriString (returnUrl , UriKind .Relative ))
142+ {
143+ returnUrl = new Uri (returnUrl , UriKind .Absolute ).PathAndQuery ;
144+ }
145+ else if (returnUrl [0 ] != '/' )
146+ {
147+ returnUrl = $" {pathBase }{returnUrl }" ;
148+ }
149+
150+ return new AuthenticationProperties { RedirectUri = returnUrl };
151+ }}
152+ ```
153+
118154## Deployment
119155
120156Deployment requires the a server side app to log in to the Catglobe site, and then the app will sync the scripts with the Catglobe site.
@@ -178,6 +214,14 @@ The authentication model is therefore that the developer logs into the using his
178214
179215All scripts are executed as the developer account and impersonation or public scripts are not supported!
180216
217+ If you have any public scripts, it is highly recommended you configure the entire site for authorization in development mode:
218+ ``` csharp
219+ var razor = app .MapRazorComponents <App >()
220+ .. . removed for abbrivity .. .;
221+ if (app .Environment .IsDevelopment ())
222+ razor .RequireAuthorization ();
223+ ```
224+
181225## Staging and Deployment
182226
183227Setup ` deployment ` and sync your scripts to the Catglobe site.
@@ -202,14 +246,20 @@ Would return empty string for development, "Hello, World!" for production and "H
202246
203247The preprocessor is case insensitive, supports multiline and supports the standard ` Environment.EnvironmentName ` values.
204248
205- ## Development mode impersonation and public scripts
206-
207- During development all scripts are executed as the developer account, therefore impersonation or public scripts are not supported!
208-
209249## You get a 404 on first deployment?
210250
211251` parentResourceId ` /` FolderResourceId ` MUST be a folder.
212252
253+ ## I marked my script as public, but get 401 in development mode?
254+
255+ Since all scripts are dynamically generated during development, it also requires running as an account that has permission to run dynamic scripts.
256+
257+ See the example above on how to force the site to always force you to login after restart of site.
258+
259+ ## impersonation is ignored during development
260+
261+ During development all scripts are executed as the developer account, therefore impersonation or public scripts are not supported!
262+
213263## Where do I find the scopes that my site supports?
214264
215265See supported scopes in your Catglobe site ` https://mysite.catglobe.com/.well-known/openid-configuration ` under ` scopes_supported ` .
0 commit comments