Skip to content

fix: ability to publish iOS applications for users with two-factor authentication enabled #4903

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 5 commits into from
Jul 30, 2019

Conversation

Fatme
Copy link
Contributor

@Fatme Fatme commented Jul 26, 2019

Currently the users are not able to publish applications to AppStore if their accounts are with two-factor authentication enabled. The current PR introduces support for publishing iOS apps for accounts with two-factor authentication enabled and shouldn't affect how publish command works for accounts without two-factor authentication. To support it, we need 2 additional options:

  • appleApplicationSpecificPassword
  • appleSessionBase64

The --appleApplicationSpecificPassword option is a password for user's Apple ID that let the user sign in to his account and securely access the information he stores from iTunes Transporter application. This option is mandatory for all accounts with two-factor authentication enabled. To generate an application specific password, follow the steps below:

  1. Go to https://appleid.apple.com/account/manage
  2. Generate a new application specific password
  3. Provide the generated application specific password using --appleApplicationSpecificPassword option.

The --appleSessionBase64 option is a base 64 string that actually is the session cookie. This session will be reused instead of triggering a new login each time NativeScript CLI communicates with Apple's APIs.

This PR introduces a new command tns apple-login as well.

The tns apple-login command uses the provided credentials to obtain Apple session, encode the received session in base64 format and print it on console.

How tns publish works?

NativeScript CLI tries to sign in the user with provided username and password. If the request fails with statusCode 409, NativeScript CLI consider this as an account with two-factor authentication enabled. If the account is with two-factor authentication, CLI prompts the user for the verification code.

Interactive console

  1. If the account is with two-factor authentication and --appleApplicationSpecificPassword option is not provided, NativeScript CLI throws an error as iTunes Transporter will not be able to upload the application.
  2. If the account is with two-factor authentication and --appleApplicationSpecificPassword option is provided:
    • If --appleSessionBase64 is provided, CLI decodes it and tries to sign in the user with provided session.
    • If --appleSessionBase64 is not provided, CLI will sign in the user with provided credentials.
  3. If the account is without two-factor authentication, --appleApplicationSpecificPassword option is not respected.
  4. If the account is without two-factor authentication, --appleSessionBase64 is respected and NativeScript CLI reuse the provided session instead of triggering a new login.

Non-interactive console (CI)

When the console is not interactive, NativeScript CLI doesn't prompt for verification code.

  1. Execute tns apple-login and copy the printed session
  2. Execute tns publish ios <username> <password> --appleApplicationSpecificPassword <app-specific-password> --appleSessionBase64 <session>

The session should be valid for about one month, meaning a new session should be generated every month. Usually the user will only know about it when the build starts failing.

NOTE: An Apple ID session is only valid for a certain region, meaning if the CI system is in a different region than the local machine, the user might run into issues.

Current behavior vs new behavior

tns publish ios tns appstore list
current behavior build the application and fail if provided credentials are invalid show Invalid username and password combination. Used '${username}' as the username.
new behavior validate the credentials and build the application if credentials are valid show { "serviceErrors" : [ { "code" : "-20101", "message" : "Your Apple ID or password was incorrect." } ]}

PR Checklist

What is the current behavior?

What is the new behavior?

Rel to: #4586

@Fatme Fatme added the bug label Jul 26, 2019
@Fatme Fatme added this to the 6.0.3 milestone Jul 26, 2019
@Fatme Fatme self-assigned this Jul 26, 2019
@cla-bot cla-bot bot added the cla: yes label Jul 26, 2019
}

if (result.isTwoFactorAuthenticationEnabled && opts && opts.ensureConsoleIsInteractive && !isInteractive()) {
this.$errors.failWithoutHelp(`Your account has two-factor authentication enabled, but your console is not interactive.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could mention the appleSessionBase64 option here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same and decided that mention tns publish ios --help command and describing --appleSessionBase64 option in help, should be enough.

@Fatme
Copy link
Contributor Author

Fatme commented Jul 30, 2019

test cli-publish

1 similar comment
@Fatme
Copy link
Contributor Author

Fatme commented Jul 30, 2019

test cli-publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants