diff --git a/lib/common/http-client.ts b/lib/common/http-client.ts index a8bc49acb3..dabbf62a0d 100644 --- a/lib/common/http-client.ts +++ b/lib/common/http-client.ts @@ -113,6 +113,7 @@ export class HttpClient implements Server.IHttpClient { method: options.method, proxy: false, httpAgent: agent, + data: options.body, }).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,