concept browser in category microservice

appears as: browser, The browser, browsers
Microservices Security in Action

This is an excerpt from Manning's book Microservices Security in Action.

If you observe the Network tab on your browser developer tools, you’ll notice the browser making a GET request to http://localhost:4200. The response of this request is a bunch of HTML code that renders the title Book List App and the Load Books button on your browser web page. You should also see other requests to load a few JavaScript files onto the browser. These are not important for the concepts we teach in this chapter, so we can safely ignore them for the moment.

Next, click the Load Books button again and observe what happens on the Network tab of your browser development tools. You should see that the browser sends a GET request to http://localhost:8080/books. This request returns a list of book titles in JSON format, the exact response we noticed when we tested the resource server directly. Figure 4.3 illustrates the sequence of events that happens to load this web page with a list of book titles.

Figure 4.3 This sequence of message exchanges among the web browser, web server, and resource server displays a list of book titles on a web page in the Angular application.

The browser makes an initial request to http://localhost:4200, which loads the web application onto the web browser. The Angular-based web application is hosted on a Node.js server running on port 4200 in this sample. Once the application is loaded onto the browser, it renders the HTML content of the home page, which contains the Load Books button. Once this button is clicked, the browser initiates a request to load the list of books from the resource server running on localhost:8080. The resource server returns the list of books in JSON format. The JavaScript loaded on the web page then converts this JSON-formatted data into HTML, which results in us seeing the book titles on the web page.

When you click the Log In button, you’ll notice that the browser initiates an authorization request to the /oauth/authorize endpoint of the authorization server. This passes a response_type parameter set to code, indicating that it is initializing an authorization code grant, in this case can also be called as an OIDC authorization code flow. The client_id is sent as a request parameter as well:

http://localhost:8081/oauth/authorize?

  response_type=code&
  client_id=clientapp&
  state=Ulg4V1pN.....&
  redirect_uri=http.....&
  scope=openid&
  nonce=Ulg4V1.....&
  audience=https...

As a response to this authorization request, the authorization server responds with a 302 redirect to the login page. You should notice the Location header in the response pointing to http://localhost:8081/login. The browser makes a GET request to this URL, and that request results in what you see on the login page of your browser. Figure 4.10 illustrates this scenario.

Once you provide the username and password on the login page, you will notice the browser submitting the data to the authorization server. The authorization server then redirects the browser to the content page, where you need to approve the web application’s access to the protected resources on the resource server. Once the approval is provided, the authorization server redirects the browser back to the web application providing an authorization code. You can notice this in the Location header that comes as a response from the authorization request:

Location: 
   http://localhost:4200/?code=rnRb4K&state=bEs1c.....

Once the browser receives this authorization code, it initiates a request to the /oauth/token endpoint of the authorization server to exchange the authorization code for an access token. You should see a request similar to the following being initiated from your web browser: