1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! An example to unlink Google OAuth credential by session-based interface.
//!
//! ```shell
//! $ cargo run --example unlink_google -- --request-uri <request_uri> --id-token <id_token>
//! ```
use clap::Parser;
use fars::ApiKey;
use fars::Config;
use fars::IdpPostBody;
use fars::OAuthRequestUri;
use fars::ProviderId;
#[derive(Parser)]
struct Arguments {
#[arg(short, long)]
request_uri: String,
#[arg(short, long)]
id_token: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Parse the command line arguments.
let arguments = Arguments::parse();
// Read API key from the environment variable.
let api_key = ApiKey::new(std::env::var("FIREBASE_API_KEY")?);
// Create a config.
let config = Config::new(api_key);
// Get a session by signing in anonymously.
let session = config
.sign_in_anonymously()
.await?;
let session = session
.link_with_oauth_credential(
OAuthRequestUri::new(arguments.request_uri.clone()),
IdpPostBody::Google {
id_token: arguments.id_token.clone(),
},
)
.await?;
// Unlink Google OAuth credential.
let session = session
.unlink_provider(
[ProviderId::Google]
.iter()
.cloned()
.collect(),
)
.await?;
println!(
"Succeeded to unlink Google OAuth credential: {:?}",
session
);
// Delete the anonymous account.
session
.delete_account()
.await?;
Ok(())
}