Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thilux/go-jwt


https://github.com/thilux/go-jwt

actions go golang jwt jwt-claims jwt-token

Last synced: about 5 hours ago
JSON representation

Awesome Lists containing this project

README

        

# thilux JWT

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/thilux/go-jwt/Go?logo=github&style=for-the-badge)](https://github.com/thilux/go-jwt/actions?query=workflow%3AGo)
[![codecov](https://img.shields.io/codecov/c/github/thilux/go-jwt/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/thilux/go-jwt)

This is a very simple implementation of a JWT encode/decode library in Go. I have mainly done this to play around with some Go concepts and standard library.

## Getting started

To install thilux's go-jwt:
`go get xxxxxxxxx/thilux/jwt`

A very basic usage example:

```go
package main

import (
"fmt"
"thilux.io/thilux/jwt"
)

type myUserDetails struct {

Username string `json:"username"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Claims map[string]string `json:"claims"`
}

const tokenSecret = "19db940ghf439bf340fgu3bdlkwnhfpehdp"

func main() {

claims := map[string]string{"admin": "no", "email":"[email protected]"}
userDetails := myUserDetails{Username: "myuser", FirstName: "First", LastName: "Last", Claims: claims}

token, err := jwt.Encode(userDetails, tokenSecret, "HS256")

if err != nil {
fmt.Println("Error generating token: " + err.Error())
return
}

fmt.Println("Token: " + token)
}
```

## License

This project is under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for the full text.