(c *gin.Context, basicRes context.BasicRes)
| 47 | } |
| 48 | |
| 49 | func getBasicAuthUserInfo(c *gin.Context, basicRes context.BasicRes) (*common.User, error) { |
| 50 | if c == nil { |
| 51 | return nil, errors.Default.New("request is nil") |
| 52 | } |
| 53 | authHeader := c.GetHeader("Authorization") |
| 54 | if authHeader == "" { |
| 55 | basicRes.GetLogger().Debug("Authorization is empty") |
| 56 | return nil, nil |
| 57 | } |
| 58 | basicAuth := strings.TrimPrefix(authHeader, "Basic ") |
| 59 | if basicAuth == authHeader || basicAuth == "" { |
| 60 | return nil, errors.Default.New("invalid basic auth") |
| 61 | } |
| 62 | userInfoData, err := base64.StdEncoding.DecodeString(basicAuth) |
| 63 | if err != nil { |
| 64 | return nil, errors.Default.Wrap(err, "base64 decode") |
| 65 | } |
| 66 | userInfo := strings.Split(string(userInfoData), ":") |
| 67 | if len(userInfo) != 2 { |
| 68 | return nil, errors.Default.New("invalid user info data") |
| 69 | } |
| 70 | return &common.User{ |
| 71 | Name: userInfo[0], |
| 72 | }, nil |
| 73 | } |
| 74 | |
| 75 | func OAuth2ProxyAuthentication(basicRes context.BasicRes) gin.HandlerFunc { |
| 76 | logger := basicRes.GetLogger() |
no test coverage detected