Arjun Patel
Arjun Patel

Reputation: 353

How to display HTTP 401 basic authentication dialog

I am new to web development. I have Android application that hosts some web pages using HTTPServer. I am using Netty to decode/encode request/responses. Now, I want to display basic authentication dialog when someone navigates to the my webpage. Something like this: enter image description here

Can I get some pointers ? Is it something HTTP built in functionality, any RFC ? Do I need to write some java script ? Any help would be great.

Upvotes: 4

Views: 9398

Answers (1)

Brad
Brad

Reputation: 163240

You just need to send the appropriate headers when a client requests a resource you want to require authentication for.

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Restricted Area"

The client can then retry the request while sending a base64 encoded header in the format username:password.

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

See also: http://en.wikipedia.org/wiki/Basic_access_authentication

Upvotes: 10

Related Questions