Crates.io | apple_auth |
lib.rs | apple_auth |
version | 0.1.1 |
source | src |
created_at | 2024-01-19 17:02:28.584615 |
updated_at | 2024-01-24 21:42:53.753689 |
description | A library for authenticating with Apple's Sign In service. |
homepage | |
repository | https://github.com/conner-replogle/apple_auth |
max_upload_size | |
id | 1105496 |
size | 9,084 |
A port of the js library apple_auth into rust.
Used for sign in with apple.
Api is the same as the JS version besides some diffrences with the config and private key. Any contributions are welcome
//check the apple-auth js docs for getting this
let config = AppleConfig{
client_id: "".to_string(),
team_id: "".to_string(),
redirect_uri: "".to_string(),
key_id: "".to_string(),
scope: "email".to_string(),
};
let key = PrivateKeyLocation::Text("-----BEGIN PRIVATE KEY-----
priv_key data
-----END PRIVATE KEY-----".to_string());
let apple_auth = apple_auth::apple_auth::AppleAuth::new(config,key);
let token = apple_auth.access_token(code).await.unwrap();
let mut no_validation = Validation::new(Algorithm::RS256);
no_validation.insecure_disable_signature_validation();
no_validation.set_audience(&[apple_auth.config.client_id.as_str()]);
let dummy_decoding_key = DecodingKey::from_rsa_components("", "").unwrap();
let tokenID:TokenData<IdToken> = jsonwebtoken::decode(&token.id_token,&dummy_decoding_key,&no_validation).unwrap();
let user_id = tokenID.claims.sub;
let email = tokenID.claims.email;
if let (Some(first_name),Some(last_name),Some(email)) = (first_name,last_name,email){
//Create user
println!("Create user: {} {} {}",first_name,last_name,email);
}