siwarest

package module
v0.0.0-...-6b82a1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 12 Imported by: 0

README

Sign in with Apple REST API Client for Go

go-sign-in-with-apple-rest-api is a simple client working with Sign in with Apple REST API.

For more information, please refer to the REST API specification.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidRequest indicates that the request is malformed.
	ErrInvalidRequest = errors.New("siwarest: invalid_request")
	// ErrInvalidClient indicates that the client authentication failed.
	ErrInvalidClient = errors.New("siwarest: invalid_client")
	// ErrInvalidGrant indicates that the authorization grant or refresh token is invalid.
	ErrInvalidGrant = errors.New("siwarest: invalid_grant")
	// ErrUnauthorizedClient indicates that the client isn’t authorized to use this authorization grant type.
	ErrUnauthorizedClient = errors.New("siwarest: unauthorized_grant_type")
	// ErrUnsupportedGrantType indicates that the authenticated client isn’t authorized to use this grant type.
	ErrUnsupportedGrantType = errors.New("siwarest: unsupported_grant_type")
	// ErrInvalidScope indicates that the requested scope is invalid.
	ErrInvalidScope = errors.New("siwarest: invalid_scope")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a HTTP client.

func New

func New(conf *ClientConfig) (*Client, error)

New initializes Client.

func (*Client) GenerateAndValidateTokens

func (c *Client) GenerateAndValidateTokens(ctx context.Context, input GenerateAndValidateTokenInput) (*TokenResponse, error)

GenerateAndValidateTokens validates an authorization grant code delivered to your app to obtain tokens, or validate an existing refresh token.

Please see also https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens

func (*Client) RevokeTokens

func (c *Client) RevokeTokens(ctx context.Context, input RevokeTokensInput) error

RevokeTokens invalidates the tokens and associated user authorizations for a user when they are no longer associated with your app.

Please see also https://developer.apple.com/documentation/sign_in_with_apple/revoke_tokens

type ClientConfig

type ClientConfig struct {
	// Client is the HTTP client. The default is http.DefaultClient.
	Client *http.Client
	// ClientID is an identifier (App ID or ClientID) for your app.
	ClientID string
	// KeyID is used to JWT claim. It is generated for the Sign in with Apple private key associated with your developer account.
	KeyID string
	// TeamID is used to JWT claim. Use your 10-character Team ID associated with your developer account.
	TeamID string
	// PrivateKeyPEM is used to sign the JWT of the client secret. Private key can be downloaded from Apple Developer.
	PrivateKeyPEM string
}

ClientConfig saves parameters to setup Client.

type ErrorResponse

type ErrorResponse struct {
	// Error is a string that describes the reason for the unsuccessful request. The string consists of a single allowed value.
	Error string `json:"error"`
}

ErrorResponse is the error object returned after an unsuccessful request. https://developer.apple.com/documentation/sign_in_with_apple/errorresponse

type GenerateAndValidateTokenInput

type GenerateAndValidateTokenInput interface {
	// contains filtered or unexported methods
}

GenerateAndValidateTokensInput is a parameter to call Generate and validate tokens API.

func GenerateAndValidateTokensWithAuthorizationCode

func GenerateAndValidateTokensWithAuthorizationCode(code string) GenerateAndValidateTokenInput

GenerateAndValidateTokensWithAuthorizationCode is an authorization code received in an authorization response sent to your app.

func GenerateAndValidateTokensWithRefreshToken

func GenerateAndValidateTokensWithRefreshToken(refreshToken string) GenerateAndValidateTokenInput

GenerateAndValidateTokensWithRefreshToken is a refresh token received from the validation server during an authorization request.

type RevokeTokensInput

type RevokeTokensInput interface {
	// contains filtered or unexported methods
}

RevokeTokensInput is a parameter to call Revoke tokens API.

func RevokeTokensInputWithAccessToken

func RevokeTokensInputWithAccessToken(token string) RevokeTokensInput

RevokeTokensInputWithAccessToken is an access token generated by Generate and validate tokens API.

func RevokeTokensInputWithRefreshToken

func RevokeTokensInputWithRefreshToken(token string) RevokeTokensInput

RevokeTokensInputWithRefreshToken is a refresh token generated by Generate and validate tokens API.

type TokenResponse

type TokenResponse struct {
	// AccessToken is a token used to access allowed data, such as generating and exchanging transfer identifiers during user migration.
	AccessToken string `json:"access_token"`
	// ExpiresIn is the amount of time, in seconds, before the access token expires.
	ExpiresIn int `json:"expires_in"`
	// IDToken is a JSON Web Token (JWT) that contains the user’s identity information.
	IDToken string `json:"id_token"`
	// RefreshToken The refresh used to regenerate new access tokens when validating an authorization code.
	// Store this token securely on your server. The refresh token isn’t returned when validating an existing refresh token.
	RefreshToken string `json:"refresh_token"`
	// TokenType is the type of access token, which is always bearer.
	TokenType string `json:"token_type"`
}

TokenResponse is the response token object returned on a successful request. https://developer.apple.com/documentation/sign_in_with_apple/tokenresponse

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL