Last active
June 8, 2022 10:38
-
-
Save cp-sumi-k/9f68492cf66a9426e16dfbd1b3700ea3 to your computer and use it in GitHub Desktop.
https://medium.com/canopas/golang-handling-appstore-server-to-server-v2-notifications-ef1e8eb05118- extract_header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare header structure contains algorithm and token type | |
type NotificationHeader struct { | |
Alg string `json:"alg"` | |
X5c []string `json:"x5c"` | |
} | |
// extract header from given JWS formatted token | |
func extractHeaderByIndex(tokenStr string, index int) ([]byte, error) { | |
tokenArr := strings.Split(tokenStr, ".") // get header from token | |
headerByte, err := base64.RawStdEncoding.DecodeString(tokenArr[0]) //convert header to byte | |
if err != nil { | |
return nil, err | |
} | |
var header NotificationHeader | |
err = json.Unmarshal(headerByte, &header) // bind byte to header structure | |
if err != nil { | |
return nil, err | |
} | |
certByte, err := base64.StdEncoding.DecodeString(header.X5c[index]) //decode x.509 cerificate headers to byte | |
if err != nil { | |
return nil, err | |
} | |
return certByte, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment