mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 00:54:20 +01:00
auth: LsatAuthenticator -> L402Authenticator sed -i 's/LsatAuthenticator/L402Authenticator/g' aperture.go auth/authenticator.go auth/authenticator_test.go rename package lsat to l402 git mv lsat/ l402 sed 's@aperture/lsat@aperture/l402@g' -i `git grep -l aperture/lsat` sed -i 's@package lsat@package l402@' `git grep -l 'package lsat'` sed -i 's@lsat\.@l402.@g' -i `git grep -l 'lsat\.'` sed 's@l402.Id@lsat.Id@' -i mint/mint_test.go replace lsat with l402 in the code sed 's@lsat@l402@' -i mint/mint_test.go sed 's@Lsat@L402@' -i l402/client_interceptor.go sed 's@lsatstore@l402store@' -i l402/store_test.go replace LSAT to L402 in comments sed '/\/\//s@LSAT@L402@g' -i `git grep -l '//.*LSAT'` replace LSAT -> L402 in the code, skip when a string starts with it sed 's@\([^"/]\)LSAT@\1L402@g' -i `git grep -l LSAT`
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package l402
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
|
|
"gopkg.in/macaroon.v2"
|
|
)
|
|
|
|
// MacaroonCredential wraps a macaroon to implement the
|
|
// credentials.PerRPCCredentials interface.
|
|
type MacaroonCredential struct {
|
|
*macaroon.Macaroon
|
|
|
|
// AllowInsecure specifies if the macaroon is allowed to be sent over
|
|
// insecure transport channels. This should only ever be set to true if
|
|
// the insecure connection is proxied through tor and the destination
|
|
// address is an onion service.
|
|
AllowInsecure bool
|
|
}
|
|
|
|
// RequireTransportSecurity implements the PerRPCCredentials interface.
|
|
func (m MacaroonCredential) RequireTransportSecurity() bool {
|
|
return !m.AllowInsecure
|
|
}
|
|
|
|
// GetRequestMetadata implements the PerRPCCredentials interface. This method
|
|
// is required in order to pass the wrapped macaroon into the gRPC context.
|
|
// With this, the macaroon will be available within the request handling scope
|
|
// of the ultimate gRPC server implementation.
|
|
func (m MacaroonCredential) GetRequestMetadata(_ context.Context,
|
|
_ ...string) (map[string]string, error) {
|
|
|
|
macBytes, err := m.MarshalBinary()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
md := make(map[string]string)
|
|
md["macaroon"] = hex.EncodeToString(macBytes)
|
|
return md, nil
|
|
}
|
|
|
|
// NewMacaroonCredential returns a copy of the passed macaroon wrapped in a
|
|
// MacaroonCredential struct which implements PerRPCCredentials.
|
|
func NewMacaroonCredential(m *macaroon.Macaroon,
|
|
allowInsecure bool) MacaroonCredential {
|
|
|
|
ms := MacaroonCredential{AllowInsecure: allowInsecure}
|
|
ms.Macaroon = m.Clone()
|
|
return ms
|
|
}
|