#apple #oauth #apple-authentication #apple-sign-in

apple_auth

用于通过Apple的登录服务进行身份验证的库

2个版本

0.1.1 2024年1月24日
0.1.0 2024年1月19日

398 in 身份验证

MIT 许可证

10KB
135

将js库apple_auth移植到Rust。

用于Apple登录。

API与JS版本相同,除了与配置和私钥的一些差异。欢迎任何贡献

设置

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

依赖关系

~7–21MB
~336K SLoC