Skip to content

fix(ios-publish): accept body on http post and update to new api #5580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/common/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 6 additions & 10 deletions lib/services/apple-portal/apple-portal-application-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -36,20 +34,18 @@ export class ApplePortalApplicationService
}

public async getApplicationsByProvider(
contentProviderId: number,
dsId: string
contentProviderId: string
): Promise<IApplePortalApplication> {
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,
Expand Down
35 changes: 20 additions & 15 deletions lib/services/apple-portal/apple-portal-session-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,24 @@ export class ApplePortalSessionService implements IApplePortalSessionService {
return result;
}

public async createWebSession(
contentProviderId: number,
dsId: string
): Promise<string> {
public async createWebSession(contentProviderId: string): Promise<string> {
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",
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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" },
});

Expand Down
5 changes: 2 additions & 3 deletions lib/services/apple-portal/definitions.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ICredentials } from "../../common/declarations";

interface IApplePortalSessionService {
createWebSession(contentProviderId: number, dsId: string): Promise<string>;
createWebSession(contentProviderId: string): Promise<string>;
createUserSession(
credentials: ICredentials,
opts?: IAppleCreateUserSessionOptions
Expand All @@ -19,8 +19,7 @@ interface IApplePortalApplicationService {
user: IApplePortalUserDetail
): Promise<IApplePortalApplicationSummary[]>;
getApplicationsByProvider(
contentProviderId: number,
dsId: string
contentProviderId: string
): Promise<IApplePortalApplication>;
getApplicationByBundleId(
user: IApplePortalUserDetail,
Expand Down