Skip to content

Commit 63a7c87

Browse files
authored
Require auth key file for Apple Sign-In (#4393)
2 parents 117590c + 41b460b commit 63a7c87

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

crates/cli/src/sync.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,18 @@ pub async fn config_sync(
189189
let encrypted_client_secret =
190190
if let Some(client_secret) = provider.client_secret.as_deref() {
191191
Some(encrypter.encrypt_to_string(client_secret.as_bytes())?)
192-
} else if let Some(siwa) = provider.sign_in_with_apple.as_ref() {
193-
// For SIWA, we JSON-encode the config and encrypt it, reusing the client_secret
194-
// field in the database
195-
let encoded = serde_json::to_vec(siwa)?;
192+
} else if let Some(mut siwa) = provider.sign_in_with_apple.clone() {
193+
// if private key file is defined and not private key (raw), we populate the
194+
// private key to hold the content of the private key file.
195+
// private key (raw) takes precedence so both can be defined
196+
// without issues
197+
if siwa.private_key.is_none() {
198+
if let Some(private_key_file) = siwa.private_key_file.take() {
199+
let key = tokio::fs::read_to_string(private_key_file).await?;
200+
siwa.private_key = Some(key);
201+
}
202+
}
203+
let encoded = serde_json::to_vec(&siwa)?;
196204
Some(encrypter.encrypt_to_string(&encoded)?)
197205
} else {
198206
None

crates/config/src/sections/upstream_oauth2.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use std::collections::BTreeMap;
88

9+
use camino::Utf8PathBuf;
910
use mas_iana::jose::JsonWebSignatureAlg;
1011
use schemars::JsonSchema;
1112
use serde::{Deserialize, Serialize, de::Error};
@@ -383,8 +384,14 @@ fn signed_response_alg_default() -> JsonWebSignatureAlg {
383384

384385
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
385386
pub struct SignInWithApple {
387+
/// The private key file used to sign the `id_token`
388+
#[serde(skip_serializing_if = "Option::is_none")]
389+
#[schemars(with = "Option<String>")]
390+
pub private_key_file: Option<Utf8PathBuf>,
391+
386392
/// The private key used to sign the `id_token`
387-
pub private_key: String,
393+
#[serde(skip_serializing_if = "Option::is_none")]
394+
pub private_key: Option<String>,
388395

389396
/// The Team ID of the Apple Developer Portal
390397
pub team_id: String,

docs/config.schema.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -2158,10 +2158,13 @@
21582158
"type": "object",
21592159
"required": [
21602160
"key_id",
2161-
"private_key",
21622161
"team_id"
21632162
],
21642163
"properties": {
2164+
"private_key_file": {
2165+
"description": "The private key file used to sign the `id_token`",
2166+
"type": "string"
2167+
},
21652168
"private_key": {
21662169
"description": "The private key used to sign the `id_token`",
21672170
"type": "string"

docs/setup/sso.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,23 @@ Sign-in with Apple uses special non-standard for authenticating clients, which r
8484
```yaml
8585
upstream_oauth2:
8686
providers:
87-
- client_id: 01JAYS74TCG3BTWKADN5Q4518C
88-
client_name: "<Service ID>" # TO BE FILLED
87+
- id: 01JAYS74TCG3BTWKADN5Q4518C
88+
issuer: "https://appleid.apple.com"
89+
human_name: "Apple"
90+
brand_name: "apple"
91+
client_id: "<Service ID>" # TO BE FILLED
8992
scope: "openid name email"
9093
response_mode: "form_post"
91-
9294
token_endpoint_auth_method: "sign_in_with_apple"
9395
sign_in_with_apple:
94-
private_key: |
95-
# Content of the PEM-encoded private key file, TO BE FILLED
96+
97+
# Only one of the below should be filled for the private key
98+
private_key_file: "<Location of the PEM-encoded private key file>" # TO BE FILLED
99+
private_key: | # TO BE FILLED
100+
# <Contents of the private key>
101+
96102
team_id: "<Team ID>" # TO BE FILLED
97103
key_id: "<Key ID>" # TO BE FILLED
98-
99104
claims_imports:
100105
localpart:
101106
action: ignore
@@ -549,4 +554,4 @@ To use a Rauthy-supported [Ephemeral Client](https://sebadob.github.io/rauthy/wo
549554
"access_token_signed_response_alg": "RS256",
550555
"id_token_signed_response_alg": "RS256"
551556
}
552-
```
557+
```

0 commit comments

Comments
 (0)