我正在嘗試使用 App Store Connect API。根據(jù)文檔,首先我嘗試生成 JWT 令牌。golang 中的代碼如下:? package main? ? import (? ? ? ? "fmt"? ? ? ? "io/ioutil"? ? ? ? "log"? ? ? ? "time"? ? ? ? "github.com/dgrijalva/jwt-go"? ? )var iss = "xxxxxxxxxxxxxxxxxxxxx"var kid = "xxxxx"func main() {? ? ? ? bytes, err := ioutil.ReadFile("AuthKey.p8")? ? ? ? if err!=nil {? ? ? ? ? ? fmt.Println(err)? ? ? ? }? ? ? ? token := jwt.NewWithClaims(jwt.SigningMethodES256, jwt.MapClaims{? ? ? ? ? ? "iss": iss,? ? ? ? ? ? "exp": time.Now().Unix()+6000,? ? ? ? ? ? "aud": "appstoreconnect-v1",? ? ? ? })? ? ? ? token.Header["kid"] = kid? ? ? ? tokenString, err := token.SignedString(bytes)? ? ? ? if err != nil {? ? ? ? ? ? log.Fatal(err)? ? ? ? }? ? ? ? fmt.Println(tokenString)? ? }AuthKey.p8 - 來自https://appstoreconnect.apple.com/access/api的 p8 私鑰似乎 jwt lib 無法在簽名密鑰上使用此 p8,所以我收到錯(cuò)誤:?key is of invalid type也許有人已經(jīng)遇到了同樣的問題?或者有其他語言的例子嗎?UPD:?在此建議之后,我將代碼更新為:func main() {? ? bytes, err := ioutil.ReadFile("AuthKey.p8")? ? if err!=nil {? ? ? ? fmt.Println(err)? ? }? ? block, _ := pem.Decode(bytes)? ? key, err := x509.ParsePKCS8PrivateKey(block.Bytes)? ? if err != nil {? ? ? ? log.Fatal(err)? ? }? ? token := jwt.NewWithClaims(jwt.SigningMethodES256, jwt.MapClaims{? ? ? ? "iss": iss,? ? ? ? "exp": time.Now().Unix()+6000,? ? ? ? "aud": "appstoreconnect-v1",? ? })? ? token.Header["kid"] = kid? ? tokenString, err := token.SignedString(key)? ? if err != nil {? ? ? ? log.Fatal(err)? ? }? ? fmt.Println(tokenString)}并獲取 JWT 令牌,但當(dāng)我嘗試使用它時(shí),從 Apple api 獲取了 401。?{? ? ? ? "errors": [{? ? ? ? ? ? ? ? "status": "401",? ? ? ? ? ? ? ? "code": "NOT_AUTHORIZED",? ? ? ? ? ? ? ? "title": "Authentication credentials are missing or invalid.",? ? ? ? ? ? ? ? "detail": "Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens"? ? ? ? }]}
ItunesConnectApi JWT
繁星點(diǎn)點(diǎn)滴滴
2023-07-26 19:40:16