Basic auth is very simply implemented through traditional HTTP request methods. You just pass a username and password as login credentials through to the provider from which you are trying to obtain the privileged user information.
Let’s say, for example, that we want to pull down some resources from a social URI endpoint that is designated by a provider site. We start out by making a simple HTTP GET request to the provider URI endpoint to capture that data:
GET /private/user/me HTTP/1.1 Host: server.example.com
Now let’s say that the provider requires basic authentication (username and password for validation). Since we didn’t include those login credentials with the request, the provider will return a simple HTTP error response stating that additional authorization is required:
HTTP/1.1 401 Authorization Required Date: Fri, 17 Dec 2010 02:27:34 GMT Server: Apache Location: http://server.example.com/private/user/me Cache-Control: max-age=300 Expires: Fri, 17 Dec 2010 02:32:34 GMT Vary: Accept-Encoding Content-Length: 148 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>Error: Unauthorized</title> </head><body> <h1>401 Unauthorized</h1> </body></html>
Let’s assume that this provider accepts basic authentication requests. We’ll use an HTTP POST request including a username, password, and any arbitrary parameters that the URI endpoint requires to denote which resources ...