{"id":2007,"date":"2024-08-20T12:00:00","date_gmt":"2024-08-20T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/json-web-token-how-to-secure-rest-api-using-jwt-in-spring-boot\/"},"modified":"2026-07-05T03:26:50","modified_gmt":"2026-07-05T01:26:50","slug":"json-web-token-how-to-secure-rest-api-using-jwt-in-spring-boot","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/json-web-token-how-to-secure-rest-api-using-jwt-in-spring-boot\/","title":{"rendered":"Json Web Token \u2013 How to Secure REST API Using JWT in Spring Boot"},"content":{"rendered":"<p>This is a tutorial on how to implement Json Web Token authentication for a REST API in Spring Boot using public and private keys. In this approach, we would be using the SecurityFilterChain bean rather than extending the WebSecurityConfigurerAdapter.<\/p>\n<p>Then we would be creating a self-signed JWT.<\/p>\n<ol>\n<li><a href=\"#t1\">Getting Started With Json Web Token( JWT)<\/a><\/li>\n<li><a href=\"#t2\">Create and Configure the SecurityFilterChain Bean<\/a><\/li>\n<li><a href=\"#t3\">Create a Test UserManager Bean<\/a><\/li>\n<li><a href=\"#t4\">Configure the ResourceServer<\/a><\/li>\n<li><a href=\"#t5\">Create a Public\/Private Key Pair<\/a><\/li>\n<li><a href=\"#t6\">Create some Configuration to Externalize the Keys<\/a><\/li>\n<li><a href=\"#t7\">Create the JwtDecoder and JwtEncoder<\/a><\/li>\n<li><a href=\"#t8\">Create the TokenService<\/a><\/li>\n<li><a href=\"#t9\">Implement the &#8220;\/token&#8221; Endpoint<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/youtu.be\/IZ2QEPhO7A4?si=8HQnE0eaDwmK4ddP\" target=\"_blank\" rel=\"noopener\">Video Tutorial &#8211;\u00a0The New JWT \u2013 How to Secure REST API Using Json Web Token in Spring Boot<\/a><\/p>\n<h4><strong id=\"t1\">1. Getting Started With JWT<\/strong><\/h4>\n<p>We would start with a basic REST API. Then we would see how to secure an endpoint using Json Web Token.<\/p>\n<p>You will need the following dependencies:<\/p>\n<div>\n<ul>\n<li>spring-boot-starter-oauth2-resource-server<\/li>\n<li>spring-boot-starter-web<\/li>\n<li><span style=\"font-family: 'Source Sans Pro', Graphik, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 1.125rem;\">spring-boot-configuration-processor<\/span><\/li>\n<\/ul>\n<\/div>\n<p><strong>How it works<\/strong><\/p>\n<ul>\n<li>For the first time, the user logs in with his username and password.<\/li>\n<li>At successful authentication (login), the server generates and returns back a token (jwt) to the user<\/li>\n<li>For subsequent requests, the token must be included in the request header<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Create and Configure the SecurityFilterChain Bean<\/strong><\/h4>\n<p>1. Create the security configuration file (name it SecurityConfig.java) in the config directory.<\/p>\n<p>2. Annotate this class with @Configuration and @EnableWebSecurity<\/p>\n<p>3. Create the SecurityFilterChain bin. It takes HttpSecurity as parameter, builds and returns the SecurityFilterChain.\u00a0 The code below shows what is returned:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">return<\/span> httpSecurity\r\n        <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">csrf<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #997700; font-weight: bold;\">AbstractHttpConfigurer:<\/span><span style=\"color: #333333;\">:<\/span>disable<span style=\"color: #333333;\">)<\/span>\r\n        <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">authorizeHttpRequests<\/span><span style=\"color: #333333;\">(<\/span>auth <span style=\"color: #333333;\">-&gt;<\/span> auth\r\n                <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">anyRequest<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">authenticated<\/span><span style=\"color: #333333;\">()<\/span>\r\n        <span style=\"color: #333333;\">)<\/span>\r\n        <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">sessionManagement<\/span><span style=\"color: #333333;\">(<\/span>session <span style=\"color: #333333;\">-&gt;<\/span> session<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">sessionCreationPolicy<\/span><span style=\"color: #333333;\">(<\/span>SessionCreationPolicy<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">STATELESS<\/span><span style=\"color: #333333;\">))<\/span>\r\n        <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">httpBasic<\/span><span style=\"color: #333333;\">(<\/span>Customizer<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">withDefaults<\/span><span style=\"color: #333333;\">())<\/span>\r\n        <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">build<\/span><span style=\"color: #333333;\">();<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Create a Test User Bean<\/strong><\/h4>\n<p>For this tutorial, we would create a user in memory. In the following tutorial, we would implemented UserDetailsService.<\/p>\n<p>1. Create the InMemoryUserDetailsManager bean as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Bean<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> InMemoryUserDetailsManager <span style=\"color: #0066bb; font-weight: bold;\">manager<\/span><span style=\"color: #333333;\">(){<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">InMemoryUserDetailsManager<\/span><span style=\"color: #333333;\">(<\/span>\r\n            User<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">withUsername<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"kindson\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n                    <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">password<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"{noop}password\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n                    <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">authorities<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"read\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n                    <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">build<\/span><span style=\"color: #333333;\">()<\/span>\r\n    <span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Configure the ResourceServer<\/strong><\/h4>\n<p>An OAuth2 resource server in Spring is a server that protects resources (e.g., APIs) and ensures that requests are authenticated using access tokens, typically issued by an OAuth2 authorization server.<\/p>\n<p>We would have to tell Spring that our service is an OAuth2 resource server.<\/p>\n<p>1. Add this line just before the sessionManagement line in the SecurityFilterChain bean<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">oauth2ResourceServer<\/span><span style=\"color: #333333;\">(<\/span>oauth2 <span style=\"color: #333333;\">-&gt;<\/span> oauth2<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jwt<\/span><span style=\"color: #333333;\">(<\/span>Customizer<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">withDefaults<\/span><span style=\"color: #333333;\">()))<\/span> \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>2. Run the application. Note that you will have the exception below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Parameter 0 of method setFilterChains in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' that could not be found.\r\n<\/pre>\n<p>To create a JwtDecoder, we would need to create a public\/private key pair.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Create a Public\/Private Key Pair<\/strong><\/h4>\n<p>We would use the openssl tool in Mac to create the keys<\/p>\n<p>1. Create a folder called certs in the resources folder<\/p>\n<p>2. Navigate to this certs directory in the terminal and run the following command<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">openssl genrsa -out keypair.pem 2048\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>3. Run the following command to extract the public key.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">openssl rsa -in keypair.pem -pubout -out public.pem\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>4. Run the following command to create a private key in the required format: pkcs8<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out private.pem\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>5. Delete the keypair.pem<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Create Some Configuration to Externalize the Keys<\/strong><\/h4>\n<p>1. Create a\u00a0 record and call it RsaKeyProperties. This would have two fields as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@ConfigurationProperties<\/span><span style=\"color: #333333;\">(<\/span>prefix <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"rsa\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> record <span style=\"color: #0066bb; font-weight: bold;\">RsaKeyProperties<\/span><span style=\"color: #333333;\">(<\/span>RSAPublicKey publicKey<span style=\"color: #333333;\">,<\/span> RSAPrivateKey privateKey<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>2. Set the values in the application.properties file<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">rsa<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">private<\/span><span style=\"color: #333333;\">-<\/span>key<span style=\"color: #333333;\">=<\/span><span style=\"color: #997700; font-weight: bold;\">classpath:<\/span>certs<span style=\"color: #333333;\">\/<\/span><span style=\"color: #008800; font-weight: bold;\">private<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">pem<\/span>\r\nrsa<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">public<\/span><span style=\"color: #333333;\">-<\/span>key<span style=\"color: #333333;\">=<\/span><span style=\"color: #997700; font-weight: bold;\">classpath:<\/span>certs<span style=\"color: #333333;\">\/<\/span><span style=\"color: #008800; font-weight: bold;\">public<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">pem<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>3. Annotate the main class with @EnableConfigurationProperties like so<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@EnableConfigurationProperties<\/span><span style=\"color: #333333;\">(<\/span>RsaKeyProperties<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">class<\/span><span style=\"color: #333333;\">)<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Create the JwtDecoder and JwtEncoder Bean<\/strong><\/h4>\n<p>We would need the keys to be able to create a JwtDecoder. This would be used to decipher the token<\/p>\n<p>1. Inject the RsaKeyProperties into the SecurityConfig as shown:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #008800; font-weight: bold;\">final<\/span> RsaKeyProperties properties<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #0066bb; font-weight: bold;\">SecurityConfig<\/span><span style=\"color: #333333;\">(<\/span>RsaKeyProperties properties<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">properties<\/span> <span style=\"color: #333333;\">=<\/span> properties<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>2. Defined the decoder using the keys:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Bean<\/span>\r\nJwtDecoder <span style=\"color: #0066bb; font-weight: bold;\">jwtDecoder<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> NimbusJwtDecoder<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">withPublicKey<\/span><span style=\"color: #333333;\">(<\/span>properties<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">publicKey<\/span><span style=\"color: #333333;\">()).<\/span><span style=\"color: #0000cc;\">build<\/span><span style=\"color: #333333;\">();<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>3. Create the JwtEncoder Bean<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Bean<\/span>\r\nJwtEncoder <span style=\"color: #0066bb; font-weight: bold;\">jwtEncoder<\/span><span style=\"color: #333333;\">(){<\/span>\r\n    JWK jwk <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> RSAKey<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">Builder<\/span><span style=\"color: #333333;\">(<\/span>rsaKeyProperties<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">publicKey<\/span><span style=\"color: #333333;\">()).<\/span><span style=\"color: #0000cc;\">privateKey<\/span><span style=\"color: #333333;\">(<\/span>rsaKeyProperties<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">privateKey<\/span><span style=\"color: #333333;\">()).<\/span><span style=\"color: #0000cc;\">build<\/span><span style=\"color: #333333;\">();<\/span>\r\n    JWKSource<span style=\"color: #333333;\">&lt;<\/span>SecurityContext<span style=\"color: #333333;\">&gt;<\/span> jwkSource <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ImmutableJWKSet<span style=\"color: #333333;\">&lt;&gt;(<\/span><span style=\"color: #008800; font-weight: bold;\">new<\/span> JWKSet<span style=\"color: #333333;\">(<\/span>jwk<span style=\"color: #333333;\">));<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">NimbusJwtEncoder<\/span><span style=\"color: #333333;\">(<\/span>jwkSource<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t8\">8. Create the TokenService<\/strong><\/h4>\n<p>We would need a service that contains the generateToken method. The method would create a token and encode it using the JwtEncoder.<\/p>\n<p>1. Create the TokenService inside the service package<\/p>\n<p>2. Get a reference to the JwtEncoder bean<\/p>\n<p>3. Create the method as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">generateToken<\/span><span style=\"color: #333333;\">(<\/span>Authentication authentication<span style=\"color: #333333;\">){<\/span>\r\n    Instant now <span style=\"color: #333333;\">=<\/span> Instant<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">now<\/span><span style=\"color: #333333;\">();<\/span>\r\n    String scope <span style=\"color: #333333;\">=<\/span> authentication<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getAuthorities<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">stream<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">map<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #997700; font-weight: bold;\">GrantedAuthority:<\/span><span style=\"color: #333333;\">:<\/span>getAuthority<span style=\"color: #333333;\">)<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">collect<\/span><span style=\"color: #333333;\">(<\/span>Collectors<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">joining<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\" \"<\/span><span style=\"color: #333333;\">));<\/span>\r\n    JwtClaimsSet claimsSet <span style=\"color: #333333;\">=<\/span> JwtClaimsSet<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">builder<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">issuer<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"self\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">issuedAt<\/span><span style=\"color: #333333;\">(<\/span>now<span style=\"color: #333333;\">)<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">expiresAt<\/span><span style=\"color: #333333;\">(<\/span>now<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">plus<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span><span style=\"color: #333333;\">,<\/span> ChronoUnit<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">HOURS<\/span><span style=\"color: #333333;\">))<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">claim<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"scope\"<\/span><span style=\"color: #333333;\">,<\/span> scope<span style=\"color: #333333;\">)<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">build<\/span><span style=\"color: #333333;\">();<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jwtEncoder<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">encode<\/span><span style=\"color: #333333;\">(<\/span>JwtEncoderParameters<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">from<\/span><span style=\"color: #333333;\">(<\/span>claimsSet<span style=\"color: #333333;\">)).<\/span><span style=\"color: #0000cc;\">getTokenValue<\/span><span style=\"color: #333333;\">();<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Note: See the video tutorial to understand each section of the code<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t9\">9. Create the AuthController<\/strong><\/h4>\n<p>We would need the controller that exposes an endpoint of &#8220;\/token&#8221;. This would call the createToken service and return the created token.<\/p>\n<p>1. Create the AuthController.java file in the controller package<\/p>\n<p>2. Inject the TokenService.<\/p>\n<p>3. Optionally create a Logger to log debug messages.<\/p>\n<p>4. Write the getToken controller method as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@PostMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/token\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">getToken<\/span><span style=\"color: #333333;\">(<\/span>Authentication authentication<span style=\"color: #333333;\">){<\/span>\r\n    LOGGER<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">debug<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Token requested form user: {}\"<\/span><span style=\"color: #333333;\">,<\/span> authentication<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getName<\/span><span style=\"color: #333333;\">());<\/span>\r\n    String token <span style=\"color: #333333;\">=<\/span> tokenService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">generateToken<\/span><span style=\"color: #333333;\">(<\/span>authentication<span style=\"color: #333333;\">);<\/span>\r\n    LOGGER<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">debug<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Token granted {}\"<\/span><span style=\"color: #333333;\">,<\/span> token<span style=\"color: #333333;\">);<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> token<span style=\"color: #333333;\">;<\/span>    <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/youtu.be\/IZ2QEPhO7A4?si=8HQnE0eaDwmK4ddP\" target=\"_blank\" rel=\"noopener\">Video Tutorial &#8211;\u00a0The New JWT \u2013 How to Secure REST API Using Json Web Token in Spring Boot<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a tutorial on how to implement Json Web Token authentication for a REST API in Spring Boot using public and private keys. In &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[289],"tags":[],"class_list":["post-2007","post","type-post","status-publish","format-standard","hentry","category-rest-web-services"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=2007"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2007\/revisions"}],"predecessor-version":[{"id":2175,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2007\/revisions\/2175"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=2007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=2007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=2007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}