security

package
v0.0.0-...-843cdbd Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Security            = "security"
	Turn                = "turn"
	Auth                = "auth"
	RefreshTokenPub     = "refresh_token_pub"
	RefreshTokenPubSign = "refresh_token_pub_sign"
	HeaderPrefix        = "Twinkle-" //Uniform prefix

	HeaderSecretPub   = HeaderPrefix + "Secret-Pub" //Secret Pub
	HeaderTokenPub    = HeaderPrefix + "Token-Pub"  //Token Public
	HeaderNonce       = HeaderPrefix + "Nonce"      //Nonce
	HeaderTimestamp   = HeaderPrefix + "Timestamp"  //Timestamp
	HeaderSignature   = HeaderPrefix + "Signature"  //Signature
	HeaderTokenExpire = HeaderPrefix + "Expiration" //Token Expiration

	BodyInside       = "__b_o_d_y__"
	TurnBySecretURL  = "/security/access/secret"
	TurnByRefreshURL = "/security/access/refresh"
)

Variables

This section is empty.

Functions

func GenSignature

func GenSignature(req *http.Request, bodyData []byte, priKey string) (string, *errors.Error)

GenSignature Sign the request data

func SecretSignature

func SecretSignature(req *http.Request, bodyData []byte, secretPub string, secretPri string) *errors.Error

SecretSignature Use signatures when exchanging protocols

func Sign

func Sign(data string, token string) (string, *errors.Error)

Sign data is signed using a token

func TokenSignature

func TokenSignature(req *http.Request, bodyData []byte, tokenPub string, tokenPri string) *errors.Error

TokenSignature Sign in accordance with the agreement

Types

type Passport

type Passport struct {
	Code        string    `bson:"code" json:"code"`
	ID          string    `bson:"id" json:"id"`
	Certificate more.More `bson:"certificate" json:"certificate"`
}

type Service

type Service interface {
	// Turn Obtain a new token pair through refresh token
	// secretPub: The public key used in network transmission
	// sign: Parameters that are signed using secretKey
	Turn(secretPub string, nonce string, timestamp time.Time, sign string) (*Token, *errors.Error)

	// Auth Verifies the user and returns the TOKEN
	Auth(passport Passport) (*Token, *errors.Error)
}

type Token

type Token struct {
	TokenPub    string    `bson:"token_pub" json:"token_pub"`
	TokenExpire time.Time `bson:"token_expire" json:"token_expire"`
	Token       string    `bson:"token" json:"token"`
}

func (Token) Clone

func (token Token) Clone(newToken Token)

func (Token) IsExpired

func (token Token) IsExpired() bool

Jump to

Keyboard shortcuts

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