This repository shows how to locally validate a JWT with Go. Please read the blog post for this repo to see how this example was created.
Prerequisites:
Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage, and secure users and roles in any application.
To install this example, run the following commands:
git clone https://github.com/oktadeveloper/okta-offline-jwt-validation-example.git
cd okta-offline-jwt-validation-example
go get github.com/gin-gonic/gin
go get github.com/dgrijalva/jwt-go
Log in to your Okta Developer account (or sign up if you don’t have an account).
- From the Applications page, choose Add Application.
- On the Create New Application page, select Single-Page App.
- Give your app a memorable name, add
http://localhost:8080
as a Login redirect URI, then click Done.
There are two pieces of information that you need to obtain from the Okta Developer Console.
These are your Okta domain name (e.g. dev-12345.okta.com
) and your client id (e.g. 0ab1c2defg3AB4Chi567
).
Edit the file client/control.js
and replace ${yourOktaDomain}
and ${yourClientId}
with the values you created above.
Return to your terminal and set the $OKTA_DOMAIN
environment variable to your Okta domain name.
Replace okta12345.okta.com
with your Okta domain name.
export OKTA_DOMAIN="dev-12345.okta.com"
Then use this command to run the example:
go run main.go
Next, point a web browser at http://localhost:8080.
Enter a message and hit the submit button. You should get an authorization error.
Now, login and try sending another message. This should send a token that gets validated correctly. Your message should be displayed.
Learn more by reading the blog post.
This example uses the following open source libraries:
Please post any questions as comments on the blog post, or on the Okta Developer Forums.
Apache 2.0, see LICENSE.