mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-01 17:10:10 +01:00
feat(examples): Add example for installed-interactive flow.
This PR also depends on the version bump to 0.6.4.
This commit is contained in:
11
examples/drive_example/Cargo.toml
Normal file
11
examples/drive_example/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "drive_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Lewin Bormann <lbo@spheniscida.de>"]
|
||||
|
||||
[dependencies]
|
||||
yup-oauth2 = "0.6.4"
|
||||
google-drive3 = "0.1"
|
||||
url = "= 0.5"
|
||||
hyper = "0.9"
|
||||
serde_json = "0.8"
|
||||
1
examples/drive_example/example_client_secret.json
Normal file
1
examples/drive_example/example_client_secret.json
Normal file
@@ -0,0 +1 @@
|
||||
{"installed":{"client_id":"384278056379-tr5pbot1mil66749n639jo54i4840u77.apps.googleusercontent.com","project_id":"sanguine-rhythm-105020","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"QeQUnhzsiO4t--ZGmj9muUAu","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
|
||||
44
examples/drive_example/src/main.rs
Normal file
44
examples/drive_example/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Just run this program: It will ask you for authorization to view metadata,
|
||||
//! and then display you the contents of your Google Drive root directory.
|
||||
//!
|
||||
//! This example demonstrates how to use the [interactive OAuth 2 flow for installed
|
||||
//! applications.](https://developers.google.com/identity/protocols/OAuth2InstalledApp)
|
||||
//!
|
||||
//! Copyright (c) 2016 Google, Inc. (Lewin Bormann <lbo@spheniscida.de>)
|
||||
|
||||
extern crate hyper;
|
||||
extern crate yup_oauth2;
|
||||
extern crate serde_json;
|
||||
extern crate google_drive3;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use yup_oauth2::{Authenticator, FlowType, ApplicationSecret, DiskTokenStorage,
|
||||
DefaultAuthenticatorDelegate, read_application_secret};
|
||||
use google_drive3::Drive;
|
||||
|
||||
const CLIENT_SECRET_FILE: &'static str = "example_client_secret.json";
|
||||
|
||||
// reads the provided example client secret, the quick and dirty way.
|
||||
fn read_client_secret(file: String) -> ApplicationSecret {
|
||||
read_application_secret(Path::new(&file)).unwrap()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let secret = read_client_secret(CLIENT_SECRET_FILE.to_string());
|
||||
let authenticator = Authenticator::new(&secret,
|
||||
DefaultAuthenticatorDelegate,
|
||||
hyper::Client::new(),
|
||||
DiskTokenStorage::new(&"token_store.json".to_string())
|
||||
.unwrap(),
|
||||
Some(FlowType::InstalledInteractive));
|
||||
let hub = Drive::new(hyper::Client::new(), authenticator);
|
||||
|
||||
let (_resp, list_result) = hub.files().list().q("'root' in parents and trashed = false").doit().unwrap();
|
||||
|
||||
for file in list_result.files.unwrap_or(vec![]) {
|
||||
println!("{} ({})",
|
||||
file.name.unwrap_or(String::new()),
|
||||
file.mime_type.unwrap_or(String::new()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user