@@ -16,11 +16,6 @@ import (
16
16
"gopkg.in/yaml.v2"
17
17
)
18
18
19
- var (
20
- // ErrUnauthorized indicates that a client doesn't have access to a resource
21
- ErrUnauthorized = status .Errorf (codes .PermissionDenied , "unauthorised" )
22
- )
23
-
24
19
// Config allows retrieve of access scope for the current client
25
20
type Config interface {
26
21
GetClientScope (ctx context.Context ) (* Scope , error )
@@ -103,29 +98,29 @@ func (s *config) GetClientScope(ctx context.Context) (*Scope, error) {
103
98
104
99
basicAuth , err := grpc_auth .AuthFromMD (ctx , "Bearer" )
105
100
if err != nil {
106
- return nil , ErrUnauthorized
101
+ return nil , status . Errorf ( codes . PermissionDenied , "failed getting Bearrer auth, %v" , err )
107
102
}
108
103
109
104
payload , err := base64 .StdEncoding .DecodeString (basicAuth )
110
105
if err != nil {
111
- return nil , ErrUnauthorized
106
+ return nil , status . Errorf ( codes . PermissionDenied , "failed getting payload: %v" , err )
112
107
}
113
108
114
109
pair := strings .SplitN (string (payload ), ":" , 2 )
115
110
116
111
if len (pair ) != 2 {
117
- return nil , ErrUnauthorized
112
+ return nil , status . Errorf ( codes . PermissionDenied , "malformed payload: should contain 2 pairs, but got %d" , len ( pair ))
118
113
}
119
114
120
115
id , secret := pair [0 ], pair [1 ]
121
116
122
117
hashPass , ok := s .auth [id ]
123
118
if ! ok {
124
- return nil , ErrUnauthorized
119
+ return nil , status . Errorf ( codes . PermissionDenied , "no password configured for id %v" , id )
125
120
}
126
121
127
122
if err := bcrypt .CompareHashAndPassword (hashPass , []byte (secret )); err != nil {
128
- return nil , ErrUnauthorized
123
+ return nil , status . Errorf ( codes . PermissionDenied , "passwords do not match for id %v" , id )
129
124
}
130
125
131
126
return s .scopes [id ], nil
0 commit comments