mirror of
https://github.com/lightninglabs/aperture.git
synced 2026-01-02 17:04:25 +01:00
The target service name remains unused in its current form, but will be required in order to verify that an incoming request with an LSAT attached is authorized to access the service being attempted. We can derive this from the request's host field, but we choose to extend the methods with the additional parameter in order to prevent parsing the host field again to determine which service is being accessed.
41 lines
1.3 KiB
Go
41 lines
1.3 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) (http.Header, error) {
|
|
|
|
header := r.Header
|
|
header.Set("WWW-Authenticate", "LSAT macaroon='AGIAJEemVQUTEyNCR0exk7ek90Cg==' invoice='lnbc1500n1pw5kjhmpp5fu6xhthlt2vucmzkx6c7wtlh2r625r30cyjsfqhu8rsx4xpz5lwqdpa2fjkzep6yptksct5yp5hxgrrv96hx6twvusycn3qv9jx7ur5d9hkugr5dusx6cqzpgxqr23s79ruapxc4j5uskt4htly2salw4drq979d7rcela9wz02elhypmdzmzlnxuknpgfyfm86pntt8vvkvffma5qc9n50h4mvqhngadqy3ngqjcym5a'")
|
|
return header, nil
|
|
}
|