Skip to content

Commit 2f8881c

Browse files
feat: add team_id option for apple notarization (#7775)
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 995ffc6 commit 2f8881c

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

.changes/bundler-team-id.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": minor:enhance
3+
---
4+
5+
Read the `APPLE_TEAM_ID` environment variable for macOS notarization arguments.

tooling/bundler/src/bundle/macos/sign.rs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ pub fn notarize(
300300
Err(anyhow::anyhow!("{log_message}").into())
301301
}
302302
} else {
303-
return Err(
304-
anyhow::anyhow!("failed to parse notarytool output as JSON: `{output_str}`").into(),
305-
);
303+
Err(anyhow::anyhow!("failed to parse notarytool output as JSON: `{output_str}`").into())
306304
}
307305
}
308306

@@ -327,13 +325,14 @@ fn staple_app(mut app_bundle_path: PathBuf) -> crate::Result<()> {
327325

328326
pub enum NotarizeAuth {
329327
AppleId {
330-
apple_id: String,
331-
password: String,
328+
apple_id: OsString,
329+
password: OsString,
330+
team_id: Option<OsString>,
332331
},
333332
ApiKey {
334-
key: String,
333+
key: OsString,
335334
key_path: PathBuf,
336-
issuer: String,
335+
issuer: OsString,
337336
},
338337
}
339338

@@ -344,11 +343,21 @@ pub trait NotarytoolCmdExt {
344343
impl NotarytoolCmdExt for Command {
345344
fn notarytool_args(&mut self, auth: &NotarizeAuth) -> &mut Self {
346345
match auth {
347-
NotarizeAuth::AppleId { apple_id, password } => self
348-
.arg("--apple-id")
349-
.arg(apple_id)
350-
.arg("--password")
351-
.arg(password),
346+
NotarizeAuth::AppleId {
347+
apple_id,
348+
password,
349+
team_id,
350+
} => {
351+
self
352+
.arg("--username")
353+
.arg(apple_id)
354+
.arg("--password")
355+
.arg(password);
356+
if let Some(team_id) = team_id {
357+
self.arg("--team-id").arg(team_id);
358+
}
359+
self
360+
}
352361
NotarizeAuth::ApiKey {
353362
key,
354363
key_path,
@@ -365,30 +374,25 @@ impl NotarytoolCmdExt for Command {
365374
}
366375

367376
pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
368-
match (var_os("APPLE_ID"), var_os("APPLE_PASSWORD")) {
369-
(Some(apple_id), Some(apple_password)) => {
370-
let apple_id = apple_id
371-
.to_str()
372-
.expect("failed to convert APPLE_ID to string")
373-
.to_string();
374-
let password = apple_password
375-
.to_str()
376-
.expect("failed to convert APPLE_PASSWORD to string")
377-
.to_string();
378-
Ok(NotarizeAuth::AppleId { apple_id, password })
379-
}
377+
match (
378+
var_os("APPLE_ID"),
379+
var_os("APPLE_PASSWORD"),
380+
var_os("APPLE_TEAM_ID"),
381+
) {
382+
(Some(apple_id), Some(password), team_id) => Ok(NotarizeAuth::AppleId {
383+
apple_id,
384+
password,
385+
team_id,
386+
}),
380387
_ => {
381388
match (var_os("APPLE_API_KEY"), var_os("APPLE_API_ISSUER"), var("APPLE_API_KEY_PATH")) {
382-
(Some(api_key), Some(api_issuer), Ok(key_path)) => {
383-
let key = api_key.to_str().expect("failed to convert APPLE_API_KEY to string").to_string();
384-
let issuer = api_issuer.to_str().expect("failed to convert APPLE_API_ISSUER to string").to_string();
389+
(Some(key), Some(issuer), Ok(key_path)) => {
385390
Ok(NotarizeAuth::ApiKey { key, key_path: key_path.into(), issuer })
386391
},
387-
(Some(api_key), Some(api_issuer), Err(_)) => {
388-
let key = api_key.to_str().expect("failed to convert APPLE_API_KEY to string").to_string();
389-
let issuer = api_issuer.to_str().expect("failed to convert APPLE_API_ISSUER to string").to_string();
390-
391-
let api_key_file_name = format!("AuthKey_{key}.p8");
392+
(Some(key), Some(issuer), Err(_)) => {
393+
let mut api_key_file_name = OsString::from("AuthKey_");
394+
api_key_file_name.push(&key);
395+
api_key_file_name.push(".p8");
392396
let mut key_path = None;
393397

394398
let mut search_paths = vec!["./private_keys".into()];
@@ -408,7 +412,7 @@ pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
408412
if let Some(key_path) = key_path {
409413
Ok(NotarizeAuth::ApiKey { key, key_path, issuer })
410414
} else {
411-
Err(anyhow::anyhow!("could not find API key file. Please set the APPLE_API_KEY_PATH environment variables to the path to the {api_key_file_name} file").into())
415+
Err(anyhow::anyhow!("could not find API key file. Please set the APPLE_API_KEY_PATH environment variables to the path to the {api_key_file_name:?} file").into())
412416
}
413417
}
414418
_ => Err(anyhow::anyhow!("no APPLE_ID & APPLE_PASSWORD or APPLE_API_KEY & APPLE_API_ISSUER & APPLE_API_KEY_PATH environment variables found").into())
@@ -417,7 +421,7 @@ pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
417421
}
418422
}
419423

420-
fn find_api_key(folder: PathBuf, file_name: &str) -> Option<PathBuf> {
424+
fn find_api_key(folder: PathBuf, file_name: &OsString) -> Option<PathBuf> {
421425
let path = folder.join(file_name);
422426
if path.exists() {
423427
Some(path)

tooling/cli/ENVIRONMENT_VARIABLES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These environment variables are inputs to the CLI which may have an equivalent C
2525
- `APPLE_CERTIFICATE_PASSWORD` — The password you used to export the certificate.
2626
- `APPLE_ID` — The Apple ID used to notarize the application. If this environment variable is provided, `APPLE_PASSWORD` must also be set. Alternatively, `APPLE_API_KEY` and `APPLE_API_ISSUER` can be used to authenticate.
2727
- `APPLE_PASSWORD` — The Apple password used to authenticate for application notarization. Required if `APPLE_ID` is specified. An app-specific password can be used. Alternatively to entering the password in plaintext, it may also be specified using a '@keychain:' or '@env:' prefix followed by a keychain password item name or environment variable name.
28+
- `APPLE_TEAM_ID`: Developer team ID. If your Apple ID only belongs to one team then you don’t need to supply a Team ID. However, it’s best practice to include it regardless. That way, joining another team at some point in the future won’t break your notarization workflow. To find your Team ID, go to the [Account](https://developer.apple.com/account) page on the Apple Developer website.
2829
- `APPLE_API_KEY` — Alternative to `APPLE_ID` and `APPLE_PASSWORD` for notarization authentication using JWT.
2930
- See [creating API keys](https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api) for more information.
3031
- `APPLE_API_ISSUER` — Issuer ID. Required if `APPLE_API_KEY` is specified.

0 commit comments

Comments
 (0)