API 参考取自源码中的 Go 文档注释,以英文书写。
package identity
import "github.com/nsgo-dev/game/pkg/online/accounts/identity"概述
Package identity is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides provider verifiers for accounts.IdentityVerifier.
OIDC verifies signed ID tokens against a configured JWKS endpoint. Steam and mini-program verifiers wrap the provider's server-side exchange API because those APIs need each game's credentials and are not part of this module.
Package identity is experimental: its API and documented formats may change in a minor release. See the API stability policy. contains standards-based account identity verifiers.
索引
变量
var (
// ErrInvalidToken reports a credential a verifier refused: a malformed, unsigned or wrongly signed token, one for another issuer or audience, an expired one, or one signed with a key the issuer does not publish.
ErrInvalidToken = errors.New("identity: invalid token")
// ErrInvalidSubject reports a provider exchange that returned an empty subject or one with a line break.
ErrInvalidSubject = errors.New("identity: provider returned an invalid subject")
)类型
type ExchangeFunc func(context.Context, string) (string, error)ExchangeFunc exchanges a provider credential for its stable subject.
type ExchangeVerifier struct {
Provider string
Exchange ExchangeFunc
}ExchangeVerifier adapts a server-side provider exchange to an identity verifier. The callback must authenticate the credential with the provider, then return its stable subject. Callback errors are deliberately redacted.
func MiniProgram(provider string, exchange ExchangeFunc) ExchangeVerifierMiniProgram returns a verifier for a code-to-session exchange. provider is the platform name, such as wechat, qq, douyin or alipay.
func Steam(exchange ExchangeFunc) ExchangeVerifierSteam returns a verifier for an AuthenticateUserTicket-style exchange.
func (v ExchangeVerifier) VerifyIdentity(ctx context.Context, credential string) (string, error)VerifyIdentity authenticates credential through Exchange.
type OIDC struct {
Issuer string
JWKSURL string
ClientIDs []string
Client *http.Client
// Clock and Now both override the current time; Now wins when both are set.
Clock func() time.Time
Now func() time.Time
// Leeway allows for clock skew in the expiry and not-before checks.
Leeway time.Duration
// contains filtered or unexported fields
}OIDC verifies a signed OpenID Connect ID token: an RS256, ES256 or EdDSA (Ed25519) JWT whose issuer is Issuer, whose audience is one of ClientIDs, and which has a subject and has not expired; a token that fails these checks is an error wrapping ErrInvalidToken. Keys come from JWKSURL, or from Issuer's /.well-known/jwks.json when JWKSURL is empty; they are cached for an hour, and an unknown key ID refreshes the cache at most once every five minutes. The default HTTP client is used when Client is nil.
func Apple(clientIDs ...string) *OIDCApple returns an OIDC verifier configured for Sign in with Apple.
func (o *OIDC) VerifyIdentity(ctx context.Context, credential string) (string, error)VerifyIdentity checks credential's signature and claims and returns its subject.