https://github.com/ttyobiwan/gouth0
Simple utils for working with Auth0 in Go
https://github.com/ttyobiwan/gouth0
auth0 go golang jwt
Last synced: 28 days ago
JSON representation
Simple utils for working with Auth0 in Go
- Host: GitHub
- URL: https://github.com/ttyobiwan/gouth0
- Owner: ttyobiwan
- License: mit
- Created: 2023-06-24T19:40:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-25T11:24:39.000Z (almost 2 years ago)
- Last Synced: 2025-02-01T17:45:03.726Z (3 months ago)
- Topics: auth0, go, golang, jwt
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gouth0
[](https://goreportcard.com/report/github.com/tobias-piotr/gouth0)
Simple utils for working with Auth0 in Go. I've made this package for my personal use, but if you find any of this useful, then I'm glad it helped.
Take note that this package is not complete, and I'm adding features as I need them. Feel free to contribute.
Also, I've made the package after around five days of learning Go, so if you find any mistakes, please let me know.
## Installation
```bash
go get github.com/tobias-piotr/gouth0
```## Usage
If you want to work with JWT tokens, first, you need to create a new instance of the `TokenService`:
```go
package mainimport (
"fmt"
"log"
"net/http""github.com/tobias-piotr/gouth0"
)func main() {
ts := gouth0.NewTokenService(gouth0.ConfigFromEnv(), &http.Client{}, 60)
}
````ConfigFromEnv()` will read the environment variables and create a new `AuthConfig` struct. You can also create the `AuthConfig` struct manually:
```go
package mainimport (
"fmt"
"log"
"net/http""github.com/tobias-piotr/gouth0"
)func main() {
ts := gouth0.NewTokenService(&gouth0.AuthConfig{
Domain: "your-domain.auth0.com",
Audience: "https://your-audience.com/",
Algorithms: []string{"RS256"},
}, &http.Client{}, 60)
}
```With that in place, you can simply start decoding JWT tokens with the `DecodeToken` method:
```go
package mainimport (
"fmt"
"log"
"net/http""github.com/tobias-piotr/gouth0"
)func main() {
ts := gouth0.NewTokenService(gouth0.ConfigFromEnv(), &http.Client{}, 60)
decoded, err := ts.DecodeToken("your-jwt-token")
}
````decoded` will contain a map of the decoded token payload, and err can be any error encountered during the decoding process.