agisboye / app-store-server-api

A Node.js client for the App Store Server API
MIT License
210 stars 32 forks source link

Always getting 401 Unauthorized. #12

Closed HusseinTaha closed 1 year ago

HusseinTaha commented 2 years ago

We are receiving the below error always, we changed the params, different keys, anything will return the same error.

Error: The request is unauthorized; the JSON Web Token (JWT) is invalid. at AppStoreServerAPI.<anonymous> (/node_modules/app-store-server-api/dist/cjs/AppStoreServerAPI.js:158:31) at step (/node_modules/app-store-server-api/dist/cjs/AppStoreServerAPI.js:52:23) at Object.next (/node_modules/app-store-server-api/dist/cjs/AppStoreServerAPI.js:33:53) at fulfilled (/node_modules/app-store-server-api/dist/cjs/AppStoreServerAPI.js:24:58) at processTicksAndRejections (internal/process/task_queues.js:97:5) transactions---- Error: The request is unauthorized; the JSON Web Token (JWT) is invalid. at processTicksAndRejections (internal/process/task_queues.js:97:5) { isHttpError: true, status: 500, code: 'UnknownError', data: undefined, source: undefined } []

our code here:

 const api = new AppStoreServerAPI(
            key, keyId, issuerId, iosBundleId, Environment.Production
        );

        const response = await api.lookupOrder(orderId);

        if (response.orderLookupStatus === OrderLookupStatus.Valid) {
            const transactions = await decodeTransactions(response.signedTransactions);
            return {
                error: null,
                transactions
            };
        }
agisboye commented 2 years ago

Hi! What version of Node.js are you using?

HusseinTaha commented 2 years ago

Hello, Hope you are well

It's v12.22.12

agisboye commented 2 years ago

That version is not supported, I'm afraid. You'll need v15.6.0 or later.

HusseinTaha commented 2 years ago

mmm, Even I tried to implement the token thing (using jsonwebtoken) and call the Apple API outside this library, and getting the same. Do you think its the same as well requiring newer node version ?

agisboye commented 2 years ago

I don't actually think your issue is related to Node but even if you manage to resolve it, you'll need still need v15.6.0 or later. Otherwise you'll encounter the same error as #10.

Regarding your issue, I'm guessing you are using the wrong key, key ID or issuer ID. Are you sure that you are using an API key for the App Store Server API (as opposed to a key for App Store Connect API)?

HusseinTaha commented 2 years ago

We're trying to fetch order by using the lookup order api https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id

we did generate the key by following the documentation on the apple form.

I also tried to debug the things in the library, but it seems its not calling the apple api yet. The error is being thrown before the request. I mean while generating the token.

agisboye commented 2 years ago

Could it be related to #17? The order lookup endpoint is only available in the production environment.