Redirect to another web page from anvil

Problem

When I detect a 401 http code, I need to redirect to another web site (temporarily) in order to carry out an authentication.

Any ideas how this might be accomplished?

Just thinking off the top of my head here.

Could you use an “if” statement to check for the response and respond accordingly?

If it is a 401, you could display the authentication page inside of an iFrame, or present a link that says “click here to authenticate” and set the link’s URL to the appropriate page.

I might be misunderstanding something but that is what comes to my mind at the moment.

Interesting. Thanks.

Is an iframe available in Anvil without using a custom HTML form?

Not at the moment; however, you can just copy the code out of the custom iFrame component and place that into a custom HTML form (see below to see where the custom HTML form is located). This way, you don’t have to add the iFrame as a dependency per se.

The IFrame is now working fine. But

In the normal part of the form, I get a response that the resource is still unauthenticated; while in the IFrame the resource is available. Is the IFrame ‘sandboxed’ from the rest of the web page?

I believe the browser does that, yes. I think it’s in its own session.

I would search the forum for “iframe” and you’ll find a few discussions regarding Anvil and iframes. Not sure if any are directly relevant but they are worth checking out for info, I think.

Thanks All,

I solved the main part of the authentication problem by using the javascript functions provided by the authentication service in the main app using call_js, rather than needing an IFrame.

Great to hear!

It would be great to see an example of this on the Forum. Are you able to share a clone link?

Of course, no worries if it is too much of a pain to do this.

Also, I’m wondering if it is possible to do the external authentication check using Anvil’s HTTP module.

Perhaps I am missing the particulars of the original question, but I thought I’d ask anyway in case this is more straight forward.