Files
aperture/auth/mock_authenticator.go
Boris Nagaev 709463fe5b proxy: LSAT and L402 WWW-Authenticate headers
Old clients expect "L402 macaroon=..." in the first WWW-Authenticate, while
the protocol [1] says it should be "WWW-Authenticate: L402 macaroon=...",
so send both LSAT and L402. LSAT must be sent first, to maintain backward
compatibility with older clients.

[1] https://github.com/lightninglabs/L402/blob/master/protocol-specification.md
2024-04-23 09:27:49 -03:00

49 lines
1.5 KiB
Go

package auth
import "net/http"
// MockAuthenticator is a mock implementation of the authenticator.
type MockAuthenticator struct{}
// A compile-time constraint to ensure MockAuthenticator implements
// Authenticator.
var _ Authenticator = (*MockAuthenticator)(nil)
// NewMockAuthenticator returns a new MockAuthenticator instance.
func NewMockAuthenticator() *MockAuthenticator {
return &MockAuthenticator{}
}
// Accept returns whether or not the header successfully authenticates the user
// to a given backend service.
func (a MockAuthenticator) Accept(header *http.Header, _ string) bool {
if header.Get("Authorization") != "" {
return true
}
if header.Get("Grpc-Metadata-macaroon") != "" {
return true
}
if header.Get("Macaroon") != "" {
return true
}
return false
}
// FreshChallengeHeader returns a header containing a challenge for the user to
// complete.
func (a MockAuthenticator) FreshChallengeHeader(r *http.Request,
_ string, _ int64) (http.Header, error) {
header := r.Header
str := "macaroon=\"AGIAJEemVQUTEyNCR0exk7ek9" +
"0Cg==\", invoice=\"lnbc1500n1pw5kjhmpp5fu6xhthlt2vucm" +
"zkx6c7wtlh2r625r30cyjsfqhu8rsx4xpz5lwqdpa2fjkzep6yptk" +
"sct5yp5hxgrrv96hx6twvusycn3qv9jx7ur5d9hkugr5dusx6cqzp" +
"gxqr23s79ruapxc4j5uskt4htly2salw4drq979d7rcela9wz02el" +
"hypmdzmzlnxuknpgfyfm86pntt8vvkvffma5qc9n50h4mvqhngadq" +
"y3ngqjcym5a\""
header.Set("WWW-Authenticate", lsatAuthScheme+" "+str)
header.Add("WWW-Authenticate", l402AuthScheme+" "+str)
return header, nil
}