Files
inbuxa-migrate/tests/integration/google.rs
T
jcoffey-dev 6ca40a68b5
ci / test (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 3m31s
ci / announce (pull_request) Skipped
guide: Microsoft 365 and Google Workspace as sources
Microsoft 365 reads every mailbox as an Entra app with a client secret
(--app-only); Check signs the app in and names any Graph application
permission it lacks. Google Workspace reads Gmail as a service account
with domain-wide delegation (--google-key); Check asks Google for a token
for the first account.
2026-10-30 14:50:13 -07:00

33 lines
1.2 KiB
Rust

/*
* SPDX-FileCopyrightText: 2026 Coffey Labs LLC <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*/
//! A Google service account's key, made for the test, so no real key is
//! ever in the repository.
/// A service account's JSON key for a new RSA key, with the token
/// endpoint at `token_uri`, and the key's public half.
pub fn service_account_key(token_uri: &str) -> (String, Vec<u8>) {
use aws_lc_rs::encoding::{AsDer, Pkcs8V1Der};
use aws_lc_rs::signature::KeyPair as _;
let pair = aws_lc_rs::rsa::KeyPair::generate(aws_lc_rs::rsa::KeySize::Rsa2048).unwrap();
let der: Pkcs8V1Der<'static> = pair.as_der().unwrap();
let body = encodify::base64::STANDARD.encode(der.as_ref());
let lines: Vec<&str> = body
.as_bytes()
.chunks(64)
.map(|c| std::str::from_utf8(c).unwrap())
.collect();
let pem = format!(
"-----BEGIN PRIVATE KEY-----\n{}\n-----END PRIVATE KEY-----\n",
lines.join("\n")
);
let key = serde_json::json!({
"type": "service_account", "client_email": "[email protected]",
"private_key": pem, "token_uri": token_uri,
});
(key.to_string(), pair.public_key().as_ref().to_vec())
}