{"id":87471,"date":"2019-01-28T09:33:19","date_gmt":"2019-01-28T07:33:19","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=87471"},"modified":"2019-02-04T09:25:10","modified_gmt":"2019-02-04T07:25:10","slug":"tutorial-create-verify-jwts-java","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2019\/01\/tutorial-create-verify-jwts-java.html","title":{"rendered":"Tutorial: Create and Verify JWTs in Java"},"content":{"rendered":"<p><span style=\"font-size: 20px;\"><b>\u201cI love writing authentication and authorization code.\u201d ~ No Java Developer Ever.<\/b> Tired of building the same login screens over and over? <a href=\"https:\/\/developer.okta.com\/signup?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">Try the Okta API for hosted authentication, authorization, and multi-factor auth.<\/a><\/span><\/p>\n<p>Java support for JWT (JSON Web Tokens) used to require a lot of work: extensive customization, hours lost resolving dependencies, and pages of code just to assemble a simple JWT. Not anymore!<\/p>\n<p>This tutorial will show you how to use an existing JWT library to do two things:<\/p>\n<ol class=\"wp-block-list\">\n<li>Generate a JWT<\/li>\n<li>Decode and verify a JWT<\/li>\n<\/ol>\n<p>You\u2019ll notice the tutorial is pretty short. That\u2019s because it\u2019s that easy. If you\u2019d like to dig deeper, take a look at the&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7519\">JWT Spec<\/a>&nbsp;or dive into&nbsp;<a href=\"https:\/\/developer.okta.com\/blog\/2018\/10\/16\/token-auth-for-java\">this longer post<\/a>&nbsp;about using JWTs for token authentication in Spring Boot apps.<\/p>\n<h2 class=\"wp-block-heading\" id=\"what-are-jwts\">What are JWTs?<\/h2>\n<p>JSON Web Tokens are JSON objects used to send information between parties in a compact and secure manner. The&nbsp;<a href=\"https:\/\/www.json.org\/\">JSON spec<\/a>, or Javascript Object Notation, defines a way of creating plain text objects using key value pairs. It\u2019s a compact way of structuring data built upon primitive types (numbers, strings, etc\u2026). You\u2019re probably already pretty familiar with JSON. It\u2019s like XML without all the brackets.<\/p>\n<p>Tokens can be used to send arbitrary state between parties. Often here \u201cparties\u201d means a client web application and a server. JWTs have many uses: authentication mechanism, url-safe encoding, securely sharing private data, interoperability, data expiration, etc.<\/p>\n<p>In practice, this information is often about two things: authorization and session state. JWTs can be used by a server to tell the client app what actions the user is allowed to execute (or what data they are allowed to access).<\/p>\n<p>JWTs are often also used to store state-dependent user data for a web session. Because the JWT is passed back and forth between the client app and the server, it means that state data does not have to be stored in a database somewhere (and subsequently retrieved on every request); because of this, it scales well.<\/p>\n<p>Let\u2019s take a look at an example JWT (taken from&nbsp;<a href=\"https:\/\/www.jsonwebtoken.io\/\">jsonwebtoken.io<\/a>)<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/01\/jwt-decoded-screenshot.png\" alt=\"JWTs in Java\" class=\"wp-image-87472\" width=\"820\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/01\/jwt-decoded-screenshot.png 860w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/01\/jwt-decoded-screenshot-300x228.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/01\/jwt-decoded-screenshot-768x583.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/figure>\n<\/div>\n<p>JWTs have three parts: a header, a body, and a signature. The header contains info on how the JWT is encoded. The body is the&nbsp;<em>meat<\/em>&nbsp;of the token (where the&nbsp;<strong>claims<\/strong>&nbsp;live). The signature provides the security.<\/p>\n<p>There\u2019s a lot of detail we\u2019re not going to go into here regarding how tokens are encoded and how information is stored in the body. Check out&nbsp;<a href=\"https:\/\/developer.okta.com\/blog\/2018\/10\/16\/token-auth-for-java?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">the previously mentioned tutorial<\/a>&nbsp;if you want.<\/p>\n<p><strong>Don\u2019t forget:<\/strong>&nbsp;cryptographic signatures do not provide confidentiality; they are simply a way of detecting tampering with a JWT, and unless a JWT is specifically encrypted, they are publicly visible. The signature simply provides a secure way of verifying the contents.<\/p>\n<p>Great. Got it? Now you need to make a token with JJWT! For this tutorial, we\u2019re using an existing JWT library.&nbsp;<a href=\"https:\/\/github.com\/jwtk\/jjwt\">Java JWT<\/a>&nbsp;(a.k.a., JJWT) was created by&nbsp;<a href=\"https:\/\/twitter.com\/lhazlewood\">Les Hazlewood<\/a>&nbsp;(lead committer to Apache Shiro, former co-founder and CTO at Stormpath, and currently Okta\u2019s very own Senior Architect), JJWT is a Java library that simplifies JWT creation and verification. It is based exclusively on the&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7519\">JWT<\/a>,&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7515\">JWS<\/a>,&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7516\">JWE<\/a>,&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7517\">JWK<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7518\">JWA<\/a>&nbsp;RFC specifications and open source under the terms of the&nbsp;<a href=\"http:\/\/www.apache.org\/licenses\/LICENSE-2.0\">Apache 2.0 License<\/a>. The library also adds some nice features to the spec, such as JWT compression and claims enforcement.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2 class=\"wp-block-heading\" id=\"generate-a-token-in-java\">Generate a Token in Java<\/h2>\n<p>This parts super easy. Let\u2019s look at some code. Clone the&nbsp;<a href=\"https:\/\/github.com\/oktadeveloper\/okta-java-jwt-example\">GitHub repo<\/a>:<\/p>\n<pre class=\"wp-block-preformatted gutter: false;brush:bash\"> git clone https:\/\/github.com\/oktadeveloper\/okta-java-jwt-example.git \n cd okta-java-jwt-example<\/pre>\n<p>This example is pretty basic, and contains a&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">src\/main\/java\/JWTDemo.java<\/code>&nbsp;class file with two static methods:&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">createJWT()<\/code>and&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">decodeJWT()<\/code>. Cunningly enough, these two methods create a JWT and decode a JWT. Take a look at the first method below.<\/p>\n<pre class=\"wp-block-preformatted gutter: false;brush:java\">public static String createJWT(String id, String issuer, String subject, long ttlMillis) {\n  \n    \/\/The JWT signature algorithm we will be using to sign the token\n    SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;\n\n    long nowMillis = System.currentTimeMillis();\n    Date now = new Date(nowMillis);\n\n    \/\/We will sign our JWT with our ApiKey secret\n    byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(SECRET_KEY);\n    Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());\n\n    \/\/Let's set the JWT Claims\n    JwtBuilder builder = Jwts.builder().setId(id)\n            .setIssuedAt(now)\n            .setSubject(subject)\n            .setIssuer(issuer)\n            .signWith(signatureAlgorithm, signingKey);\n  \n    \/\/if it has been specified, let's add the expiration\n    if (ttlMillis &gt; 0) {\n        long expMillis = nowMillis + ttlMillis;\n        Date exp = new Date(expMillis);\n        builder.setExpiration(exp);\n    }  \n  \n    \/\/Builds the JWT and serializes it to a compact, URL-safe string\n    return builder.compact();\n}\n<\/pre>\n<p>To summarize, the&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">createJWT()<\/code>&nbsp;method does the following:<\/p>\n<ul class=\"wp-block-list\">\n<li>Sets the hashing algorithm<\/li>\n<li>Gets the current date for the&nbsp;<strong>Issued At<\/strong>&nbsp;claim<\/li>\n<li>Uses the SECRET_KEY static property to generate the signing key<\/li>\n<li>Uses the fluent API to add the claims and sign the JWT<\/li>\n<li>Sets the expiration date<\/li>\n<\/ul>\n<p>This could be customized to your needs. If, for example, you wanted to add different or custom claims.<\/p>\n<h2 class=\"wp-block-heading\" id=\"decode-a-token\">Decode a Token<\/h2>\n<p>Now take a look at the even simpler&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">decodeJWT()<\/code>&nbsp;method.<\/p>\n<pre class=\"wp-block-preformatted gutter: false;brush:java\">public static Claims decodeJWT(String jwt) {\n    \/\/This line will throw an exception if it is not a signed JWS (as expected)\n    Claims claims = Jwts.parser()\n            .setSigningKey(DatatypeConverter.parseBase64Binary(SECRET_KEY))\n            .parseClaimsJws(jwt).getBody();\n    return claims;\n}<\/pre>\n<p>The method again uses the static&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">SECRET_KEY<\/code>&nbsp;property to generate the signing key, and uses that to verify that the JWT has not been tampered with. The method will throw&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">io.jsonwebtoken.SignatureException<\/code>&nbsp;exception if the signature does not match the token. If the signature does match, the method returns the claims as a&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">Claims<\/code>&nbsp;object.<\/p>\n<p>That\u2019s pretty much it!<\/p>\n<h2 class=\"wp-block-heading\" id=\"run-the-junit-tests\">Run the JUnit Tests<\/h2>\n<p>For extra credit, you can run the JUnit tests in the example project. There are three tests, and they demonstrate some basic features on the JJWT library. The first test shows the happy path, creating and successfully decoding a valid JWT. The second test shows how the JJWT library will fail when you attempt to decode a totally bogus string as a JWT. The last test shows how a tampered-with JJWT will cause the&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">decodeJWT()<\/code>&nbsp;method to throw a&nbsp;<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">SignatureException<\/code>.<\/p>\n<p>You can run these tests from the command line using:<\/p>\n<pre class=\"wp-block-preformatted gutter: false;brush:bash\">.\/gradlew test -i<\/pre>\n<p>The&nbsp;<code>-i<\/code>&nbsp;is to set Gradle\u2019s log level to&nbsp;<code>Info<\/code>&nbsp;so that we see the simple logging output from the tests.<\/p>\n<h2 class=\"wp-block-heading\" id=\"learn-more-about-working-with-jwts-in-your-java-apps\">Learn More About Working with JWTs in Your Java Apps<\/h2>\n<p>The JJWT library makes it super easy to create and verify JWTs. Just specify a secret key and some claims, and you\u2019ve got a JJWT. Later, use the same secret key to decode the JJWT and verify its contents.<\/p>\n<p>Creating and using JJWTs is now so easy, why aren\u2019t you using them?<\/p>\n<p>Don\u2019t forget SSL! Remember that unless JWTs are encrypted, the information encoded within them is generally only Base64 encoded, which any small child and some pets can read. So unless you want China, Russia, and the FBI reading all of your session data, encrypt it using SSL.<\/p>\n<p>Baeldung has a&nbsp;<a href=\"https:\/\/www.baeldung.com\/java-json-web-tokens-jjwt\">pretty good in depth tutorial on Java and JWTs<\/a>.<\/p>\n<p>Also, here are some more links from the Okta blog to keep you going:<\/p>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.okta.com\/blog\/2018\/10\/16\/token-auth-for-java?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">Simple Token Authentication for Java Apps<\/a><\/li>\n<li><a href=\"https:\/\/developer.okta.com\/blog\/2017\/03\/21\/spring-boot-oauth?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">Get Started with Spring Boot, OAuth 2.0, and Okta<\/a><\/li>\n<li><a href=\"https:\/\/developer.okta.com\/blog\/2018\/07\/30\/10-ways-to-secure-spring-boot?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">10 Excellent Ways to Secure Your Spring Boot Application<\/a><\/li>\n<li><a href=\"https:\/\/developer.okta.com\/blog\/2018\/06\/20\/what-happens-if-your-jwt-is-stolen?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">What Happens If Your JWT Is Stolen?<\/a><\/li>\n<li><a href=\"https:\/\/chrome.google.com\/webstore\/detail\/jwt-analyzer-inspector\/henclmbnehmcpbjgipaajbggekefngob?hl=en\">JWT Analyzer &amp; Inspector Chrom Plugin<\/a><\/li>\n<li><a href=\"https:\/\/www.jsonwebtoken.io\/\">Encode or Decode JWTs online<\/a><\/li>\n<\/ul>\n<p>If you have any questions about this post, please add a comment below. For more awesome content, follow&nbsp;<a href=\"https:\/\/twitter.com\/oktadev\">@oktadev<\/a>&nbsp;on Twitter, like us&nbsp;<a href=\"https:\/\/www.facebook.com\/oktadevelopers\/\">on Facebook<\/a>, or subscribe to&nbsp;<a href=\"https:\/\/www.youtube.com\/channel\/UC5AMiWqFVFxF1q9Ya1FuZ_Q\">our YouTube channel<\/a>.<\/p>\n<p><span style=\"font-size: 20px;\"><b>\u201cI love writing authentication and authorization code.\u201d ~ No Java Developer Ever.<\/b> Tired of building the same login screens over and over? <a href=\"https:\/\/developer.okta.com\/signup?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\">Try the Okta API for hosted authentication, authorization, and multi-factor auth.<\/a><\/span><\/p>\n<p><a href=\"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java?utm_campaign=text_website_all_multiple_dev_ciam_jwts-with-java_null&amp;utm_source=jcg&amp;utm_medium=cpc\" target=\"_blank\" rel=\"noopener\" data-saferedirecturl=\"https:\/\/www.google.com\/url?q=https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java&amp;source=gmail&amp;ust=1548744105977000&amp;usg=AFQjCNHRMbIAbm2wmZ-qBjrD5_fetCxLNQ\">&#8216;Tutorial: Create and Verify JWTs in Java&#8217;<\/a>&nbsp;was originally published on the Okta developer blog on October 31, 2018.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cI love writing authentication and authorization code.\u201d ~ No Java Developer Ever. Tired of building the same login screens over and over? Try the Okta API for hosted authentication, authorization, and multi-factor auth. Java support for JWT (JSON Web Tokens) used to require a lot of work: extensive customization, hours lost resolving dependencies, and pages &hellip;<\/p>\n","protected":false},"author":49514,"featured_media":175,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[69,1289],"class_list":["post-87471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-json","tag-jwt"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tutorial: Create and Verify JWTs in Java - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial: Create and Verify JWTs in Java - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-28T07:33:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-04T07:25:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Hughes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Hughes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/01\\\/tutorial-create-verify-jwts-java.html\"},\"author\":{\"name\":\"Andrew Hughes\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0ded99ab51010abb68790f6189ce99d3\"},\"headline\":\"Tutorial: Create and Verify JWTs in Java\",\"datePublished\":\"2019-01-28T07:33:19+00:00\",\"dateModified\":\"2019-02-04T07:25:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/01\\\/tutorial-create-verify-jwts-java.html\"},\"wordCount\":1190,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"keywords\":[\"JSON\",\"JWT\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/01\\\/tutorial-create-verify-jwts-java.html\",\"url\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java\",\"name\":\"Tutorial: Create and Verify JWTs in Java - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"datePublished\":\"2019-01-28T07:33:19+00:00\",\"dateModified\":\"2019-02-04T07:25:10+00:00\",\"description\":\"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/developer.okta.com\\\/blog\\\/2018\\\/10\\\/31\\\/jwts-with-java#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Tutorial: Create and Verify JWTs in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0ded99ab51010abb68790f6189ce99d3\",\"name\":\"Andrew Hughes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g\",\"caption\":\"Andrew Hughes\"},\"sameAs\":[\"https:\\\/\\\/developer.okta.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/andrew-hughes\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial: Create and Verify JWTs in Java - Java Code Geeks","description":"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.","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:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java","og_locale":"en_US","og_type":"article","og_title":"Tutorial: Create and Verify JWTs in Java - Java Code Geeks","og_description":"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.","og_url":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-01-28T07:33:19+00:00","article_modified_time":"2019-02-04T07:25:10+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","type":"image\/jpeg"}],"author":"Andrew Hughes","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andrew Hughes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/01\/tutorial-create-verify-jwts-java.html"},"author":{"name":"Andrew Hughes","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0ded99ab51010abb68790f6189ce99d3"},"headline":"Tutorial: Create and Verify JWTs in Java","datePublished":"2019-01-28T07:33:19+00:00","dateModified":"2019-02-04T07:25:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/01\/tutorial-create-verify-jwts-java.html"},"wordCount":1190,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","keywords":["JSON","JWT"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2019\/01\/tutorial-create-verify-jwts-java.html","url":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java","name":"Tutorial: Create and Verify JWTs in Java - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#primaryimage"},"image":{"@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","datePublished":"2019-01-28T07:33:19+00:00","dateModified":"2019-02-04T07:25:10+00:00","description":"Interested to learn about JWTs in Java? Check our tutorial showing how to use an existing JWT library to Generate and Decode and verify a JWT.","breadcrumb":{"@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/developer.okta.com\/blog\/2018\/10\/31\/jwts-with-java#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Tutorial: Create and Verify JWTs in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0ded99ab51010abb68790f6189ce99d3","name":"Andrew Hughes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/703689ecb161268c8a6ca8ad4057b8342d22972ec435111a055712b399716dbd?s=96&d=mm&r=g","caption":"Andrew Hughes"},"sameAs":["https:\/\/developer.okta.com\/blog"],"url":"https:\/\/www.javacodegeeks.com\/author\/andrew-hughes"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/87471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/49514"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=87471"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/87471\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=87471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=87471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=87471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}