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

Update golang-jwt/jwt to v5 #308

Merged
merged 2 commits into from
Feb 1, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func main() {
```go
import (
"github.com/awa/go-iap/appstore"
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
)

func main() {
Expand Down
77 changes: 70 additions & 7 deletions appstore/api/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package api

import "github.com/awa/go-iap/appstore"
import (
"github.com/awa/go-iap/appstore"
"github.com/golang-jwt/jwt/v5"
)

// OrderLookupResponse https://developer.apple.com/documentation/appstoreserverapi/orderlookupresponse
type OrderLookupResponse struct {
Expand Down Expand Up @@ -83,6 +86,9 @@ type ConsumptionRequestBody struct {
RefundPreference int32 `json:"refundPreference"`
}

// Verify that JWSRenewalInfoDecodedPayload implements jwt.Claims
var _ jwt.Claims = JWSRenewalInfoDecodedPayload{}

// JWSRenewalInfoDecodedPayload https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload
type JWSRenewalInfoDecodedPayload struct {
AutoRenewProductId string `json:"autoRenewProductId"`
Expand All @@ -105,8 +111,34 @@ type JWSRenewalInfoDecodedPayload struct {
EligibleWinBackOfferIds []string `json:"eligibleWinBackOfferIds,omitempty"`
}

func (J JWSRenewalInfoDecodedPayload) Valid() error {
return nil
// GetAudience implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetAudience() (jwt.ClaimStrings, error) {
return nil, nil
}

// GetExpirationTime implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetExpirationTime() (*jwt.NumericDate, error) {
return nil, nil
}

// GetIssuedAt implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetIssuedAt() (*jwt.NumericDate, error) {
return nil, nil
}

// GetIssuer implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetIssuer() (string, error) {
return "", nil
}

// GetNotBefore implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetNotBefore() (*jwt.NumericDate, error) {
return nil, nil
}

// GetSubject implements jwt.Claims.
func (J JWSRenewalInfoDecodedPayload) GetSubject() (string, error) {
return "", nil
}

// JWSDecodedHeader https://developer.apple.com/documentation/appstoreserverapi/jwsdecodedheader
Expand Down Expand Up @@ -143,6 +175,9 @@ const (
OfferDiscountTypePayUpFront OfferDiscountType = "PAY_UP_FRONT"
)

// Verify that JWSTransaction implements jwt.Claims
var _ jwt.Claims = JWSTransaction{}

// JWSTransaction https://developer.apple.com/documentation/appstoreserverapi/jwstransaction
type JWSTransaction struct {
TransactionID string `json:"transactionId,omitempty"`
Expand Down Expand Up @@ -173,8 +208,34 @@ type JWSTransaction struct {
OfferDiscountType OfferDiscountType `json:"offerDiscountType,omitempty"`
}

func (J JWSTransaction) Valid() error {
return nil
// GetAudience implements jwt.Claims.
func (J JWSTransaction) GetAudience() (jwt.ClaimStrings, error) {
return nil, nil
}

// GetExpirationTime implements jwt.Claims.
func (J JWSTransaction) GetExpirationTime() (*jwt.NumericDate, error) {
return nil, nil
}

// GetIssuedAt implements jwt.Claims.
func (J JWSTransaction) GetIssuedAt() (*jwt.NumericDate, error) {
return nil, nil
}

// GetIssuer implements jwt.Claims.
func (J JWSTransaction) GetIssuer() (string, error) {
return "", nil
}

// GetNotBefore implements jwt.Claims.
func (J JWSTransaction) GetNotBefore() (*jwt.NumericDate, error) {
return nil, nil
}

// GetSubject implements jwt.Claims.
func (J JWSTransaction) GetSubject() (string, error) {
return "", nil
}

// https://developer.apple.com/documentation/appstoreserverapi/extendreasoncode
Expand Down Expand Up @@ -258,8 +319,10 @@ type SendTestNotificationResponse struct {
TestNotificationToken string `json:"testNotificationToken"`
}

type AutoRenewSubscriptionStatus int32
type AutoRenewStatus int32
type (
AutoRenewSubscriptionStatus int32
AutoRenewStatus int32
)

const (
SubscriptionActive AutoRenewSubscriptionStatus = 1
Expand Down
2 changes: 1 addition & 1 deletion appstore/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
)

const (
Expand Down
13 changes: 1 addition & 12 deletions appstore/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"os"
"sync"
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -113,16 +112,6 @@ func (t *Token) Generate() error {
return nil
}

// loadKeyFromFile loads a .p8 certificate from a local file and returns a *ecdsa.PrivateKey.
func (t *Token) loadKeyFromFile(filename string) (*ecdsa.PrivateKey, error) {
bytes, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

return t.passKeyFromByte(bytes)
}

// passKeyFromByte loads a .p8 certificate from an in memory byte array and returns an *ecdsa.PrivateKey.
func (t *Token) passKeyFromByte(bytes []byte) (*ecdsa.PrivateKey, error) {
block, _ := pem.Decode(bytes)
Expand Down
36 changes: 19 additions & 17 deletions appstore/mocks/appstore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading