26 releases (13 breaking)
0.14.0 | Sep 13, 2023 |
---|---|
0.12.0 | Aug 7, 2023 |
0.11.0 | Jul 16, 2023 |
0.5.3 | Mar 26, 2023 |
149 downloads per month
95KB
2.5K
SLoC
Unofficial bindings for the Proton REST API in Rust
This project aims to implement the Proton REST API in Rust. It is all based on the information available from the go-proton-api and the Proton Bridge repositories.
Disclaimer
This is an UNOFFICIAL project and a work in progress. Use the code in this repository at your own risk. The author of this project will not be held liable if data loss occurs or your account gets blocked.
Build Requirements
- Rust
- Go >= 1.19
This library currently uses one go library to handle the SRP part of the authentication. While there are srp crates available for rust, to avoid issues with the proton servers, we currently use the library that's used internally by go-proton-api.
Safety
This project currently needs unsafe to interact with the go bindings for srp
lib.rs
:
Unofficial Rust bindings for the REST API for Proton. It is all based on the information available from the go-proton-api and the Proton Bridge repositories.
Disclaimer
These are UNOFFICIAL bindings, use at your own risk. The author will not be held liable if you experience data loss or your account gets blocked.
Getting Started
Login into a new session async:
use proton_api_rs::{http, Session, SessionType, http::Sequence};
use proton_api_rs::domain::SecretString;
async fn example<T:http::ClientAsync>() {
let client = http::ClientBuilder::new()
.user_agent("MyUserAgent/0.0.0")
.base_url("server_url")
.app_version("MyApp@0.1.1")
.build::<T>().unwrap();
let session = match Session::login(&"my_address@proton.me", &SecretString::new("my_proton_password".into()), None).do_async(&client).await.unwrap(){
// Session is authenticated, no 2FA verifications necessary.
SessionType::Authenticated(c) => c,
// Session needs 2FA TOTP auth.
SessionType::AwaitingTotp(t) => {
t.submit_totp("000000").do_async(&client).await.unwrap()
}
};
// session is now authenticated and can access the rest of the API.
// ...
session.logout().do_async(&client).await.unwrap();
}
Login into a new session sync:
use proton_api_rs::{Session, http, SessionType, http::Sequence};
use proton_api_rs::domain::SecretString;
fn example<T:http::ClientSync>() {
let client = http::ClientBuilder::new()
.user_agent("MyUserAgent/0.0.0")
.base_url("server_url")
.app_version("MyApp@0.1.1")
.build::<T>().unwrap();
let session = match Session::login("my_address@proton.me", &SecretString::new("my_proton_password".into()), None).do_sync(&client).unwrap(){
// Session is authenticated, no 2FA verifications necessary.
SessionType::Authenticated(c) => c,
// Session needs 2FA TOTP auth.
SessionType::AwaitingTotp(t) => {
t.submit_totp("000000").do_sync(&client).unwrap()
}
};
// session is now authenticated and can access the rest of the API.
// ...
session.logout().do_sync(&client).unwrap();
}
Login using a previous sessions token.
use proton_api_rs::{http, Session, SessionType, http::Sequence};
use proton_api_rs::domain::UserUid;
async fn example<T:http::ClientAsync>() {
let user_uid = "user_uid".into();
let user_refresh_token = "token";
let client = http::ClientBuilder::new()
.user_agent("MyUserAgent/0.0.0")
.base_url("server_url")
.app_version("MyApp@0.1.1")
.build::<T>().unwrap();
let session = Session::refresh(&user_uid, &user_refresh_token).do_async(&client).await.unwrap();
// session is now authenticated and can access the rest of the API.
// ...
session.logout().do_async(&client).await.unwrap();
}
Dependencies
~2–17MB
~262K SLoC