{"id":407,"date":"2021-05-02T20:39:51","date_gmt":"2021-05-02T20:39:51","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?p=407"},"modified":"2021-05-02T20:39:51","modified_gmt":"2021-05-02T20:39:51","slug":"jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/","title":{"rendered":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2"},"content":{"rendered":"<p>In <a href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-1\/\" target=\"_blank\" rel=\"noopener\">Part 1<\/a>, we were able to setup a Spring Boot application to use JWT. We also wrote to code to generate the JSON Web Token(JWT). In this part, you will learn how to do authorization using the JWT.<\/p>\n<p><strong>Basics<\/strong><\/p>\n<p>The generated token would have to be added to subsequent requests. Then spring security would be configured to intercept incoming requests, checking for JWT in the header. If it finds JWT, it does the following;<\/p>\n<ul>\n<li>intercept every request and extract the JWT<\/li>\n<li>validate the JWT<\/li>\n<li>set the JWT in the execution context<\/li>\n<\/ul>\n<p>As usual, we would follow the step by step.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create Filter and implement the filter method. This is a way to intercept a request. So create filter class that extends OncePerRequestFilter. I call this class JwtRequestFilter.<\/p>\n<p>Autowire the MyUserDetails service and the JwtUtility into this class<\/p>\n<p>Then override the doFilterInternal() method.<\/p>\n<p>Annotate the class with @Component mapping.<\/p>\n<p>Extract the authorization header using request.getHeader() passing in the string &#8220;Authorization&#8221;<\/p>\n<p>Initialize the username and <em>jwtToken<\/em> variables<\/p>\n<p>Check if the <em>authorizationHeader<\/em> is not null and starts with &#8220;Bearer &#8221; and extract the jwtToken and username<\/p>\n<p>Next, check if the username is not null and SecurityContext is null ie authentication has not occurred. If so, then extract the userDetails, validate it using the validateToken method of the JwtUtility. If it validated, then create a new authentication token. Then using this token, set the the security context.<\/p>\n<p>At the end, you then call chain.doFilter() passing in the request and response.<\/p>\n<p>The complete doInternalFilter() method is given below:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Override<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">protected<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">doFilterInternal<\/span><span style=\"color: #333333;\">(<\/span>HttpServletRequest request<span style=\"color: #333333;\">,<\/span>\r\n                                HttpServletResponse response<span style=\"color: #333333;\">,<\/span>\r\n                                FilterChain filterChain<span style=\"color: #333333;\">)<\/span> <span style=\"color: #008800; font-weight: bold;\">throws<\/span> ServletException<span style=\"color: #333333;\">,<\/span> IOException <span style=\"color: #333333;\">{<\/span>\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">final<\/span> String authorizationHeader <span style=\"color: #333333;\">=<\/span> request<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getHeader<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Authorization\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\r\n    String username <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">;<\/span>\r\n    String jwtToken <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>authorizationHeader <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span> <span style=\"color: #333333;\">&amp;&amp;<\/span> authorizationHeader<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">startsWith<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Bearer \"<\/span><span style=\"color: #333333;\">))<\/span> <span style=\"color: #333333;\">{<\/span>\r\n        jwtToken <span style=\"color: #333333;\">=<\/span> authorizationHeader<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">substring<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #0000dd; font-weight: bold;\">7<\/span><span style=\"color: #333333;\">);<\/span>\r\n        username <span style=\"color: #333333;\">=<\/span> jwtUtility<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getUsernameFromToken<\/span><span style=\"color: #333333;\">(<\/span>jwtToken<span style=\"color: #333333;\">);<\/span>\r\n    <span style=\"color: #333333;\">}<\/span>\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>username <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span> <span style=\"color: #333333;\">&amp;&amp;<\/span> SecurityContextHolder<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getContext<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">getAuthentication<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">){<\/span>\r\n        UserDetails userDetails <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">myUserDetailsService<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">loadUserByUsername<\/span><span style=\"color: #333333;\">(<\/span>username<span style=\"color: #333333;\">);<\/span>\r\n        <span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>jwtUtility<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">validateToken<\/span><span style=\"color: #333333;\">(<\/span>jwtToken<span style=\"color: #333333;\">,<\/span> userDetails<span style=\"color: #333333;\">)){<\/span>\r\n            UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> UsernamePasswordAuthenticationToken<span style=\"color: #333333;\">(<\/span>\r\n                    userDetails<span style=\"color: #333333;\">,<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">,<\/span> userDetails<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getAuthorities<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <span style=\"color: #333333;\">);<\/span>\r\n            usernamePasswordAuthenticationToken<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">setDetails<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">new<\/span> WebAuthenticationDetailsSource<span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">buildDetails<\/span><span style=\"color: #333333;\">(<\/span>request<span style=\"color: #333333;\">));<\/span>\r\n            SecurityContextHolder<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getContext<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">setAuthentication<\/span><span style=\"color: #333333;\">(<\/span>usernamePasswordAuthenticationToken<span style=\"color: #333333;\">);<\/span>\r\n        <span style=\"color: #333333;\">}<\/span>\r\n    <span style=\"color: #333333;\">}<\/span>\r\n    filterChain<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">doFilter<\/span><span style=\"color: #333333;\">(<\/span>request<span style=\"color: #333333;\">,<\/span> response<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Tell the SecurityConfigurer to use the filter chain and also make session management policy to be stateless.\u00a0 You need to go to the SecurityConfigurer class and modify the configure method like so<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@Override<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">protected<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">configure<\/span><span style=\"color: #333333;\">(<\/span>HttpSecurity http<span style=\"color: #333333;\">)<\/span> <span style=\"color: #008800; font-weight: bold;\">throws<\/span> Exception <span style=\"color: #333333;\">{<\/span>\r\n    http<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">csrf<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">disable<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">authorizeRequests<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">antMatchers<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/authenticate\"<\/span><span style=\"color: #333333;\">).<\/span><span style=\"color: #0000cc;\">permitAll<\/span><span style=\"color: #333333;\">()<\/span>\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><span style=\"color: #0000cc;\">and<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">sessionManagement<\/span><span style=\"color: #333333;\">()<\/span>\r\n            <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    http<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">addFilterBefore<\/span><span style=\"color: #333333;\">(<\/span>jwtRequestFilter<span style=\"color: #333333;\">,<\/span> UsernamePasswordAuthenticationFilter<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">class<\/span><span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Notice two things from the above code:<\/p>\n<ul>\n<li>session managment have been added<\/li>\n<li>our jwtRequestFilter have been added using addFilterBefore<\/li>\n<\/ul>\n<p>Finally, we are done!<\/p>\n<p>You can now fire up the application and test it using postman. First do a request to \/authenticate. Then use the returned token to make a request to the &#8220;\/&#8221; route and all is fine.<\/p>\n<p>I recommend you watch the video on my YouTube Channel.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In Part 1, we were able to setup a Spring Boot application to use JWT. We also wrote to code to generate the JSON Web &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":409,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[46,44],"class_list":["post-407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot-tutorials","tag-json-web-token","tag-jwt"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot<\/title>\n<meta name=\"description\" content=\"In this tutorial you&#039;ll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot\" \/>\n<meta property=\"og:description\" content=\"In this tutorial you&#039;ll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Spring Boot\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-02T20:39:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"637\" \/>\n\t<meta property=\"og:image:height\" content=\"212\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2\",\"datePublished\":\"2021-05-02T20:39:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/\"},\"wordCount\":370,\"commentCount\":2,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/05\\\/JWT-Authentication-in-Spring-Boot-1.jpg\",\"keywords\":[\"JSON Web Token\",\"JWT\"],\"articleSection\":[\"Spring Boot Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/\",\"name\":\"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/05\\\/JWT-Authentication-in-Spring-Boot-1.jpg\",\"datePublished\":\"2021-05-02T20:39:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"description\":\"In this tutorial you'll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/05\\\/JWT-Authentication-in-Spring-Boot-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2021\\\/05\\\/JWT-Authentication-in-Spring-Boot-1.jpg\",\"width\":637,\"height\":212,\"caption\":\"JWT Authentication in Spring Boot\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\",\"name\":\"Learn Spring Boot\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot","description":"In this tutorial you'll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/","og_locale":"en_US","og_type":"article","og_title":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot","og_description":"In this tutorial you'll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.","og_url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/","og_site_name":"Learn Spring Boot","article_published_time":"2021-05-02T20:39:51+00:00","og_image":[{"width":637,"height":212,"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2","datePublished":"2021-05-02T20:39:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/"},"wordCount":370,"commentCount":2,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg","keywords":["JSON Web Token","JWT"],"articleSection":["Spring Boot Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/","name":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2 - Learn Spring Boot","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg","datePublished":"2021-05-02T20:39:51+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"description":"In this tutorial you'll learn how to configure a spring boot API to using JWT(JSON Web Token) for authentication.","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2021\/05\/JWT-Authentication-in-Spring-Boot-1.jpg","width":637,"height":212,"caption":"JWT Authentication in Spring Boot"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/jwtjson-web-token-with-springboot-step-by-step-tutorial-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/spring-boot\/"},{"@type":"ListItem","position":2,"name":"JWT(JSON Web Token) With SpringBoot \u2013 Step by Step Tutorial \u2013 Part 2"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/","name":"Learn Spring Boot","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/comments?post=407"}],"version-history":[{"count":2,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"predecessor-version":[{"id":410,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/407\/revisions\/410"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media\/409"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}