add id for auther
This commit is contained in:
parent
c258a114c4
commit
a1419ec2f4
16
auth/auth.go
16
auth/auth.go
@ -4,7 +4,7 @@ import "context"
|
|||||||
|
|
||||||
// Authenticator is an interface for user authentication.
|
// Authenticator is an interface for user authentication.
|
||||||
type Authenticator interface {
|
type Authenticator interface {
|
||||||
Authenticate(ctx context.Context, user, password string) bool
|
Authenticate(ctx context.Context, user, password string) (ok bool, id string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type authenticatorGroup struct {
|
type authenticatorGroup struct {
|
||||||
@ -17,14 +17,18 @@ func AuthenticatorGroup(authers ...Authenticator) Authenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) bool {
|
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) (bool, string) {
|
||||||
if len(p.authers) == 0 {
|
if len(p.authers) == 0 {
|
||||||
return true
|
return false, ""
|
||||||
}
|
}
|
||||||
for _, auther := range p.authers {
|
for _, auther := range p.authers {
|
||||||
if auther != nil && auther.Authenticate(ctx, user, password) {
|
if auther == nil {
|
||||||
return true
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok, id := auther.Authenticate(ctx, user, password); ok {
|
||||||
|
return ok, id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false, ""
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -2,4 +2,4 @@ module github.com/go-gost/core
|
|||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require golang.org/x/sys v0.6.0
|
require golang.org/x/sys v0.12.0
|
||||||
|
4
go.sum
4
go.sum
@ -1,2 +1,2 @@
|
|||||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
Loading…
Reference in New Issue
Block a user