From 43e6298e06fb05bd022878a904260c165918b9aa Mon Sep 17 00:00:00 2001 From: Jason Cassidy Date: Tue, 28 Sep 2021 15:37:44 +0100 Subject: [PATCH 1/3] fix(ios-publish): accept body on http post and update to new api --- lib/common/http-client.ts | 8 +++++ .../apple-portal-application-service.ts | 16 ++++----- .../apple-portal-session-service.ts | 35 +++++++++++-------- lib/services/apple-portal/definitions.d.ts | 5 ++- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/common/http-client.ts b/lib/common/http-client.ts index a8bc49acb3..e85682b9fe 100644 --- a/lib/common/http-client.ts +++ b/lib/common/http-client.ts @@ -107,12 +107,20 @@ export class HttpClient implements Server.IHttpClient { }, }); } + + let data; + + if (options.body) { + data = options.body; + } + const result = await axios({ url: options.url, headers: options.headers, method: options.method, proxy: false, httpAgent: agent, + data: data, }).catch((err) => { this.$logger.trace("An error occurred while sending the request:", err); if (err.response) { diff --git a/lib/services/apple-portal/apple-portal-application-service.ts b/lib/services/apple-portal/apple-portal-application-service.ts index aea5ad7f93..1893b79e1e 100644 --- a/lib/services/apple-portal/apple-portal-application-service.ts +++ b/lib/services/apple-portal/apple-portal-application-service.ts @@ -23,11 +23,9 @@ export class ApplePortalApplicationService let result: IApplePortalApplicationSummary[] = []; for (const account of user.associatedAccounts) { - const contentProviderId = account.contentProvider.contentProviderId; - const dsId = user.sessionToken.dsId; + const contentProviderId = account.contentProvider.contentProviderPublicId; const applications = await this.getApplicationsByProvider( - contentProviderId, - dsId + contentProviderId ); result = result.concat(applications.summaries); } @@ -36,20 +34,18 @@ export class ApplePortalApplicationService } public async getApplicationsByProvider( - contentProviderId: number, - dsId: string + contentProviderId: string ): Promise { const webSessionCookie = await this.$applePortalSessionService.createWebSession( - contentProviderId, - dsId + contentProviderId ); const response = await this.$httpClient.httpRequest({ url: "https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/manageyourapps/summary/v2", method: "GET", - body: JSON.stringify({ + body: { contentProviderId, - }), + }, headers: { "Content-Type": "application/json", Cookie: webSessionCookie, diff --git a/lib/services/apple-portal/apple-portal-session-service.ts b/lib/services/apple-portal/apple-portal-session-service.ts index e17c1c5c29..7fad35e8ed 100644 --- a/lib/services/apple-portal/apple-portal-session-service.ts +++ b/lib/services/apple-portal/apple-portal-session-service.ts @@ -79,19 +79,24 @@ export class ApplePortalSessionService implements IApplePortalSessionService { return result; } - public async createWebSession( - contentProviderId: number, - dsId: string - ): Promise { + public async createWebSession(contentProviderId: string): Promise { const webSessionResponse = await this.$httpClient.httpRequest({ url: - "https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/v1/session/webSession", + "https://appstoreconnect.apple.com/olympus/v1/providerSwitchRequests", method: "POST", - body: JSON.stringify({ - contentProviderId, - dsId, - ipAddress: null, - }), + body: { + data: { + type: "providerSwitchRequests", + relationships: { + provider: { + data: { + type: "providers", + id: contentProviderId, + }, + }, + }, + }, + }, headers: { Accept: "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br", @@ -132,7 +137,7 @@ export class ApplePortalSessionService implements IApplePortalSessionService { try { await this.loginCore(credentials); } catch (err) { - const statusCode = err && err.response && err.response.statusCode; + const statusCode = err && err.response && err.response.status; result.areCredentialsValid = statusCode !== 401 && statusCode !== 403; result.isTwoFactorAuthenticationEnabled = statusCode === 409; @@ -177,11 +182,11 @@ For more details how to set up your environment, please execute "tns publish ios "X-Apple-Widget-Key": loginConfig.authServiceKey, Accept: "application/json, text/javascript", }; - const body = JSON.stringify({ + const body = { accountName: credentials.username, password: credentials.password, rememberMe: true, - }); + }; const loginResponse = await this.$httpClient.httpRequest({ url: loginUrl, @@ -244,11 +249,11 @@ For more details how to set up your environment, please execute "tns publish ios await this.$httpClient.httpRequest({ url: `https://idmsa.apple.com/appleauth/auth/verify/trusteddevice/securitycode`, method: "POST", - body: JSON.stringify({ + body: { securityCode: { code: token.toString(), }, - }), + }, headers: { ...headers, "Content-Type": "application/json" }, }); diff --git a/lib/services/apple-portal/definitions.d.ts b/lib/services/apple-portal/definitions.d.ts index 8c50e4f661..f8ee4a5558 100644 --- a/lib/services/apple-portal/definitions.d.ts +++ b/lib/services/apple-portal/definitions.d.ts @@ -1,7 +1,7 @@ import { ICredentials } from "../../common/declarations"; interface IApplePortalSessionService { - createWebSession(contentProviderId: number, dsId: string): Promise; + createWebSession(contentProviderId: string): Promise; createUserSession( credentials: ICredentials, opts?: IAppleCreateUserSessionOptions @@ -19,8 +19,7 @@ interface IApplePortalApplicationService { user: IApplePortalUserDetail ): Promise; getApplicationsByProvider( - contentProviderId: number, - dsId: string + contentProviderId: string ): Promise; getApplicationByBundleId( user: IApplePortalUserDetail, From 930dfd989ead4f6792b3115db9348f9f3fe31acc Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 30 Sep 2021 19:05:39 +0200 Subject: [PATCH 2/3] Update lib/common/http-client.ts --- lib/common/http-client.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/common/http-client.ts b/lib/common/http-client.ts index e85682b9fe..2e340f20f2 100644 --- a/lib/common/http-client.ts +++ b/lib/common/http-client.ts @@ -107,13 +107,6 @@ export class HttpClient implements Server.IHttpClient { }, }); } - - let data; - - if (options.body) { - data = options.body; - } - const result = await axios({ url: options.url, headers: options.headers, From 542040787adeed163d68db95e112fec1fb328461 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 30 Sep 2021 19:05:43 +0200 Subject: [PATCH 3/3] Update lib/common/http-client.ts --- lib/common/http-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/http-client.ts b/lib/common/http-client.ts index 2e340f20f2..dabbf62a0d 100644 --- a/lib/common/http-client.ts +++ b/lib/common/http-client.ts @@ -113,7 +113,7 @@ export class HttpClient implements Server.IHttpClient { method: options.method, proxy: false, httpAgent: agent, - data: data, + data: options.body, }).catch((err) => { this.$logger.trace("An error occurred while sending the request:", err); if (err.response) {