watoken

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 10 Imported by: 156

README

watoken

Whatsauth Token using PASETO, How to Use :

package controller

import (
 "fmt"
 "testing"

 "github.com/stretchr/testify/require"
 "github.com/whatsauth/watoken"
)

func TestWatoken(t *testing.T) {
   privateKey, publicKey := watoken.GenerateKey()
    
   //generate token for user awangga
   userid := "awangga"
   tokenstring, err := watoken.Encode(userid, privateKey)

    //decode token to get userid
   useridstring := watoken.DecodeGetId(publicKey, tokenstring)
   if useridstring == "" {
       fmt.Println("expire token")
   }

}

Tagging

git tag v0.0.6
git push origin --tags
go list -m github.com/whatsauth/[email protected]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGetId added in v0.0.7

func DecodeGetId(publicKey string, tokenstring string) string

func Encode added in v0.0.2

func Encode(id string, privateKey string) (string, error)

func EncodeWithStruct added in v0.1.3

func EncodeWithStruct[T any](id string, data *T, privateKey string) (string, error)

func EncodeWithStructDuration added in v0.1.4

func EncodeWithStructDuration[T any](id string, data *T, privateKey string, dur ...time.Duration) (string, error)

func EncodeforHours added in v0.0.6

func EncodeforHours(id string, privateKey string, hours int32) (string, error)

func EncodeforMinutes added in v0.0.6

func EncodeforMinutes(id string, privateKey string, minutes int32) (string, error)

func EncodeforSeconds added in v0.0.6

func EncodeforSeconds(id string, privateKey string, seconds int32) (string, error)

func GenerateKey added in v0.0.2

func GenerateKey() (privateKey, publicKey string)

func GetAppInfo added in v0.0.8

func GetAppInfo(wuid string) (protocol, hostname, pathname string)

func GetAppSubDomain added in v0.0.8

func GetAppSubDomain(wuid string) (subdomain string)

func GetAppUrl added in v0.0.8

func GetAppUrl(wuid string) string

func GetBcryptHash added in v0.1.2

func GetBcryptHash(text string) string

func GetMD5Hash added in v0.1.0

func GetMD5Hash(text string) string

func RandomLowerCaseString added in v0.1.1

func RandomLowerCaseString(length int) string

func RandomLowerCaseStringwithSpecialCharacter added in v0.1.1

func RandomLowerCaseStringwithSpecialCharacter(length int) string

func RandomString added in v0.0.5

func RandomString(length int) string

Types

type Payload

type Payload[T any] struct {
	Id   string    `json:"id"`
	Exp  time.Time `json:"exp"`
	Iat  time.Time `json:"iat"`
	Nbf  time.Time `json:"nbf"`
	Data T         `json:"data"`
}

func Decode added in v0.0.2

func Decode(publicKey string, tokenstring string) (payload Payload[any], err error)

func DecodeWithStruct added in v0.1.3

func DecodeWithStruct[T any](publicKey string, tokenstring string) (payload Payload[T], err error)

Jump to

Keyboard shortcuts

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