Documentation
¶
Index ¶
- Constants
- func ClearCIMDCache()
- func ClientHostAllowed(policy model.OAuthPolicy, clientID string, redirectURI string) (allowed bool, warn bool)
- func GenerateAccessToken() (plain string, hash string, err error)
- func GenerateAuthCode() (string, error)
- func GenerateRefreshToken() (plain string, hash string, err error)
- func HashToken(plain string) string
- func InternalCredentialToken(grantID uint) string
- func IsAccessTokenFormat(s string) bool
- func IsCustomSchemeRedirect(redir string) bool
- func IsLoopbackRedirect(redir string) bool
- func Issuer(cfg *config.Config, st *store.Store, r *http.Request) string
- func NormalizeAndValidatePolicy(p model.OAuthPolicy) (model.OAuthPolicy, error)
- func NormalizeClientHostAllowlist(in []string) ([]string, error)
- func ParseScopeString(scope string) []string
- func ProtocolEnabled(cfg *config.Config, st *store.Store) bool
- func PublicBase(cfg *config.Config, st *store.Store, r *http.Request) (string, bool)
- func RedirectDisplayScheme(redir string) string
- func RedirectHost(redir string) string
- func RedirectURIInList(uris []string, requested string) bool
- func RedirectURIMatches(registered, requested string) bool
- func ResetCIMDNetHooksForTest()
- func ResolvePublicBase(cfg *config.Config, st *store.Store, r *http.Request) (base string, derived bool)
- func ResourceMetadataURL(cfg *config.Config, st *store.Store, r *http.Request) string
- func ResourceURL(cfg *config.Config, st *store.Store, r *http.Request) string
- func ScopesToPermissions(scopes []string) (model.Permissions, bool)
- func SetCIMDCacheClock(fn func() time.Time)
- func SetCIMDHTTPDoer(d HTTPDoer)
- func SetCIMDLookupHost(fn func(ctx context.Context, host string) error)
- func SetCIMDNetHooksForTest(lookup func(context.Context, string) ([]netip.Addr, error), ...)
- func SetServiceClock(fn func() time.Time)
- func TokenEqualHash(plain, hash string) bool
- func ValidateCodeChallenge(challenge string) bool
- func ValidateCodeVerifier(verifier string) bool
- func ValidateRedirectHostSyntax(host string) bool
- func ValidateRedirectURI(raw string) error
- func ValidateRedirectURIList(uris []string) error
- func VerifyPKCE(challenge, method, verifier string) bool
- func WWWAuthenticateValue(cfg *config.Config, st *store.Store, r *http.Request) string
- type ApproveDecision
- type AuditFn
- type CIMDDocument
- type HTTPDoer
- type PendingRequestView
- type RevokeFn
- type Service
- func (s *Service) Config() *config.Config
- func (s *Service) Decide(ctx context.Context, reqID string, d ApproveDecision) (redirectURL string, err error)
- func (s *Service) Enabled() bool
- func (s *Service) GetPending(id string) (*PendingRequestView, bool)
- func (s *Service) Mount(engine *gin.Engine)
- func (s *Service) ResolveCredential(ctx context.Context, plain string) (*model.MCPCredential, error)
- func (s *Service) RevokeGrant(ctx context.Context, grantID uint) error
- func (s *Service) SavePolicy(ctx context.Context, p model.OAuthPolicy) error
- func (s *Service) Store() *store.Store
- func (s *Service) WWWAuthenticate(r *http.Request) string
Constants ¶
const (
AccessTokenPrefix = "rmo_"
)
const OAuthClientHostAllowlistMax = 32
Variables ¶
This section is empty.
Functions ¶
func ClientHostAllowed ¶
func GenerateAccessToken ¶
func GenerateAuthCode ¶
func GenerateRefreshToken ¶
func InternalCredentialToken ¶
func IsAccessTokenFormat ¶
func IsCustomSchemeRedirect ¶
IsCustomSchemeRedirect 是否为 RFC 8252 私有方案(非 http(s))。
func IsLoopbackRedirect ¶
func NormalizeAndValidatePolicy ¶
func NormalizeAndValidatePolicy(p model.OAuthPolicy) (model.OAuthPolicy, error)
NormalizeAndValidatePolicy 规范化 client_host_allowlist 并校验策略字段。
func NormalizeClientHostAllowlist ¶
NormalizeClientHostAllowlist 只保留合法主机名:不含协议、端口、路径、通配符;小写、去重。
func ParseScopeString ¶
func ProtocolEnabled ¶
ProtocolEnabled 环境硬开关关闭或策略总开关关闭时,OAuth 协议端点与 MCP 元数据均不启用。
func PublicBase ¶
PublicBase 返回对外可见的根 URL(无尾斜杠)与是否来自请求推导。
func RedirectDisplayScheme ¶
RedirectDisplayScheme 供授权页展示。
func RedirectURIInList ¶
func RedirectURIMatches ¶
RedirectURIMatches 精确匹配 redirect_uri;回环地址按 RFC 8252 忽略端口。
func ResetCIMDNetHooksForTest ¶
func ResetCIMDNetHooksForTest()
ResetCIMDNetHooksForTest 恢复默认 CIMD 网络行为。
func ResolvePublicBase ¶
func ResolvePublicBase(cfg *config.Config, st *store.Store, r *http.Request) (base string, derived bool)
ResolvePublicBase 返回 issuer 根 URL 与是否来自请求推导(推导时需 no-store / Vary)。
func ResourceMetadataURL ¶
func ScopesToPermissions ¶
func ScopesToPermissions(scopes []string) (model.Permissions, bool)
func SetCIMDHTTPDoer ¶
func SetCIMDHTTPDoer(d HTTPDoer)
func SetCIMDLookupHost ¶
SetCIMDLookupHost 供测试注入 DNS 解析(返回 nil 表示通过)。
func SetCIMDNetHooksForTest ¶
func SetCIMDNetHooksForTest(lookup func(context.Context, string) ([]netip.Addr, error), dial func(context.Context, string, string) (net.Conn, error))
SetCIMDNetHooksForTest 注入 CIMD 网络钩子(仅测试)。
func SetServiceClock ¶
func TokenEqualHash ¶
func ValidateCodeChallenge ¶
ValidateCodeChallenge S256 challenge 必须为 43 字符 base64url。
func ValidateCodeVerifier ¶
ValidateCodeVerifier RFC 7636 code_verifier。
func ValidateRedirectHostSyntax ¶
ValidateRedirectHostSyntax 校验从请求推导出的 Host 是否合法。
func ValidateRedirectURI ¶
ValidateRedirectURI 校验 OAuth redirect_uri(DCR / CIMD / authorize 共用)。
func ValidateRedirectURIList ¶
ValidateRedirectURIList 校验列表长度与每一项。
Types ¶
type ApproveDecision ¶
type ApproveDecision struct {
TerminalHosts []string
TerminalModeCap string
Approve bool
DenyReason string
}
ApproveDecision 用户批准授权(已通过 Web 登录与解锁校验)。
type CIMDDocument ¶
type CIMDDocument struct {
ClientID string `json:"client_id"`
ClientName string `json:"client_name"`
RedirectURIs []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
TokenAuth string `json:"token_endpoint_auth_method"`
}
CIMDDocument 是客户端元数据文档的最小字段集。
type PendingRequestView ¶
type PendingRequestView struct {
ID string `json:"id"`
ClientID string `json:"client_id"`
ClientName string `json:"client_name"`
RedirectHost string `json:"redirect_host"`
Scopes []string `json:"scopes"`
Resource string `json:"resource"`
WarnUntrusted bool `json:"warn_untrusted"`
WarnLoopback bool `json:"warn_loopback"`
}
PendingRequest 供 REST 读取待决授权。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service OAuth 授权服务器与资源元数据。
func NewService ¶
func (*Service) GetPending ¶
func (s *Service) GetPending(id string) (*PendingRequestView, bool)
func (*Service) ResolveCredential ¶
func (*Service) RevokeGrant ¶
RevokeGrant 管理端撤销授权。
func (*Service) SavePolicy ¶
SavePolicy 保存 OAuth 策略并记审计。detail 只记各开关的开 / 关与「是否填了对外地址」,不写地址本身,也不含任何机密。