2019-06-27 17:04:25 +08:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/component/auth"
|
2019-06-27 17:04:25 +08:00
|
|
|
)
|
|
|
|
|
2024-09-27 18:10:05 +08:00
|
|
|
type authStore struct {
|
|
|
|
authenticator auth.Authenticator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *authStore) Authenticator() auth.Authenticator {
|
|
|
|
return a.authenticator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *authStore) SetAuthenticator(authenticator auth.Authenticator) {
|
|
|
|
a.authenticator = authenticator
|
|
|
|
}
|
2019-06-27 17:04:25 +08:00
|
|
|
|
2024-09-27 18:10:05 +08:00
|
|
|
func NewAuthStore(authenticator auth.Authenticator) auth.AuthStore {
|
|
|
|
return &authStore{authenticator}
|
2019-06-27 17:04:25 +08:00
|
|
|
}
|
|
|
|
|
2024-09-27 18:10:05 +08:00
|
|
|
var Default auth.AuthStore = NewAuthStore(nil)
|
|
|
|
|
|
|
|
type nilAuthStore struct{}
|
|
|
|
|
|
|
|
func (a *nilAuthStore) Authenticator() auth.Authenticator {
|
|
|
|
return nil
|
2019-06-27 17:04:25 +08:00
|
|
|
}
|
2024-08-25 19:26:06 +08:00
|
|
|
|
2024-09-27 18:10:05 +08:00
|
|
|
func (a *nilAuthStore) SetAuthenticator(authenticator auth.Authenticator) {}
|
|
|
|
|
|
|
|
var Nil auth.AuthStore = (*nilAuthStore)(nil) // always return nil, even call SetAuthenticator() with a non-nil authenticator
|