Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apple -- make SecretParams properties public #295

Merged
merged 1 commit into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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