add client ID for plugin service
This commit is contained in:
22
internal/util/auth/key.go
Normal file
22
internal/util/auth/key.go
Normal file
@ -0,0 +1,22 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type idKey struct{}
|
||||
|
||||
type ID string
|
||||
|
||||
var (
|
||||
clientIDKey = &idKey{}
|
||||
)
|
||||
|
||||
func ContextWithID(ctx context.Context, id ID) context.Context {
|
||||
return context.WithValue(ctx, clientIDKey, id)
|
||||
}
|
||||
|
||||
func IDFromContext(ctx context.Context) ID {
|
||||
v, _ := ctx.Value(clientIDKey).(ID)
|
||||
return v
|
||||
}
|
@ -27,7 +27,7 @@ func PasswordCallback(au auth.Authenticator) PasswordCallbackFunc {
|
||||
return nil
|
||||
}
|
||||
return func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
|
||||
if au.Authenticate(context.Background(), conn.User(), string(password)) {
|
||||
if ok, _ := au.Authenticate(context.Background(), conn.User(), string(password)); ok {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("password rejected for %s", conn.User())
|
||||
|
Reference in New Issue
Block a user