Categorygithub.com/jonathanbrenman/goauth
modulepackage
0.0.0-20210211193222-cd353a0f06c5
Repository: https://github.com/jonathanbrenman/goauth.git
Documentation: pkg.go.dev

# README

goauth Build Status

This is a library to use jwt-token (web)

How to install?

$ go get github.com/jonathanbrenman/goauth

How to create a token?

First at all we need to instance and set the secretKey we will use to create the token and then to retrieve the encrypted data to.

    // Create an instance of goauth to use in your code.
    goAuth := NewGoAuth("my-secret-key")
    
    /* 
        Create a map with the data you want to add 
        on your new token
    */
    data := make(map[string]interface{})
    data[<key>] = <value>
    
    // Create the new token without expiration
    token, err := goAuth.CreateToken(data, 0)
    if err != nil {
        fmt.Errorf("Something is wrong", err);
    }

    // Example new token with expiration (1 hour for example)
    token, err := goAuth.CreateToken(data, 1 * time.Hour)
    if err != nil {
        fmt.Errorf("Something is wrong", err);
    }
    
    fmt.Println(token) // This print your new token

How to decrypt a token?

First at all we need to instance and set the secretKey we will use to create the token and then to retrieve the encrypted data to.

    // Use the instance with the same secret key that you have created the specify token.
    goAuth := NewGoAuth("my-secret-key")
    
    claim, err := goAuth.DecryptToken(token)
    if err != nil {
        fmt.Errorf("Something is wrong", err);
    }

    print(claim[<key>]) // This will return the same map you specify before on the token creation step.

You can implement this library on a middleware and manage there the authentification/authorization with this library.

# Functions

No description provided by the author

# Interfaces

No description provided by the author