auth

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IAMKeyLen    = 33
	IAMKeyPrefix = "IAM-"

	AuthorizationPrefixQiniu = "Qiniu "
	AuthorizationPrefixQBox  = "QBox "
)

Variables

This section is empty.

Functions

func CredentialsFromContext

func CredentialsFromContext(ctx context.Context) (cred *Credentials, t TokenType, ok bool)

CredentialsFromContext 从context获取密钥信息

func WithCredentials

func WithCredentials(ctx context.Context, cred *Credentials) context.Context

WithCredentials 返回一个包含密钥信息的context

func WithCredentialsType

func WithCredentialsType(ctx context.Context, cred *Credentials, t TokenType) context.Context

WithCredentialsType 返回一个context, 保存了密钥信息和token类型

Types

type Credentials

type Credentials struct {
	AccessKey string
	SecretKey []byte
}

AK/SK可以从 https://portal.qiniu.com/user/key 获取

func New

func New(accessKey, secretKey string) *Credentials

构建一个Credentials对象

func (*Credentials) AddToken

func (ath *Credentials) AddToken(t TokenType, req *http.Request) error

SignToken 根据t的类型对请求进行签名,并把token加入req中

func (*Credentials) Sign

func (ath *Credentials) Sign(data []byte) (token string)

Sign 对数据进行签名,一般用于私有空间下载用途

func (*Credentials) SignRequest

func (ath *Credentials) SignRequest(req *http.Request) (token string, err error)

SignRequest 对数据进行签名,一般用于管理凭证的生成

func (*Credentials) SignRequestV2

func (ath *Credentials) SignRequestV2(req *http.Request) (token string, err error)

SignRequestV2 对数据进行签名,一般用于高级管理凭证的生成

func (*Credentials) SignWithData

func (ath *Credentials) SignWithData(b []byte) (token string)

SignWithData 对数据进行签名,一般用于上传凭证的生成用途

type TokenType

type TokenType int

七牛签名算法的类型: QBoxToken, QiniuToken, BearToken, QiniuMacToken

const (
	TokenQiniu TokenType = iota
	TokenQBox
)

Jump to

Keyboard shortcuts

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