{"id":12293,"date":"2025-05-14T19:15:00","date_gmt":"2025-05-15T00:15:00","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=12293"},"modified":"2026-05-20T15:46:47","modified_gmt":"2026-05-20T20:46:47","slug":"getting-an-oauth-token-for-bearer-auth","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=12293","title":{"rendered":"Getting an OAUTH Token for Bearer Auth"},"content":{"rendered":"\n<p>Quick script to mint and decode an OAUTH bearer token &#8230; requires CLIENT_ID and CLIENT_SECRET variables with data. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nTOKEN_URL=&#039;https:\/\/oauth.example.com\/as\/token.oauth2&#039;\nINTROSPECT_URL=&#039;https:\/\/oauth.example.com\/as\/introspect.oauth2&#039;\n\n\nTOKEN=$(curl -s -k -X POST &quot;$TOKEN_URL&quot; \\\n\u00a0 -H &#039;Content-Type: application\/x-www-form-urlencoded&#039; \\\n\u00a0 -u &quot;${CLIENT_ID}:${CLIENT_SECRET}&quot; \\\n\u00a0 -d &#039;grant_type=client_credentials&amp;scope=openid profile email&#039; | jq -r &#039;.access_token&#039;)\n\n\nif &#x5B; -z &quot;$TOKEN&quot; ] || &#x5B; &quot;$TOKEN&quot; = &quot;null&quot; ]; then\n  echo &quot;Failed to obtain access token&quot;\n  exit 1\nfi\n\necho &quot;=== JWT HEADER ===&quot;\nHEADER=$(echo &quot;$TOKEN&quot; | cut -d &#039;.&#039; -f1)\nLEN=$(( ${#HEADER} % 4 ))\nif &#x5B; $LEN -eq 2 ]; then HEADER=&quot;${HEADER}==&quot;; fi\nif &#x5B; $LEN -eq 3 ]; then HEADER=&quot;${HEADER}=&quot;; fi\necho &quot;$HEADER&quot; | tr &#039;_-&#039; &#039;\/+&#039; | base64 -d 2&gt;\/dev\/null | jq\n\necho\necho &quot;=== JWT PAYLOAD ===&quot;\nPAYLOAD=$(echo &quot;$TOKEN&quot; | cut -d &#039;.&#039; -f2)\nLEN=$(( ${#PAYLOAD} % 4 ))\nif &#x5B; $LEN -eq 2 ]; then PAYLOAD=&quot;${PAYLOAD}==&quot;; fi\nif &#x5B; $LEN -eq 3 ]; then PAYLOAD=&quot;${PAYLOAD}=&quot;; fi\necho &quot;$PAYLOAD&quot; | tr &#039;_-&#039; &#039;\/+&#039; | base64 -d 2&gt;\/dev\/null | jq\n\necho\necho &quot;=== INTROSPECTION ===&quot;\ncurl -s -k \\\n  -u &quot;${CLIENT_ID}:${CLIENT_SECRET}&quot; \\\n  -H &#039;Content-Type: application\/x-www-form-urlencoded&#039; \\\n  -d &quot;token=$TOKEN&quot; \\\n  &quot;$INTROSPECT_URL&quot; | jq\n\n\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick script to mint and decode an OAUTH bearer token &#8230; requires CLIENT_ID and CLIENT_SECRET variables with data.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[1488,1489],"class_list":["post-12293","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-oauth","tag-oauth2"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12293"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12293\/revisions"}],"predecessor-version":[{"id":12296,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12293\/revisions\/12296"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}