diff --git a/auth/csvauth/credential.go b/auth/csvauth/credential.go index e96281b..f42f18e 100644 --- a/auth/csvauth/credential.go +++ b/auth/csvauth/credential.go @@ -8,17 +8,14 @@ import ( "slices" "strconv" "strings" + + "github.com/therootcompany/golib/auth" ) type BasicAuthVerifier interface { Verify(string, string) error } -type Principle interface { - ID() string - Permissions() []string -} - const ( // deprecated, misspelling of PurposeDefault DefaultPurpose = "login" @@ -233,4 +230,4 @@ func (c Credential) ToRecord() []string { } var _ BasicAuthVerifier = (*Credential)(nil) -var _ Principle = (*Credential)(nil) +var _ auth.BasicPrinciple = (*Credential)(nil) diff --git a/auth/csvauth/csvauth.go b/auth/csvauth/csvauth.go index fe7ccb4..bfeedb8 100644 --- a/auth/csvauth/csvauth.go +++ b/auth/csvauth/csvauth.go @@ -23,6 +23,8 @@ import ( "sync" "golang.org/x/crypto/bcrypt" + + "github.com/therootcompany/golib/auth" ) var ErrNotFound = errors.New("not found") @@ -368,7 +370,7 @@ func (a *Auth) gcmDecrypt(aes128key [16]byte, gcmNonce [12]byte, derived []byte) // (because 'pass' is swapped with 'user' when 'pass' is empty) // - the resulting 'user' must match BasicAuthTokenNames ("", "api", and "apikey" are the defaults) // - then the token is (timing-safe) hashed to check if it exists, and then verified by its algorithm -func (a *Auth) Authenticate(name, secret string) (Principle, error) { +func (a *Auth) Authenticate(name, secret string) (auth.BasicPrinciple, error) { if name == "" && secret == "" { return nil, ErrUnauthorized } @@ -463,3 +465,5 @@ func (a *Auth) cacheID(s string, n int) string { name := base64.RawURLEncoding.EncodeToString(nameBytes) return name } + +var _ auth.BasicAuthenticator = (*Auth)(nil) diff --git a/auth/csvauth/go.mod b/auth/csvauth/go.mod index c67cc7a..8b56c5f 100644 --- a/auth/csvauth/go.mod +++ b/auth/csvauth/go.mod @@ -1,5 +1,8 @@ module github.com/therootcompany/golib/auth/csvauth -go 1.24.3 +go 1.25.0 -require golang.org/x/crypto v0.42.0 +require ( + github.com/therootcompany/golib/auth v1.0.0 + golang.org/x/crypto v0.42.0 +) diff --git a/auth/csvauth/go.sum b/auth/csvauth/go.sum index 48e0464..996fe4b 100644 --- a/auth/csvauth/go.sum +++ b/auth/csvauth/go.sum @@ -1,2 +1,4 @@ +github.com/therootcompany/golib/auth v1.0.0 h1:17hfwcJO/Efc22/8RcCTKUD49mhCc5tyoHiKonA3Slg= +github.com/therootcompany/golib/auth v1.0.0/go.mod h1:DSw8llmDkMtvMZWrzrTRtcaLPpPMsT6Sg+qwGf5O2U8= golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=