Documentation
¶
Index ¶
- Constants
- Variables
- func AsFloat(value any) (float64, bool)
- func AsList(value any) ([]any, bool)
- func AsMap(value any) (map[string]any, bool)
- func AsString(value any) (string, bool)
- func B64Std(data []byte) string
- func B64URL(data []byte) string
- func B64URLDecode(value string) ([]byte, error)
- func ContentDigest(body string) string
- func DecodeJSON(text string) (any, error)
- func DetachedJWS(key *ClientKey, method, rawURL string, body *string, token string) (string, error)
- func Dump(value any) (string, error)
- func Fingerprint256(cert *x509.Certificate) string
- func HashEqual(a, b string) bool
- func Href(raw string) (string, error)
- func InteractionHash(clientNonce, serverNonce, interactRef, grantEndpoint string) string
- func IsLoopback(raw string) bool
- func IsNumber(value any) bool
- func Origin(raw string) (string, error)
- func PublicKeyFromJWK(jwk map[string]any) (crypto.PublicKey, error)
- func PublicKeyObject(key *ClientKey) (map[string]any, error)
- func ReadTrust(raw, base string) string
- func SHA256(data []byte) []byte
- func SignRaw(key *ClientKey, data []byte) ([]byte, error)
- func SignRequest(key *ClientKey, method, rawURL string, headers map[string]string, body *string) (map[string]string, error)
- func SubjectOf(subID any, issuer string) map[string]string
- func TimingEqual(a, b string) bool
- func UIDFromAccount(uri string) *string
- func VerifyRaw(public crypto.PublicKey, alg string, data, signature []byte) bool
- func WellKnown(issuer, suffix string) ([]string, error)
- type Answer
- type Client
- func (c *Client) AuthorizationHeaders(grant *Grant, method, rawURL string, body *string) (map[string]string, error)
- func (c *Client) Call(grant *Grant, rawURL, method string, headers map[string]string, body *string) (*Answer, error)
- func (c *Client) EnsureFresh(grant *Grant) (*Grant, error)
- func (c *Client) FinishPush(body any) (*Finished, error)
- func (c *Client) FinishRedirect(query any, allowedIDs []string) (*Finished, error)
- func (c *Client) RequestGrant() (*GrantResult, error)
- func (c *Client) RequestGrantAccess(access []any, expectedSub string, user any) (*GrantResult, error)
- func (c *Client) Revoke(grant *Grant) error
- func (c *Client) Rotate(grant *Grant) (*Grant, error)
- func (c *Client) TLS() (TLSOpt, error)
- type ClientKey
- type Config
- type Continuation
- type Display
- type Error
- type Finished
- type Grant
- type GrantResult
- type GrantServer
- type IDCheck
- type JWS
- type KeyPair
- type Logger
- type OpenID
- type Pending
- type Person
- type ReceiverOpt
- type SSFConfig
- type SSFRequest
- type SignalEvent
- type SignalsReceiver
- func (r *SignalsReceiver) On(eventType string, handler func(*SignalEvent)) *SignalsReceiver
- func (r *SignalsReceiver) PollOnce() (bool, error)
- func (r *SignalsReceiver) Start() error
- func (r *SignalsReceiver) Stop()
- func (r *SignalsReceiver) Track(session TrackedSession)
- func (r *SignalsReceiver) Untrack(localID string)
- func (r *SignalsReceiver) Verify(state string) error
- type TLSOpt
- type TrackedSession
Constants ¶
const ( CAEP = "https://schemas.openid.net/secevent/caep/event-type/" RISC = "https://schemas.openid.net/secevent/risc/event-type/" SSF = "https://schemas.openid.net/secevent/ssf/event-type/" )
CAEP, RISC, and SSF event type prefixes.
const ( EventSessionRevoked = CAEP + "session-revoked" EventTokenClaimsChange = CAEP + "token-claims-change" EventCredentialChange = CAEP + "credential-change" EventAssuranceLevelChange = CAEP + "assurance-level-change" EventDeviceComplianceChange = CAEP + "device-compliance-change" EventSessionEstablished = CAEP + "session-established" EventSessionPresented = CAEP + "session-presented" EventRiskLevelChange = CAEP + "risk-level-change" EventAccountCredentialChangeRequired = RISC + "account-credential-change-required" EventAccountPurged = RISC + "account-purged" EventAccountDisabled = RISC + "account-disabled" EventAccountEnabled = RISC + "account-enabled" EventIdentifierChanged = RISC + "identifier-changed" EventIdentifierRecycled = RISC + "identifier-recycled" EventCredentialCompromise = RISC + "credential-compromise" EventOptIn = RISC + "opt-in" EventOptOutInitiated = RISC + "opt-out-initiated" EventOptOutCancelled = RISC + "opt-out-cancelled" EventOptOutEffective = RISC + "opt-out-effective" EventRecoveryActivated = RISC + "recovery-activated" EventRecoveryInformationChanged = RISC + "recovery-information-changed" EventSessionsRevoked = RISC + "sessions-revoked" EventVerification = SSF + "verification" EventStreamUpdated = SSF + "stream-updated" )
Shared Signals event types this receiver understands.
Variables ¶
var DefaultEndingEvents = []string{ EventSessionRevoked, EventAccountDisabled, EventAccountPurged, EventCredentialCompromise, EventSessionsRevoked, }
DefaultEndingEvents end local sessions that match the subject.
var DefaultEventsRequested = []string{ EventSessionRevoked, EventCredentialChange, EventAssuranceLevelChange, EventTokenClaimsChange, EventAccountDisabled, EventAccountEnabled, EventAccountPurged, EventCredentialCompromise, EventSessionsRevoked, EventAccountCredentialChangeRequired, }
DefaultEventsRequested is the set a new stream asks for.
Functions ¶
func B64URLDecode ¶
func ContentDigest ¶
func DecodeJSON ¶
func DetachedJWS ¶
func Fingerprint256 ¶
func Fingerprint256(cert *x509.Certificate) string
func InteractionHash ¶
InteractionHash is base64url(SHA-256(clientNonce, serverNonce, interact_ref, grant endpoint)) separated by newlines.
func IsLoopback ¶
func SignRequest ¶
func TimingEqual ¶
func UIDFromAccount ¶
UIDFromAccount returns the user part of an acct: URI. Invalid percent-encoding is kept as written.
Types ¶
type Client ¶
type Client struct {
Config *Config
// contains filtered or unexported fields
}
Client is a server-side GNAP client. The private key stays in this process.
func (*Client) AuthorizationHeaders ¶
func (c *Client) AuthorizationHeaders(grant *Grant, method, rawURL string, body *string) (map[string]string, error)
AuthorizationHeaders are the key proof for one request that carries this grant's access token.
func (*Client) Call ¶
func (c *Client) Call(grant *Grant, rawURL, method string, headers map[string]string, body *string) (*Answer, error)
Call sends a key-bound request.
func (*Client) EnsureFresh ¶
EnsureFresh rotates when the access token expires within 60 seconds. now is milliseconds.
func (*Client) FinishPush ¶
FinishPush completes a back-channel interaction finish.
func (*Client) FinishRedirect ¶
FinishRedirect completes a redirect interaction. allowedIDs are the pending ids this browser was given.
func (*Client) RequestGrant ¶
func (c *Client) RequestGrant() (*GrantResult, error)
RequestGrant asks for the configured access and returns the redirect the browser should open.
func (*Client) RequestGrantAccess ¶
func (c *Client) RequestGrantAccess(access []any, expectedSub string, user any) (*GrantResult, error)
RequestGrantAccess asks for access, or the configured rights when access is nil. expectedSub is optional.
type ClientKey ¶
type ClientKey struct {
Proof string
Private any
Thumb string
Alg string
Kid string
JWK map[string]string
CertPEM string
ChainPEM string
}
ClientKey is the one key this process proves. The private half is not sent.
func LoadClientKey ¶
func (*ClientKey) PrivatePEM ¶
type Config ¶
type Config struct {
GrantEndpoint string
IDTokenIssuer string
Application string
ClassID string
Display *Display
Access []any
Signals *bool
SubIDFormats []string
AssertionFormats []string
Key *ClientKey
FinishURI string
FinishMethod string
InteractionStart []string
HashMethod string
RequireBoundTokens bool
UseInstanceID bool
TLSCA string
AllowInsecure bool
ClockToleranceSec float64
MaxWaitSec float64
TransactionTTLSec float64
SSF *SSFConfig
}
Config is a resolved gnap.json. Signals is nil when CAEP and RISC stay on, and false when they are off.
func ReadConfigFile ¶
ReadConfigFile loads gnap.json from path.
type Continuation ¶
Continuation is a GNAP continue or manage handle. The token is key-bound.
type Grant ¶
type Grant struct {
AccessToken string
Bearer bool
Access any
ExpiresIn *float64
ExpiresAt *float64
Manage *Continuation
Continuation *Continuation
InstanceID string
Subject *Person
GrantID string
}
Grant is an access token and the subject it was issued for.
type GrantResult ¶
GrantResult is either a redirect the browser must follow or a grant that needed no interaction.
type GrantServer ¶
type GrantServer struct {
GrantRequestEndpoint string
InteractionStart []string
InteractionFinish []string
KeyProofs []string
SubIDFormats []string
AssertionFormats []string
}
GrantServer is the metadata from OPTIONS on the grant endpoint.
func DiscoverGrantServer ¶
func DiscoverGrantServer(grantEndpoint string, tlsOpt TLSOpt) (*GrantServer, error)
func ValidateGrantServer ¶
func ValidateGrantServer(raw any, grantEndpoint string) (*GrantServer, error)
type IDCheck ¶
type IDCheck struct {
Issuer string
Audiences []string
Skew float64
Keys func() ([]map[string]any, error)
}
IDCheck is how an id_token is judged.
type KeyPair ¶
type KeyPair struct {
PrivateKeyPEM string
CertificatePEM string
Fingerprint string
Certificate *x509.Certificate
Private *ecdsa.PrivateKey
}
KeyPair is a self-signed P-256 key and certificate kept in this process.
type Pending ¶
type Pending struct {
ID string
ClientNonce string
ServerNonce string
HashMethod string
Continuation *Continuation
ContinueNotBefore float64
GrantEndpoint string
CreatedAt float64
Context any
InstanceID string
ExpectedSub string
}
Pending is a grant whose browser interaction has not finished.
type Person ¶
type Person struct {
Sub string
Claims map[string]any
AssertionVerified bool
Iss string
Uid *string
Email string
Name string
PreferredUsername string
Sid string
Acr string
Amr []string
}
Person is the subject of a grant. Uid is nil when the grant has no account identifier.
type ReceiverOpt ¶
type ReceiverOpt struct {
TLS TLSOpt
Headers func(SSFRequest) map[string]string
EventsRequested []string
EndOn []string
Description string
PollIntervalMs int
MaxEvents int
Log Logger
}
ReceiverOpt tunes one poll receiver.
type SSFConfig ¶
SSFConfig is the transmitter the receiver polls. It is absent when signals are off.
type SSFRequest ¶
SSFRequest is one transmitter call. Body is set when the call has one.
type SignalEvent ¶
type SignalEvent struct {
Type string
Payload any
Subject map[string]string
JTI string
Sessions []string
Ended bool
IAT *float64
Txn string
}
SignalEvent is one event from a Security Event Token.
type SignalsReceiver ¶
SignalsReceiver polls one Shared Signals stream. Stop waits until the poll Start already had in flight has finished.
func NewSignalsReceiver ¶
func NewSignalsReceiver(transmitter string, onEnd func([]string, *SignalEvent), opt ReceiverOpt) (*SignalsReceiver, error)
NewSignalsReceiver builds a receiver. onEndSessions is required. The transmitter is an http(s) URL.
func (*SignalsReceiver) On ¶
func (r *SignalsReceiver) On(eventType string, handler func(*SignalEvent)) *SignalsReceiver
On registers a handler for one event type, or "*" for every event.
func (*SignalsReceiver) PollOnce ¶
func (r *SignalsReceiver) PollOnce() (bool, error)
PollOnce fetches one batch. A caller that arrives while a poll is running waits for that poll.
func (*SignalsReceiver) Start ¶
func (r *SignalsReceiver) Start() error
Start discovers the transmitter, opens one poll stream, and polls in the background.
func (*SignalsReceiver) Stop ¶
func (r *SignalsReceiver) Stop()
Stop waits until the background poll has finished, so the next poll is a new one.
func (*SignalsReceiver) Track ¶
func (r *SignalsReceiver) Track(session TrackedSession)
Track remembers a local session.
func (*SignalsReceiver) Untrack ¶
func (r *SignalsReceiver) Untrack(localID string)
Untrack forgets a local session.
func (*SignalsReceiver) Verify ¶
func (r *SignalsReceiver) Verify(state string) error
Verify asks the transmitter to send a verification event.
type TLSOpt ¶
TLSOpt is the back-channel trust material. CA pins the authorization server. Cert and Key are the mutual TLS client.
type TrackedSession ¶
type TrackedSession struct {
LocalID string
Person string
Email string
IDPSession string
ExpiresAt *float64
}
TrackedSession is one local session that a signal can end.
func TrackedFromPerson ¶
func TrackedFromPerson(localID string, person *Person, expiresAt *float64) TrackedSession
TrackedFromPerson copies the identifiers a grant subject can be found by.