2022-03-23 16:15:34 +00:00
|
|
|
|
/*
|
2023-02-08 14:35:27 +00:00
|
|
|
|
*FileName: auth.go
|
|
|
|
|
*Author: JJXu
|
|
|
|
|
*CreateTime: 2022/3/24 上午12:09
|
|
|
|
|
*Description:
|
2022-03-23 16:15:34 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package simpleRequest
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Authorization struct {
|
|
|
|
|
simpleReq *SimpleRequest
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 14:35:27 +00:00
|
|
|
|
// Basic
|
|
|
|
|
// Description: 身份验证,使用bearer 令牌bearer 令牌
|
|
|
|
|
// receiver s
|
|
|
|
|
// param username
|
|
|
|
|
// param password
|
2022-03-23 16:15:34 +00:00
|
|
|
|
func (s *Authorization) Bearer(token string) {
|
2022-03-23 16:17:32 +00:00
|
|
|
|
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Bearer %v", token))
|
2022-03-23 16:15:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 14:35:27 +00:00
|
|
|
|
// Basic
|
|
|
|
|
// Description: 身份验证的基本验证方案
|
|
|
|
|
// receiver s
|
|
|
|
|
// param username
|
|
|
|
|
// param password
|
2022-03-23 16:15:34 +00:00
|
|
|
|
func (s *Authorization) Basic(username, password string) {
|
|
|
|
|
authStr := fmt.Sprintf("%v:%v", username, password)
|
|
|
|
|
data := base64.StdEncoding.EncodeToString([]byte(authStr))
|
2022-03-23 16:17:32 +00:00
|
|
|
|
s.simpleReq.headers.Set("Authorization", fmt.Sprintf("Basic %v", data))
|
2022-03-23 16:15:34 +00:00
|
|
|
|
}
|