mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
use jwt instead of basicAuth for webEnv (#10246)
This commit is contained in:
parent
6914b2c99d
commit
900eebb9a4
16
pkg/env/web_env.go
vendored
16
pkg/env/web_env.go
vendored
@ -30,6 +30,8 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -96,10 +98,20 @@ func fetchEnvHTTP(envKey string, u *url.URL) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if username != "" && password != "" {
|
||||
req.SetBasicAuth(username, password)
|
||||
claims := &jwt.StandardClaims{
|
||||
ExpiresAt: int64(15 * time.Minute),
|
||||
Issuer: username,
|
||||
Subject: envKey,
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS512, claims)
|
||||
ss, err := token.SignedString([]byte(password))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "Bearer "+ss)
|
||||
|
||||
clnt := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
|
Loading…
Reference in New Issue
Block a user