apple_auth

Crates.ioapple_auth
lib.rsapple_auth
version0.1.1
sourcesrc
created_at2024-01-19 17:02:28.584615
updated_at2024-01-24 21:42:53.753689
descriptionA library for authenticating with Apple's Sign In service.
homepage
repositoryhttps://github.com/conner-replogle/apple_auth
max_upload_size
id1105496
size9,084
(conner-replogle)

documentation

README

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

Setup

    //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);
    }

Commit count: 0

cargo fmt