Running the application and testing

Run the application using the Spring Boot command shown below:

mvn spring-boot:run

I will be using Postman to execute the REST endpoints.

You can get hold of the token, to include it in subsequent calls, by employing two methods as detailed below:

  • If you access any route using basic authentication credentials, in the response header, you should get the token. I will be using the /login path with Basic Auth (authorization header) to get the token, as shown here:

Figure 4: Getting token using Basic Auth in Postman
  • Access the /auth/token endpoint with Basic Auth credentials supplied in the form of JSON (using the JWTAuthRequest class), as shown here, in Postman:

Figure 5: Getting token using /auth/token endpoint using Basic Auth credentials in JSON

Using the token retrieved, call the movie endpoint, as shown here, using Postman:

Figure 6: Retrieving movie listing using a JWT token in Postman

This completes the example that we were building. In this example, we secured the REST APIs by making use of JWT and validated them using Spring Security. As mentioned, this is a basic way in which you can secure your REST APIs using Spring Security with JWTs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.62.122