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

Consider embed jwt.RegisteredClaims to SubscriptionNotificationV2DecodedPayload? #225

Closed
laeo opened this issue Jul 5, 2023 · 3 comments

Comments

@laeo
Copy link

laeo commented Jul 5, 2023

I want parse SubscriptionNotificationV2.SignedPayload.SignedPayload payload to SubscriptionNotificationV2DecodedPayload by calls jwt.ParseWithClaims, but the struct does not fit jwt.Claims interface.

@richzw
Copy link
Collaborator

richzw commented Jul 5, 2023

One option could be as below https://github.com/awa/go-iap#parse-notification-from-app-store

	token := jwt.Token{}
	client := appstore.New()
	err := client.ParseNotificationV2(tokenStr, &token)

	claims, ok := token.Claims.(jwt.MapClaims)
	for key, val := range claims {
		fmt.Printf("Key: %v, value: %v\n", key, val) 
	}

@richzw
Copy link
Collaborator

richzw commented Jul 6, 2023

@laeo Another option could be to wrap SubscriptionNotificationV2DecodedPayload with jwt.RegisteredClaims, then jwt.ParseWithClaims could be called directly.

	type CustomClaims struct {
		jwt.RegisteredClaims
		SubscriptionNotificationV2DecodedPayload
	}
	ret := &CustomClaims{}
	t, e := jwt.ParseWithClaims(tokenStr, ret, func(token *jwt.Token) (interface{}, error) {
		return cert.ExtractPublicKeyFromToken(tokenStr)
	})

@laeo
Copy link
Author

laeo commented Jul 6, 2023

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants