Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akshaybabloo/jwt
JWT decoder and encoder
https://github.com/akshaybabloo/jwt
go golang jwt oauth2
Last synced: 1 day ago
JSON representation
JWT decoder and encoder
- Host: GitHub
- URL: https://github.com/akshaybabloo/jwt
- Owner: akshaybabloo
- License: mit
- Created: 2021-02-28T06:11:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-30T09:57:01.000Z (over 1 year ago)
- Last Synced: 2024-05-02T05:10:27.315Z (6 months ago)
- Topics: go, golang, jwt, oauth2
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWT
[![Go](https://github.com/akshaybabloo/jwt/actions/workflows/go.yml/badge.svg)](https://github.com/akshaybabloo/jwt/actions/workflows/go.yml)
[![GoDoc](https://godoc.org/github.com/akshaybabloo/jwt?status.svg)](https://pkg.go.dev/github.com/akshaybabloo/jwt)A simple JWT decoder.
## Usage
### Parsing URLs
```go
func ExampleParseURL() {
u := "https://jwt.ms/?state=d61b0af6-4704-4070-b854-ee5feab01bf2&access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTQ1ODY5ODIsIm5iZiI6MTYxNDU4MzM4MiwidmVyIjoiMS4wIiwiaXNzIjoiaHR0cHM6Ly9nb2xsYWhhbGxpYXV0aC5iMmNsb2dpbi5jb20vNDkyMDY1NmQtMzZlMC00YjM1LTg5NGQtMGEwYTE0YmVjOGIzL3YyLjAvIiwic3ViIjoiNzYyNWY0MDktMWZhNy00ZDc4LTkzYjAtNWMzNDAyNTVjZGYyIiwiYXVkIjoiMTIzNDU2Nzg5Iiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjE2MTQ1ODMzODIsImF1dGhfdGltZSI6MTYxNDU4MzM4Miwib2lkIjoic29tZS1vaWQiLC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EMr7qk21eSy_HlybVKQgCB9Cde_rmNWJETyw6X712QGYWaDkDrwocQ99wR6rALWVkkTOhmL6CRT5Q"
c := "123456789"
var data providers.AzureB2C
token, err := ParseURL(u, c)
if err != nil {
panic(err)
}
err = token.UnmarshalAccessToken(&data)
if err != nil {
panic(err)
}
fmt.Println(data)
// Output: {1614586982 1614583382 1.0 https://gollahalliauth.b2clogin.com/4920656d-36e0-4b35-894d-0a0a14bec8b3/v2.0/ 7625f409-1fa7-4d78-93b0-5c340255cdf2 123456789 defaultNonce 1614583382 1614583382 some-oid Akshay Gollahalli B2C_1_SignUpSignInFlow }
}
```### Parsing Tokens
```go
func ExampleParseAccessToken() {
u := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTQ1ODY5ODIsIm5iZiI6MTYxNDU4MzM4MiwidmVyIjoiMS4wIiwiaXNzIjoiaHR0cHM6Ly9nb2xsYWhhbGxpYXV0aC5iMmNsb2dpbi5jb20vNDkyMDY1NmQtMzZlMC00YjM1LTg5NGQtMGEwYTE0YmVjOGIzL3YyLjAvIiwic3ViIjoiNzYyNWY0MDktMWZhNy00ZDc4LTkzYjAtNWMzNDAyNTVjZGYyIiwiYXVkIjoiMTIzNDU2Nzg5Iiwibm9uY2UiOiJkZWZhdWx0Tm9uY2UiLCJpYXQiOjE2MTQ1ODMzODIsImF1dGhfdGltZSI6MTYxNDU4MzM4Miwib2lkIjoic29tZS1vaWQiLCJnaXZlbl9uYW1lIjoiQWtzaGF5IiwiZmFtaWx5X25hbWUiOiJHb2xsYWhhbGxpIiwidGZwIjoiQjJDXzFfU2lnblVwU2lnbkluRmxvdyJ9.CNbe3qUhpUR7U51e9k1miAdQP3ZEbCDip67MlvgTpFsFmB3nbjp7wi8e-66cPoS9z_hmQP3wLc5I8KE-b4_cFCzHZkhuQPA0Mhi9mBAZ_tAPSXNaDeiX1FEalsiH_sWuHWnojxSwlSxeKL9Tlh_0u5vXaABILdDeRWOTBJDHZ5I2BgIk8J_hI-fXDvBb0wfjI4mQe7lQqDZLVos4mlA1Uhpz2wN7Lorc31PZo02STbk5S1j1BMk4eQUS_OHTKZfAlUmfV9giWEMr7qk21eSy_HlybVKQgCB9Cde_rmNWJETyw6X712QGYWaDkDrwocQ99wR6rALWVkkTOhmL6CRT5Q"
c := "123456789"
var data providers.AzureB2C
token := ParseAccessToken(u, c)
err := token.UnmarshalAccessToken(&data)
if err != nil {
panic(err)
}
fmt.Println(data)
// Output: {1614586982 1614583382 1.0 https://gollahalliauth.b2clogin.com/4920656d-36e0-4b35-894d-0a0a14bec8b3/v2.0/ 7625f409-1fa7-4d78-93b0-5c340255cdf2 123456789 defaultNonce 1614583382 1614583382 some-oid Akshay Gollahalli B2C_1_SignUpSignInFlow }
}
```## Security
There is a minimal security validation in this module. Use it at your own risk. I suggest using [https://github.com/dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go) for secure validation of your token.