File: auth.rs

package info (click to toggle)
rust-launchpadlib 0.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,576 kB
  • sloc: makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
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
use launchpadlib::auth::authorize_token_url;
use launchpadlib::blocking::client::auth::{exchange_request_token, get_request_token};
use launchpadlib::blocking::Client;

fn main() {
    // Step 0: Pick a consumer key
    let consumer_key = "your_consumer_key";

    let instance = "launchpad.net";

    // Step 1: Get a request token
    let req_token = get_request_token(instance, consumer_key).unwrap();

    // Step 2: Get the user to authorize the request token
    let auth_url = authorize_token_url(instance, req_token.0.as_str(), None).unwrap();

    println!("Please authorize the request token at {}", auth_url);
    println!("Once done, press enter to continue...");
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();

    // Step 3: Exchange the request token for an access token
    let access_token = exchange_request_token(
        instance,
        consumer_key,
        None,
        req_token.0.as_str(),
        Some(req_token.1.as_str()),
    )
    .unwrap();

    let client = Client::from_tokens(
        consumer_key,
        None,
        access_token.0.as_str(),
        access_token.1.as_str(),
    );

    let root = launchpadlib::blocking::v1_0::service_root(&client).unwrap();
    let person = root.me().unwrap().get(&client).unwrap();
    println!("{:?}", person);
}