{"id":55118,"date":"2022-06-12T03:18:59","date_gmt":"2022-06-12T03:18:59","guid":{"rendered":"https:\/\/ampscript.guide\/?p=55118"},"modified":"2022-06-12T03:18:59","modified_gmt":"2022-06-12T03:18:59","slug":"getjwt","status":"publish","type":"post","link":"https:\/\/ampscript.guide\/getjwt\/","title":{"rendered":"GetJWT"},"content":{"rendered":"<h2>GetJWT<\/h2>\n<p>This function creates a JSON Web Token (JWT) of a JSON formatted payload. <\/p>\n<p>JWT, or JSON Web Token, is an open standard used to share security information between a client and a server. A JWT contains encoded JSON objects, including a set of claims (for example, JSON formatted key-value pairs). JWTs are signed using a cryptographic algorithm to ensure that the claims cannot be altered after the token is issued. Essentially, a JWT provides a method for validating that the data contained within it can be trusted.<\/p>\n<p>A JWT consists of three parts:<\/p>\n<ol>\n<li>A header (Base64 encoded)<\/li>\n<li>A payload of claims (also Base64 encoded)<\/li>\n<li>An encrypted HMAC signature<\/li>\n<\/ol>\n<p>These three parts appear as a concatenated string, delimited by periods. The signature is built from all parts, so if the JWT is modified, then signature will change and it won&#8217;t match the original signature.<\/p>\n<h3>Arguments<\/h3>\n<p><code>GetJWT(1,2,3)<\/code><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">Ordinal<\/th>\n<th style=\"text-align: left;\">Type<\/th>\n<th style=\"text-align: left;\">Required<\/th>\n<th style=\"text-align: left;\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">1<\/td>\n<td style=\"text-align: left;\">String<\/td>\n<td style=\"text-align: left;\">True<\/td>\n<td style=\"text-align: left;\">Secret as string value<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">2<\/td>\n<td style=\"text-align: left;\">String<\/td>\n<td style=\"text-align: left;\">True<\/td>\n<td style=\"text-align: left;\">Hash algorithm used to encrypt the signature. Valid values are <code>HS256<\/code>, <code>HS384<\/code>, or <code>HS512<\/code>.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">3<\/td>\n<td style=\"text-align: left;\">String<\/td>\n<td style=\"text-align: left;\">True<\/td>\n<td style=\"text-align: left;\">The payload string to encode (typically in JSON format)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p>NOTE: This function does not encrypt the payload.<\/p>\n<p>NOTE: <a href=\"\/getjwtbykeyname\">GetJWTByKeyName<\/a> is the recommended function for creating JWTs, as <code>GetJWT<\/code> exposes the hard-coded secret in the server-side code (so it&#8217;s not a secret anymore), whereas <code>GetJWTByKeyName<\/code> retrieves the secret from Key Management, and access to this platform feature can be limited to individual users or roles.<\/p>\n<\/blockquote>\n<h3>Example<\/h3>\n<pre><code>%%[\nvar @json, @secret, @jwt\n\nset @json = '{\n  \"ContactKey\": \"00Q6F00001APnymUAD\",\n  \"FirstName\": \"Samantha\",\n  \"LastName\": \"Smith\",\n  \"Email\": \"samantha@limedash.com\"\n}'\nset @secret = 'x!A%C*F-JaNdRgUkXp2s5v8y\/B?E(G+K'\nset @jwt = GetJWT(@secret, 'HS256', @json)\n\n]%%\n\nJWT: %%=v(@jwt)=%%<\/code><\/pre>\n<h4>Output<\/h4>\n<pre><code>JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ew0KICAiQ29udGFjdEtleSI6ICIwMFE2RjAwMDAxQVBueW1VQUQiLA0KICAiRmlyc3ROYW1lIjogIlNhbWFudGhhIiwNCiAgIkxhc3ROYW1lIjogIlNtaXRoIiwNCiAgIkVtYWlsIjogInNhbWFudGhhQGxpbWVkYXNoLmNvbSINCn0.QJw_GNupl6kaVf_MjlIWaykIOA9Z4pu_wPx4dvZGXzk<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GetJWT This function creates a JSON Web Token (JWT) of a JSON formatted payload. JWT, or JSON Web Token, is an open standard used to share security information between a client and a server. A JWT contains encoded JSON objects, including a set of claims (for example, JSON formatted key-value pairs). JWTs are signed using [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v14.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GetJWT - The AMPscript Guide<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ampscript.guide\/getjwt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GetJWT - The AMPscript Guide\" \/>\n<meta property=\"og:description\" content=\"GetJWT This function creates a JSON Web Token (JWT) of a JSON formatted payload. JWT, or JSON Web Token, is an open standard used to share security information between a client and a server. A JWT contains encoded JSON objects, including a set of claims (for example, JSON formatted key-value pairs). JWTs are signed using [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ampscript.guide\/getjwt\/\" \/>\n<meta property=\"og:site_name\" content=\"The AMPscript Guide\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-12T03:18:59+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ampscript.guide\/#website\",\"url\":\"https:\/\/ampscript.guide\/\",\"name\":\"The AMPscript Guide\",\"description\":\"The Definitive Scripting Manual for Salesforce Marketing Cloud\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/ampscript.guide\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ampscript.guide\/getjwt\/#webpage\",\"url\":\"https:\/\/ampscript.guide\/getjwt\/\",\"name\":\"GetJWT - The AMPscript Guide\",\"isPartOf\":{\"@id\":\"https:\/\/ampscript.guide\/#website\"},\"datePublished\":\"2022-06-12T03:18:59+00:00\",\"dateModified\":\"2022-06-12T03:18:59+00:00\",\"author\":{\"@id\":\"https:\/\/ampscript.guide\/#\/schema\/person\/8b5da668926fdaf9cb0d932cf42b079b\"},\"breadcrumb\":{\"@id\":\"https:\/\/ampscript.guide\/getjwt\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ampscript.guide\/getjwt\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ampscript.guide\/getjwt\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ampscript.guide\/\",\"url\":\"https:\/\/ampscript.guide\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ampscript.guide\/getjwt\/\",\"url\":\"https:\/\/ampscript.guide\/getjwt\/\",\"name\":\"GetJWT\"}}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/ampscript.guide\/#\/schema\/person\/8b5da668926fdaf9cb0d932cf42b079b\",\"name\":\"Adam Spriggs\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/posts\/55118"}],"collection":[{"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/comments?post=55118"}],"version-history":[{"count":0,"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/posts\/55118\/revisions"}],"wp:attachment":[{"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/media?parent=55118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/categories?post=55118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ampscript.guide\/wp-json\/wp\/v2\/tags?post=55118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}