apikey

package
v0.0.0-...-1277d2a Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

API Key

Usage

通过 Payload 生成 API-Token

var apiKey = &apikey.APIKey{
  Name:      "test",
  AccessKey: "987f9b5d5e4a46799281d5487372425c",
  SecretKey: "1b9c39e77eb1480cb887-ecbcbf557b13",
}
token, err := apiKey.GenerateAPIToken(apikey.APITokenPayload{
  UID:     "001",
  Host:    "www.example.com",
  Expired: 1741918889,
})

解析 API-Token 获取 Payload

payload, err := apiKey.DecryptAPIToken(token)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key string, cryptoText string) (result []byte, err error)

func Encrypt

func Encrypt(key string, value []byte) (result string, err error)

Types

type APIKey

type APIKey struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	UserID     string     `json:"userId"`
	SecretKey  string     `json:"secretKey"`
	AccessKey  string     `json:"accessKey"`
	Expiration *time.Time `json:"expiration,omitempty"`
}

func (*APIKey) DecryptAPIToken

func (apiKey *APIKey) DecryptAPIToken(token string) (payload *APITokenPayload, err error)

通过 Payload 生成 Token

func (*APIKey) GenerateAPIToken

func (apiKey *APIKey) GenerateAPIToken(payload APITokenPayload) (token string, err error)

解密 Token 并返回 Payload

type APITokenPayload

type APITokenPayload struct {
	UID     string `json:"uid"`
	Host    string `json:"host"`
	Expired uint64 `json:"expired"`
}

Jump to

Keyboard shortcuts

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