第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無法使用 JWT 令牌連接到 Apple App Store API

無法使用 JWT 令牌連接到 Apple App Store API

catspeake 2023-10-20 15:12:52
我需要為 Store Connect API 生成 JWT 令牌。這是我的令牌生成代碼:console.log("?? appStoreConnectAPIFromNode.js running ???")const fs   = require('fs');const jwt  = require('jsonwebtoken'); // npm i jsonwebtoken// You get privateKey, apiKeyId and issuerId from your Apple App Store Connect accountconst privateKey = fs.readFileSync("./AuthKey-XXXXXXXX.p8") // this is the file you can only download once and should treat like a real, very precious key.const apiKeyId = "XXXXXXXX"const issuerId = "XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXX"let now = Math.round((new Date()).getTime() / 1000); // Notice the /1000 let nowPlus20 = now + 1199 // 1200 === 20 minuteslet payload = {    "iss": issuerId,    "exp": nowPlus20,    "aud": "appstoreconnect-v1",    "iat": now}let signOptions = {    "algorithm": "ES256", // you must use this algorythm, not jsonwebtoken's default    header : {        "alg": "ES256",        "kid": apiKeyId,        "typ": "JWT"    }};let token = jwt.sign(payload, privateKey, signOptions);console.log('@token: ', token);fs.writeFile('Output.txt', token, (err) => {           // In case of a error throw err.     if (err) throw err; })我收到了這個(gè)回復(fù) "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"        }]我認(rèn)為問題在于令牌(直接帶有簽名)。當(dāng)我嘗試在https://jwt.io/#debugger-io上解碼令牌時(shí),我的有效負(fù)載和標(biāo)頭已正確解碼。狀態(tài):簽名無效我做錯(cuò)了什么?有什么想法如何正確地做到這一點(diǎn)嗎?
查看完整描述

4 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

我也遇到這個(gè)問題,我和隊(duì)友解決了。。。。。


解決方案:


刪除有效負(fù)載中的“iat”(這很重要):像這樣,

let payload = {

     iss: *******,

     exp: *******,

     aud: "appstoreconnect-v1",

     bid: "your_bundle_id",

   };

網(wǎng)址:我用的是axios:

const { data } = await axios({

     method: "GET",

     url: "https://api.storekit.itunes.apple.com/inApps/v1/history/",

     headers: {

       "Content-type": "application/json",

       Authorization: `Bearer ${token}`,

     },

   });

res.json(data);


查看完整回答
反對(duì) 回復(fù) 2023-10-20
?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

我最近也需要解決這個(gè)問題,在學(xué)習(xí)了很多教程之后,這些教程經(jīng)常給出應(yīng)用程序商店連接 api 的錯(cuò)誤答案。我找到了一種讓它發(fā)揮作用的方法。我在 Java 中就是這樣做的。


import com.auth0.jwt.JWT;

import com.auth0.jwt.algorithms.Algorithm;

import org.bouncycastle.openssl.PEMParser;

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;

import java.security.spec.PKCS8EncodedKeySpec;

import java.security.interfaces.ECPrivateKey;

import java.security.KeyFactory;

import java.io.FileReader;

import java.util.Base64;

import java.time.Instant;

import java.time.temporal.ChronoUnit;


// The code is like this so try it in whatever method you want, 

// break it up into pieces so it's a bit more readable


// These variables are the minimum you should need

String keyFile = "/path/to/app_store_AuthKey_XXXX.p8";

// The XXXX is the same XXXX from the keyFile filename itself

String keyId = "XXXX";

String issuerId = "1234-1234-1234-1234-1234";


FileReader kfReader = new FileReader(keyFile);

PEMParser pemParser = new PEMParser(kfReader);

PrivateKeyInfo info = (PrivateKeyInfo) pemParser.readObject();

byte[] pkData = info.getEncoded();


// Convert the PrivateKeyInfo object to a PKCS8EncodedKeySpec object

PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkData);


KeyFactory keyFactory = KeyFactory.getInstance("EC");

ECPrivateKey privateKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);


Algorithm algorithm = Algorithm.ECDSA256(null, privateKey);


Instant expiration = Instant.now().plus(TIMEOUT_MINUTES, ChronoUnit.MINUTES);


return JWT.create()

          .withKeyId(keyId)

          .withIssuer(issuerId)

          .withExpiresAt(expiration)

          .withAudience("appstoreconnect-v1")

          .sign(algorithm);


查看完整回答
反對(duì) 回復(fù) 2023-10-20
?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊

我試圖解決我自己的問題,即使用 JWT 連接到 Apple Music API,我在您的有效負(fù)載中注意到了兩件事。首先,您將 1200 添加到 IAT 中,修復(fù)了我的問題,所以謝謝您。第二個(gè)是函數(shù)現(xiàn)在返回一個(gè)浮點(diǎn)數(shù)。我認(rèn)為 API 需要一個(gè) int。我會(huì)嘗試"iat": parseInt(now)或者now = Math.floor(new Date().getTime() / 1000)



查看完整回答
反對(duì) 回復(fù) 2023-10-20
?
呼啦一陣風(fēng)

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊

根據(jù)jsonwebtoken使用說明。options您可以直接在空負(fù)載上使用,如下所示:


let signOptions = {

? ? issuer: issuerId,

? ? keyid: apiKeyId,

? ? expiresIn: '20m',

? ? audience: 'appstoreconnect-v1',

? ? algorithm: 'ES256'

};


let token = jwt.sign({}, privateKey, signOptions);


查看完整回答
反對(duì) 回復(fù) 2023-10-20
  • 4 回答
  • 0 關(guān)注
  • 374 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)