Documentation
¶
Index ¶
- Constants
- type AppleKey
- type JWTBody
- type JWTHeader
- type JWTTokenBody
- type JWTTokenHeader
- type SiwaConfig
- func (self *SiwaConfig) ExchangeAuthCode(code string, redirectUri string) (*Token, error)
- func (self *SiwaConfig) ExchangeRefreshToken(code string, redirectUri string) (*Token, error)
- func (self *SiwaConfig) GetClientSecret() (string, error)
- func (self *SiwaConfig) GetEncodedJwtBody(bundleId string, teamId string, d time.Duration) (string, error)
- func (self *SiwaConfig) GetEncodedJwtHeader(keyId string) (string, error)
- func (self *SiwaConfig) SetSecretP8Bytes(p8Contents []byte)
- func (self *SiwaConfig) SetSecretP8File(p8Filename string) error
- func (self *SiwaConfig) SetSecretP8String(p8Contents string)
- func (self *SiwaConfig) ValidateObject() (bool, error)
- type SiwaIdToken
- type Token
Constants ¶
const APPLE_AUTH_URL = "https://appleid.apple.com/auth/token"
const APPLE_KEYS_URL = "https://appleid.apple.com/auth/keys"
const AUD = "https://appleid.apple.com"
aud The audience registered claim key, the value of which identifies the recipient the JWT is intended for. Since this token is meant for Apple, use https://appleid.apple.com. https://developer.apple.com/documentation/signinwithapplerestapi/generate_and_validate_tokens
const AUTHORIZATION_CODE = "code"
const REFRESH_TOKEN = "refresh_token"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppleKey ¶
type AppleKey struct { Kty string `json:"kty"` Kid string `json:"kid"` Use string `json:"use":` Alg string `json:"alg"` N string `json:"n"` E string `json:"e"` }
key object fetched from APPLE_KEYS_URL
type JWTBody ¶
type JWTBody struct { Iss string `json:"iss"` Iat int64 `json:"iat"` Exp int64 `json:"exp"` Aud string `json:"aud"` Sub string `json:"sub"` }
struct for JWT Body
type JWTTokenBody ¶
type JWTTokenBody struct { Iss string `json:"iss"` Iat int64 `json:"iat"` Exp int64 `json:"exp"` Aud string `json:"aud"` Sub string `json:"sub"` AtHash string `json:"at_hash"` Email string `json:"email"` EmailVerified string `json:"email_verified"` IsPrivateEmail string `json:"is_private_email"` RealUserStatus int64 `json:"real_user_status"` AuthTime int64 `json:"auth_time"` Nonce string `json:"nonce"` }
struct for JWT Body
type JWTTokenHeader ¶
struct for JWT Header
type SiwaConfig ¶
type SiwaConfig struct { KeyId string //key Id from Certificates, Identifiers & Profiles on developers.apple.com TokenDelta time.Duration //duration for which you would want the generated client_secret jwt token to be valid. Can not be more than 15777000 (6 months in seconds) from the Current Unix Time on the server. TeamId string //Team Id that is configured with Key, can also ne found in Certificates, Identifiers & Profiles on developers.apple.com BundleId string //bundleId for product com.companyname.product PemFileContents []byte //contents of the p8 file Nonce string //nonce is set while making the request to generate authorization_code. If you dont use it, keep it an empty string }
struct holding various values needed to generate tokens. this should only needed to be initialized once and then can be kept in memory
func GetObject ¶
func GetObject(keyId string, teamId string, bundleId string, d time.Duration, nonce string) *SiwaConfig
helper function to get SiwaConfig object
func (*SiwaConfig) ExchangeAuthCode ¶
func (self *SiwaConfig) ExchangeAuthCode(code string, redirectUri string) (*Token, error)
function to exchange authorization code for id token, access token, refresh token, etc.
func (*SiwaConfig) ExchangeRefreshToken ¶
func (self *SiwaConfig) ExchangeRefreshToken(code string, redirectUri string) (*Token, error)
function to exchange refresh token for access token
func (*SiwaConfig) GetClientSecret ¶
func (self *SiwaConfig) GetClientSecret() (string, error)
get the client_secret
func (*SiwaConfig) GetEncodedJwtBody ¶
func (self *SiwaConfig) GetEncodedJwtBody(bundleId string, teamId string, d time.Duration) (string, error)
function to get encoded jwt body
func (*SiwaConfig) GetEncodedJwtHeader ¶
func (self *SiwaConfig) GetEncodedJwtHeader(keyId string) (string, error)
function to get encoded jwt header
func (*SiwaConfig) SetSecretP8Bytes ¶
func (self *SiwaConfig) SetSecretP8Bytes(p8Contents []byte)
helper function to set secret file contents as bytes this needs to be pem encoded PKCS8 private key same format as the p8 file downloaded from apple -----BEGIN PRIVATE KEY----- jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybje/vuewkvbbhjdjbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshj -----END PRIVATE KEY-----
func (*SiwaConfig) SetSecretP8File ¶
func (self *SiwaConfig) SetSecretP8File(p8Filename string) error
helper function to set secrets value by filename the function expects full path to the p8 file generated in the keys and certificates section of developer account it should look like this: -----BEGIN PRIVATE KEY----- jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybje/vuewkvbbhjdjbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshj -----END PRIVATE KEY-----
func (*SiwaConfig) SetSecretP8String ¶
func (self *SiwaConfig) SetSecretP8String(p8Contents string)
helper function to set secret file contents as a string this needs to be pem encoded PKCS8 private key same format as the p8 file downloaded from apple -----BEGIN PRIVATE KEY----- jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybje/vuewkvbbhjdjbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshjdjkhjsbjvguybjebvuewkvbbhj+jbdhbjhbvjhbvjhbvbjvbvjvagcve jkfweshj -----END PRIVATE KEY-----
func (*SiwaConfig) ValidateObject ¶
func (self *SiwaConfig) ValidateObject() (bool, error)
function to validate the object
type SiwaIdToken ¶
type SiwaIdToken struct { Header *JWTTokenHeader Body *JWTTokenBody Signature []byte Valid bool }
struct to hold the decoded idtoken
func ValidateIdToken ¶
func ValidateIdToken(aud string, idToken string) (*SiwaIdToken, string)
validates idToken without nonce check
func ValidateIdTokenWithNonce ¶
func ValidateIdTokenWithNonce(aud string, idToken string, nonce string) (*SiwaIdToken, string)
validates idtoken more info: https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
type Token ¶
type Token struct { //(Reserved for future use) A token used to access allowed data. Currently, no data set has been defined for access. AccessToken string `json:"access_token"` //The type of access token. It will always be bearer. TokenType string `json:"token_type"` //The amount of time, in seconds, before the access token expires. ExpiresIn int64 `json:"expires_in"` //The refresh token used to regenerate new access tokens. Store this token securely on your server. RefreshToken string `json:"refresh_token"` //A JSON Web Token that contains the user’s identity information. IdToken string `json:"id_token"` //Set if ErrorResponse is recieved //A string that describes the reason for the unsuccessful request. The string consists of a single allowed value. //Possible values: invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope Error string `json:"error"` //After the token is fetched from apple, id token is validated //this field stores the result of the validation check Valid bool `json:"_"` //The decoded Id token //Holds the decoded JWT Header, Body, Signature and result of validity check DecodedIdToken *SiwaIdToken `json:"_"` }
struct for token returned from apple