Redirect non-authenticated users to SSO page

Hello,

We are creating a Drupal 8 website where some sub-pages are only accessible to authenticated users. These sub-pages are accessible from links on other pages. However, we would like to avoid that users, which are not logged in, get the “access denied” page when they click on the link, but they should rather be redirected to the SSO page. Is this possible?

Thanks!
Anton

Hi Anton,

You can create a basic page with the thellowing message:

“In order to access the content of this page you need to login first.”

Then hyperlink the login with this URL /user/login

Then go to Configuration->Basic site settings and put the page that you have created as the new Access denied page under Default 403 (access denied) page.

Hi Sotirios,

Is there any way we can include the target page in the login link?

For example, I don’t want my users to land again on the Access Denied page after logging in.

Ideally it should even be dynamic, so I would like to keep somewhere the original URL that triggered the 403 page, and use that for redirection.

In Drupal 7 we could do /Shibboleth.sso/?target=https%3A%2F%2Fmy-site.web.cern.ch%2Fmy-redirection to statically define the redirection but with /user/login that trick doesn’t seem to work :confused:

If there’s any trick we can use it would be great :wink:

Hi Oscar,

Are you sure that /user/login doesn’t work? I have seen it on other sites people set a custom access denied page and add a link to user/login and works fine.

Also there are the following two modules that you can check:


Hi @sboutas,

thanks for the quick answer. I tried yesterday and it was not working, but I tried today and it does :stuck_out_tongue:

So no need for modules, but thanks anyway, they might be helpful for other use cases!

Regards,
Óscar

Hi, I do not understand this answer.
I created a Basic Page . But what do you call"hyperlink the login with this URL" ?
When i when to configure “Configuration->Basic site settings” I don’t know what to put ? should I put /node/xxx or something else?

Thanks in advance.
joel.

Hi Joel,

What are you trying to do exactly?

I want to replace the default “access denied” page with my custom one which add in fact that we need to SIGN-IN to get access

Joel.

Hi Joel,

Just create a basic page and in the body of the node ass some text like:

“Click here to login”

Make “here” a hyperlink and add /user/login

Then go to Configuration->Basic site settings and at the bottom of the page you will see the access denied URL. Put there the link of your basic page either like /node/nodeid or /content/titleofnode

Save, clear cache and it should work fine.

HI I tried but it seems that the result is not what I expected.
See capture…
So obviously I do something wrong. But what ?

Hi Joel,

You have enabled the Content Access module and you set it up per content type. The basic page content type was accessible only to authenticated users that’s why the custom access denied page could not be displayed.

I enabled the content access in basic page content type per node and I allowed anonymous users to see this specific node.

Now it works fine. Be careful when you work with access and permission modules.

This was the problem. Thanks for your efficient action.
Joel