Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew 52 posts 234 karma points
    Aug 25, 2022 @ 14:19
    Andrew
    0

    Is it possible to provide a preview url to a person who does not have a login

    Hi,

    I'm using Umbraco 10 and I would like to send a preview url to someone who doesn't have a User or Member to login with.

    I've seen other CMS offer this option with a token in the url.

    Is this possible with Umbraco?

    Thanks

  • James Shelley 9 posts 103 karma points
    Aug 25, 2022 @ 19:06
    James Shelley
    0

    If your initial worry is them viewing parts of the Umbraco Backoffice you don't want them to see yet, you can get extremely granular with Umbraco permissions, i.e. you could create them an account and assign a user group that just gives them read only access to 1 single Umbraco node (i.e. the page they want to preview).

    Is there any particular reason they can't have a login?

  • Andrew 52 posts 234 karma points
    Aug 25, 2022 @ 19:41
    Andrew
    0

    Its something that came up in during a discussion:

    The other CMS can do it

    Its a feature some clients use sometimes for people who just want to see something on very rare occasions and don't want any extra steps.

  • Mario Lopez 168 posts 952 karma points MVP 3x c-trib
    Aug 27, 2022 @ 06:31
    Mario Lopez
    0

    The workflow package Plumber has this feature. Check the Offline approval section on the docs

    The package (and its author) has just been acquired by Umbraco, and it's not free.

  • Mark Drake 133 posts 457 karma points c-trib
    Aug 28, 2022 @ 15:28
    Mark Drake
    0

    The fastest & easiest solution to your problem is to publish the page.

    If your domain name is domain.com and your page name is skljfsdjk43523424 you can then access it at domain.com/skljfsdjk43523424.

    Nobody is going to guess this URL. Nobody, including robots, will find this page unless you put it into your sitemap.

    It would also be a good opportunity to add properties to your document type for explicitly hiding a page from your sitemap, and telling bots not to index the page (if you haven't done this already).

    If you find another solution, please share it as many people have this exact requirement. I just publish the page with an obfuscated URL.

  • Andrew 52 posts 234 karma points
    Aug 30, 2022 @ 15:21
    Andrew
    0

    I may have a solution, it seems to be working, but haven't done much testing yet and there are lots of rough edges.

    The site is "headless" using Nuxt for the front end, all the controllers are hijacked to return json for nuxt instead of native rendering.

    When a user clicks on save and preview in the Umbraco editor, I generate a token and then redirect to the nuxt site with the token instead of serving the json.

    The nuxt site calls back to umbraco with the token and the UMB_PREVIEW cookie. If the token is valid, a middleware component looks up a user and sets it as the principal** for the request. (The user is defined in Umbraco with limited rights). Having the cookie and an Umbraco user as the principal makes UmbracoContext.InPreviewMode true. The UI sends an extra parameter to avoid a redirect loop

    To add middleware in Umbraco, I used IStartupFilter

    Just before services.AddUmbraco()

    services.AddTransient<IStartupFilter, StartupFilter>();
    

    And the filter is fairly simple

    private class StartupFilter : IStartupFilter
            {
                public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) => app =>
                {
                    app.UseMiddleware<PreviewMiddleware>();
                    next(app);
                };
            }
    

    To get the user I use 3 types that are injected into the middleware's Invoke method

    IBackOfficeUserManager backOfficeUserManager , IUserClaimsPrincipalFactory

    var user = await backOfficeUserManager.FindByNameAsync(config.Username);
    var prin = await ucpf.CreateAsync(user);
    httpContext.SetPrincipalForRequest(prin);
    
Please Sign in or register to post replies

Write your reply to:

Draft