Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to re-direct to a webpage upon requestAuthentification() failling #11457

Unanswered
AIoT-Consulting asked this question in Q&A
Discussion options

In the esp32 WebServer.h library, I've been referencing the HttpAdvancedAuth.ino example file @lucasssvaz to figure out how to add authentication when linking to a specific webpage and was wondering if anyone else is tried to re-direct to a webpage upon the requestAuthentication() method failling when a user enters the wrong credentials or hits "Cancel". For example, when a user enters the IP address of the eps32 (ex: 192.168.50.197) , my code contains the following:

server.on("/", handleRoot);

which calls:

void handleRoot() {
 server.send(200, "text/html", htmlPage1);
}

htmlPage1 being a const char containing the html code stored in SPIFF memory.

So far so good.

Now on my htmlPage1, if the users want to access another page called "Settings", they click on a link <a href="/page2">Settings</a> and I have the following code to handle the /page2 call:

server.on("/page2", []() {
 if(!server.authenticate(www_username, www_password))
 {
 server.requestAuthentication(DIGEST_AUTH, www_realm, authFailResponse);
 }
 server.send(200, "text/html", htmlPage2);
 });

Again, so far so good as the authentification pops up,
Screenshot 1
and if the user enters the right credential, htmlPage2 opens up.

The problem I'm trying to address is what happens when the user hits the "Cancel" button after trying and failling to enter their credential. What currently happens is when the user clicks on "Cancel" the following screen appears:

Screenshot 2

And the user is not re-directed to any page.

I've tried adding server.send(200, "text/html", htmlPage1); under the server.requestAuthentication(DIGEST_AUTH, www_realm, authFailResponse); as well as all kinds of other ways to make this happen without any success. Here are the values of the www_realm and authFailResponse variables:

const char* www_realm = "Login Required";
String authFailResponse = "Authentication Failed";

I'm hoping someone who has better knowledge of the webserver.h library can help me find a way to solve this by having the user re-directed to the original root page upon failling the authentication or clicking the "Cancel" button.
Thanks for any help...

You must be logged in to vote

Replies: 1 comment

Comment options

This behavior might be from the browser itself. I don't have much knowledge of the webserver library, @me-no-dev might help you better.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /