Documentation
¶
Overview ¶
Package oauth 提供 Google ID Token 与 Apple Sign In 验证器。
Google 验证器依赖 Google Identity Platform(idtoken.Validate)。 Apple 验证器支持 ID Token 验签、authorization code 换 token、refresh token 撤销、 Apple S2S Notifications V2 验签解析。
零业务耦合,仅依赖标准库 + golang-jwt + Google/Apple SDK。
快速用法:
googleV := oauth.NewGoogleVerifier()
u, err := googleV.Verify(ctx, idToken, clientID)
// u.Sub, u.Email
appleV := oauth.NewAppleVerifier(oauth.AppleCredentials{ClientID, TeamID, KeyID, PrivateKey})
u, err := appleV.Verify(ctx, identityToken, clientID, nonce)
Index ¶
- Constants
- Variables
- type AppleCredentials
- type AppleNotification
- type AppleTokenResponse
- type AppleUser
- type AppleVerifier
- func (v *AppleVerifier) ExchangeCode(ctx context.Context, code string) (*AppleTokenResponse, error)
- func (v *AppleVerifier) ParseNotification(ctx context.Context, signedPayload string) (*AppleNotification, error)
- func (v *AppleVerifier) RevokeRefreshToken(ctx context.Context, refreshToken string) error
- func (v *AppleVerifier) Verify(ctx context.Context, identityToken, clientID, nonce string) (*AppleUser, error)
- type GoogleUser
- type GoogleVerifier
Constants ¶
const ( AppleEventConsentRevoked = "consent-revoked" AppleEventAccountDeleted = "account-deleted" )
Apple S2S Notification 事件类型常量(Apple 官方值,lowercase with hyphens)。 注意 go-signin-with-apple 库 v0.3.0 注释/测试中把 account-deleted 误写为 "account-delete", 实际 Apple 发送的是 "account-deleted"(带 d),以官方文档为准。
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AppleCredentials ¶
type AppleCredentials struct {
ClientID string
TeamID string
KeyID string
PrivateKey string // PEM-encoded P8 内容
}
AppleCredentials Apple Sign In 配置凭证。
type AppleNotification ¶
AppleNotification Apple S2S 通知验签结果。
type AppleTokenResponse ¶
type AppleTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token"`
}
AppleTokenResponse Apple /auth/token 返回体。
type AppleVerifier ¶
type AppleVerifier struct {
// contains filtered or unexported fields
}
AppleVerifier Apple ID Token 验证 + authorization code 交换。
func NewAppleVerifier ¶
func NewAppleVerifier(cfg AppleCredentials, httpClient *http.Client) *AppleVerifier
NewAppleVerifier 创建 Apple 验证器。 TeamID/KeyID/PrivateKey 任一为空时仅支持 ID Token 验签(code exchange / revoke 不可用)。
func (*AppleVerifier) ExchangeCode ¶
func (v *AppleVerifier) ExchangeCode(ctx context.Context, code string) (*AppleTokenResponse, error)
ExchangeCode 用 authorization code 换 refresh_token。需配置 TeamID/KeyID/PrivateKey。
func (*AppleVerifier) ParseNotification ¶
func (v *AppleVerifier) ParseNotification(ctx context.Context, signedPayload string) (*AppleNotification, error)
ParseNotification 验签并解析 Apple S2S Notifications V2 的 signedPayload。
func (*AppleVerifier) RevokeRefreshToken ¶
func (v *AppleVerifier) RevokeRefreshToken(ctx context.Context, refreshToken string) error
RevokeRefreshToken 撤销 Apple 侧 refresh token。
type GoogleUser ¶
type GoogleUser struct {
Sub string `json:"sub"`
Email string `json:"email"`
Name string `json:"name"`
}
GoogleUser Google 用户信息。
type GoogleVerifier ¶
type GoogleVerifier struct{}
GoogleVerifier 验证 Google ID Token。
func (*GoogleVerifier) Verify ¶
func (v *GoogleVerifier) Verify(ctx context.Context, token, clientID string) (*GoogleUser, error)
Verify 验证 Google ID Token 并返回用户信息。token 来自客户端 Sign In 返回的 idToken。