Documentation
¶
Overview ¶
Package device owns the optional RFC8628 device authorization protocol. It composes the actual OAuth Service and native execution owner; it owns no replacement authentication, consent, grant, token or transaction engine.
Index ¶
- Constants
- type Approval
- type Authorization
- type Config
- type Denial
- type DeviceCode
- type DeviceRequest
- type Error
- type Metadata
- type PollPolicy
- type PollResult
- type Recovery
- type Service
- func (s *Service) Approve(ctx context.Context, r Approval) (oauth.Completion, error)
- func (s *Service) Authorize(ctx context.Context, r DeviceRequest) (out Authorization, err error)
- func (s *Service) Cancel(ctx context.Context, r TokenExchange) (oauth.Completion, error)
- func (s *Service) Deny(ctx context.Context, r Denial) (oauth.Completion, error)
- func (s *Service) Enabled() bool
- func (*Service) Format(f fmt.State, v rune)
- func (s *Service) Inspect(ctx context.Context, r Verification) (out oauth.DevicePrompt, err error)
- func (s *Service) Metadata() Metadata
- func (s *Service) Poll(ctx context.Context, r TokenExchange) (PollResult, error)
- func (s *Service) PollPolicy() PollPolicy
- func (s *Service) Recover(ctx context.Context, r Recovery) (oauth.Completion, error)
- type Store
- type TokenExchange
- type UserCode
- type Verification
Examples ¶
Constants ¶
const GrantType = "urn:ietf:params:oauth:grant-type:device_code"
GrantType is RFC8628 section3.4's exact extension-grant discriminator.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Approval ¶
type Approval struct {
Verification
CSRF session.CSRFToken
Origin, ConfirmedUserCode string
}
Approval requires an explicit user action comparing the displayed canonical code. A complete verification URI never supplies this confirmation or CSRF.
func (Approval) MarshalJSON ¶
func (Approval) MarshalText ¶
type Authorization ¶
type Authorization struct {
Completion oauth.Completion
DeviceCode DeviceCode
UserCode, VerificationURI, VerificationURIComplete string
ExpiresAt time.Time
Interval time.Duration
}
Authorization contains fresh known-committed reveal-once device custody and bounded UI data. Completion alone never establishes response delivery.
func (Authorization) MarshalJSON ¶
func (Authorization) MarshalJSON() ([]byte, error)
func (Authorization) MarshalText ¶
func (Authorization) MarshalText() ([]byte, error)
type Config ¶
type Config = oauth.DevicePolicy
Config is the child's immutable policy projection shared with its native owner. Enabled=false permits dependency-free disabled construction. Enabled policy requires trusted tenant and same-issuer exact HTTPS endpoint locations, TTL1..15minutes, initial interval5..60seconds, complete-URI bound128..2048 and lookup limit1..100/hour. No request/proxy header may replace these values.
type Denial ¶
type Denial struct {
Verification
CSRF session.CSRFToken
Origin string
}
Denial requires the same genuine fresh session/origin/CSRF admission. Repeated denial is idempotent without disclosing a previous reviewing subject.
func (Denial) MarshalJSON ¶
func (Denial) MarshalText ¶
type DeviceCode ¶
DeviceCode retains the root owner's canonical32byte reveal-once secret custody. Parsing or copying one never creates durable grant authority.
type DeviceRequest ¶
type DeviceRequest struct {
ClientID, Resource, Network string
Scopes []string
ClientAuthentication oauth.ClientAuthentication
}
DeviceRequest supplies no subject/tenant/consent selectors. Nil Scopes selects the current registered OAuth-only ceiling; client credentials remain borrowed.
func ParseDeviceRequest ¶
func ParseDeviceRequest(raw string, authorization []string) (DeviceRequest, error)
ParseDeviceRequest parses bounded RFC8628 section3.1 public-none or exclusive confidential-Basic custody. Unknown parameters are ignored; duplicates and conflicting credential channels deny. Trusted Network is never form input.
func (DeviceRequest) MarshalJSON ¶
func (DeviceRequest) MarshalJSON() ([]byte, error)
func (DeviceRequest) MarshalText ¶
func (DeviceRequest) MarshalText() ([]byte, error)
type Error ¶
type Error string
Error is a stable redacted protocol condition, suitable for errors.Is and explicit OAuth transport mapping. It contains no submitted diagnostic values.
type Metadata ¶
type Metadata struct{ DeviceAuthorizationEndpoint, TokenEndpoint, GrantType string }
Metadata advertises only a completely selected optional device profile. It is not base OAuth discovery or HTTP route registration.
type PollPolicy ¶
PollPolicy describes server-owned polling policy. SlowDown is fixed by RFC8628 section3.5, not configuration; every early poll adds exactly5seconds.
type PollResult ¶
type PollResult struct {
Completion oauth.Completion
Interval time.Duration
Tokens oauth.TokenResult
}
PollResult preserves committed polling interval/durability even for pending and slow_down errors. Tokens exist only for the sole fresh atomic winner.
func (PollResult) MarshalJSON ¶
func (PollResult) MarshalJSON() ([]byte, error)
func (PollResult) MarshalText ¶
func (PollResult) MarshalText() ([]byte, error)
type Recovery ¶
type Recovery struct {
OperationID string
CommandID identity.CommandID
ClientID, DeviceCode, UserCode string
ClientAuthentication oauth.ClientAuthentication
Session auth.BearerCredential
}
Recovery carries only original-command correlation plus the appropriate current client or human custody. No user/tenant/subject override is accepted.
func (Recovery) MarshalJSON ¶
func (Recovery) MarshalText ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is immutable, concurrent-safe and borrows all owner dependencies. It owns no pool, goroutine, background recovery loop or resource to Close.
func NewService ¶
NewService freezes exact optional composition without IO or generation. Disabled construction exposes no capability or metadata and needs no owners. The selected profile supports unbound issuance and recent verified password humans only; pre-binding, OIDC claims, workload/device UI are not approximated.
Example (Disabled) ¶
package main
import (
"fmt"
device "github.com/faustbrian/go-oauth-server/device"
)
func main() {
service, err := device.NewService(nil, device.Config{}, nil)
if err != nil {
return
}
fmt.Println(service.Enabled(), service.Metadata().GrantType == "")
}
Output: false true
func (*Service) Approve ¶
Approve binds actual reviewing subject/current consent atomically only after explicit canonical-code comparison and native current session/origin/CSRF fences.
func (*Service) Authorize ¶
func (s *Service) Authorize(ctx context.Context, r DeviceRequest) (out Authorization, err error)
Authorize authenticates an explicitly permitted current registration before native issuance. Core/native retain current policy/transaction authority; the device cannot select a subject. Codes are delivered only on known commitment.
func (*Service) Cancel ¶
func (s *Service) Cancel(ctx context.Context, r TokenExchange) (oauth.Completion, error)
Cancel is an authenticated explicit client extension. It permanently withdraws this request; cancelling a Go context alone does not imply durable withdrawal.
func (*Service) Inspect ¶
func (s *Service) Inspect(ctx context.Context, r Verification) (out oauth.DevicePrompt, err error)
Inspect returns only a current safe prompt. It never approves, creates a command or emits a domain audit/lifecycle; native rate admission precedes lookup.
func (*Service) Poll ¶
func (s *Service) Poll(ctx context.Context, r TokenExchange) (PollResult, error)
Poll implements RFC8628 pending/slow_down/denied/expired and one token winner.
func (*Service) PollPolicy ¶
func (s *Service) PollPolicy() PollPolicy
PollPolicy returns the selected bounds, not a mutable current device interval.
type Store ¶
type Store = oauth.DeviceStore
Store is the actual native execution interface. Base OAuth does not require it. Applications compose the owned native factory, not private domain stores.
type TokenExchange ¶
type TokenExchange struct {
ClientID, DeviceCode, Network string
ClientAuthentication oauth.ClientAuthentication
}
TokenExchange borrows exact client and device-code custody. It permits no subject/scope/resource override. Cancel uses this same authenticated custody to permanently withdraw the device request; context cancellation is distinct.
func ParseTokenExchange ¶
func ParseTokenExchange(raw string, authorization []string) (TokenExchange, error)
ParseTokenExchange admits only the exact device grant and canonical bearer. Scope is not an allowed polling override. Parsing grants no client/device authority; the native owner independently fences both on every request.
func (TokenExchange) MarshalJSON ¶
func (TokenExchange) MarshalJSON() ([]byte, error)
func (TokenExchange) MarshalText ¶
func (TokenExchange) MarshalText() ([]byte, error)
type UserCode ¶
type UserCode string
UserCode is the fixed reference nonconfusable8-character code, displayed4-4. It is not an authenticated actor, an OAuth bearer or an approval instruction.
func ParseUserCode ¶
ParseUserCode accepts only8ASCII alphabet characters with optional middle hyphen. ASCII case folding is explicit; whitespace/Unicode/confusables deny. Missing, malformed, expired and foreign codes share the same public denial.
type Verification ¶
type Verification struct {
Session auth.BearerCredential
UserCode, Network string
}
Verification borrows a genuine recent browser session and submitted user code. Tenant is fixed at construction. Network is trusted transport attribution.
func (Verification) MarshalJSON ¶
func (Verification) MarshalJSON() ([]byte, error)
func (Verification) MarshalText ¶
func (Verification) MarshalText() ([]byte, error)