accesstoken

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Golang module for generating access token in Github token format

This Golang module creates an access token in the format of prefix``separator``code``crc32 checksum as is being done by GitHub.

The generated token can be used for purposes aside access. You can distinguish tokens using their prefixes within your own applications.

The token can be verified to be untampered if the checksum matches the code. This is meant to verify a token is valid before any checks in the database is made.

Usage


const (
    prefix = "abc"
    randomBytesLen = 32
)

token, err:= accesstoken.Generate(prefix, accesstoken.Separator, accesstoken.RandomBytesLen)
if nil != err {
    return
}

if !accesstoken.IsChecksumOK(prefix, accesstoken.Separator) {
    return
}

fmt.Println("token is ok")

Documentation

Index

Constants

View Source
const (
	// Separator - default separator used for distinguishing prefix from the actual code
	Separator = "_"

	// RandomBytesLen = default random bytes to generate for the code
	RandomBytesLen = 32
)

Variables

This section is empty.

Functions

func Generate

func Generate(prefix, separator string, randBytesLen int) (output string, err error)

Generate - generate an access token based on the given input

func IsChecksumOK

func IsChecksumOK(prefix, separator, token string) (ok bool)

IsChecksumOK - checks if a given input token has a valid checksum

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL