Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UmbracoContext.InPreviewMode always false, Umbraco.Context.Security.CurrentUser always null #144

Open
dhymik opened this issue Jul 17, 2021 · 1 comment

Comments

@dhymik
Copy link

dhymik commented Jul 17, 2021

After I install UmbracoIdentity into a clean Umbraco 8 installation, UmbracoContext.InPreviewMode always returns false. The reason is that Umbraco.Context.Security.CurrentUser always returns null with UmbracoIdentity installed.

Can I do something to prevent this from happening?

@dvdvliet
Copy link

dvdvliet commented Oct 5, 2021

I ran into exactly the same issue and took me a while to figure out.

This is fixed by changing the example of the UmbracoIdentityOwinStartup code a bit.

Remove the line

base.ConfigureUmbracoAuthentication(app);

instead add these lines (and add an extra using Umbraco.Web.Security;)

app
     .UseUmbracoBackOfficeCookieAuthentication(UmbracoContextAccessor, RuntimeState, Services.UserService,
         GlobalSettings, UmbracoSettings.Security, PipelineStage.Authenticate)
     .UseUmbracoBackOfficeExternalCookieAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings,
         PipelineStage.Authenticate);

Now place your custom code and authentication configurations.

Finally at the end add these lines of code

// this must come after all authentication so should be moved within ConfigureMiddleware
app.UseUmbracoPreviewAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, UmbracoSettings.Security, PipelineStage.Authorize);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants