Skip to content

Commit

Permalink
Merge pull request #295 from outdoorsy/sign-in-with-apple
Browse files Browse the repository at this point in the history
apple -- make SecretParams properties public
  • Loading branch information
bentranter committed Oct 29, 2019
2 parents a472872 + 305b91e commit 0c61c93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions providers/apple/apple.go
Expand Up @@ -63,12 +63,12 @@ func (p Provider) ClientId() string {
}

type SecretParams struct {
pkcs8PrivateKey, teamId, keyId, clientId string
iat, exp int
PKCS8PrivateKey, TeamId, KeyId, ClientId string
Iat, Exp int
}

func MakeSecret(sp SecretParams) (*string, error) {
block, rest := pem.Decode([]byte(strings.TrimSpace(sp.pkcs8PrivateKey)))
block, rest := pem.Decode([]byte(strings.TrimSpace(sp.PKCS8PrivateKey)))
if block == nil || len(rest) > 0 {
return nil, errors.New("invalid private key")
}
Expand All @@ -77,13 +77,13 @@ func MakeSecret(sp SecretParams) (*string, error) {
return nil, err
}
token := jwt.NewWithClaims(jwt.SigningMethodES256, jwt.MapClaims{
"iss": sp.teamId,
"iat": sp.iat,
"exp": sp.exp,
"iss": sp.TeamId,
"iat": sp.Iat,
"exp": sp.Exp,
"aud": AppleAudOrIss,
"sub": sp.clientId,
"sub": sp.ClientId,
})
token.Header["kid"] = sp.keyId
token.Header["kid"] = sp.KeyId
ss, err := token.SignedString(pk)
return &ss, err
}
Expand Down
12 changes: 6 additions & 6 deletions providers/apple/apple_test.go
Expand Up @@ -58,16 +58,16 @@ func TestMakeSecret(t *testing.T) {

iat := 1570636633
ss, err := MakeSecret(SecretParams{
pkcs8PrivateKey: `-----BEGIN PRIVATE KEY-----
PKCS8PrivateKey: `-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgPALVklHT2n9FNxeP
c1+TCP+Ep7YOU7T9KB5MTVpjL1ShRANCAATXAbDMQ/URATKRoSIFMkwetLH/M2S4
nNFzkp23qt9IJDivieB/BBJct1UvhoICg5eZDhSR+x7UH3Uhog8qgoIC
-----END PRIVATE KEY-----`, // example
teamId: "TK...",
keyId: "<keyId>",
clientId: "<clientId>",
iat: iat,
exp: iat + 15777000,
TeamId: "TK...",
KeyId: "<keyId>",
ClientId: "<clientId>",
Iat: iat,
Exp: iat + 15777000,
})
a.NoError(err)
a.NotZero(ss)
Expand Down

0 comments on commit 0c61c93

Please sign in to comment.