From 515e128cac42569b5009108fa0eb008b412631ca Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 27 Feb 2015 17:53:01 +0100 Subject: [PATCH] feat(auth): open verification url automatically --- Cargo.toml | 2 +- examples/auth.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa7ca2720..22fb3ad9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ rustc-serialize = "*" [dev-dependencies] getopts = "*" yup-hyper-mock = "*" - +open = "*" diff --git a/examples/auth.rs b/examples/auth.rs index b1f7cb671..5a4006740 100644 --- a/examples/auth.rs +++ b/examples/auth.rs @@ -1,13 +1,17 @@ -#![feature(env, collections)] +#![feature(env, collections, old_io, std_misc)] extern crate "yup-oauth2" as oauth2; extern crate "yup-hyper-mock" as mock; extern crate hyper; extern crate chrono; extern crate getopts; +extern crate open; use chrono::{Local}; use getopts::{HasArg,Options,Occur,Fail}; use std::env; +use std::time::Duration; +use std::old_io::timer::sleep; + fn usage(program: &str, opts: &Options, err: Option) { if err.is_some() { @@ -55,6 +59,11 @@ fn main() { You have time until {} to do that. Do not terminate the program until you deny or grant access !", pi.user_code, pi.verification_url, pi.expires_at.with_timezone(&Local)); + let delay = Duration::seconds(5); + println!("Browser opens automatically in {} seconds", delay); + sleep(delay); + open::that(&pi.verification_url).ok(); + println!("DONE - waiting for authorization ..."); } }