Permalink
Browse files

Fix #47: add -headless option

  • Loading branch information...
1 parent 35d9d7b commit 945bcd88f6f731e20a674fc9737e7967b0f562b3 @astrada committed Jan 29, 2014
Showing with 22 additions and 6 deletions.
  1. +14 −3 src/gdfuse.ml
  2. +8 −3 src/oauth2.ml
View
@@ -89,6 +89,7 @@ type application_params = {
client_secret : string;
mountpoint : string;
clear_cache : bool;
+ headless : bool;
}
let setup_application params =
@@ -144,6 +145,7 @@ let setup_application params =
if params.client_secret = ""
then current_config |. Config.client_secret
else params.client_secret in
+ let headless = params.headless in
let config =
{ current_config with
Config.debug = params.debug;
@@ -201,9 +203,13 @@ let setup_application params =
let refresh_token = context |. Context.refresh_token_lens in
if refresh_token = "" then
if client_id = "" || client_secret = "" then
- get_auth_tokens_from_server ()
+ if headless then
+ failwith ("In headless mode, you should specify a client id and a \
+ client secret")
+ else
+ get_auth_tokens_from_server ()
else
- Oauth2.get_access_token ()
+ Oauth2.get_access_token headless
else
Utils.log_message "Refresh token already present.\n%!"
(* END setup *)
@@ -395,6 +401,7 @@ let () =
let client_id = ref "" in
let client_secret = ref "" in
let clear_cache = ref false in
+ let headless = ref false in
let program = Filename.basename Sys.executable_name in
let usage =
Printf.sprintf
@@ -440,6 +447,9 @@ let () =
"-cc",
Arg.Set clear_cache,
" clear cache";
+ "-headless",
+ Arg.Set headless,
+ " enable headless mode. Default is false.";
]) in
let () =
Arg.parse
@@ -464,7 +474,8 @@ let () =
client_id = !client_id;
client_secret = !client_secret;
mountpoint = !mountpoint;
- clear_cache = !clear_cache
+ clear_cache = !clear_cache;
+ headless = !headless;
} in
if !mountpoint = "" then begin
setup_application { params with mountpoint = "." };
View
@@ -49,8 +49,9 @@ let do_request interact =
in
try_request 0
-(* Get access token using the installed apps flow *)
-let get_access_token () =
+(* Get access token using the installed apps flow or print authorization URL
+ * if headleass mode is on *)
+let get_access_token headless =
let context = Context.get_ctx () in
let config_lens = context |. Context.config_lens in
let client_id = config_lens |. Config.client_id in
@@ -64,7 +65,11 @@ let get_access_token () =
~scope
~response_type:"code"
client_id in
- Utils.start_browser url;
+ if headless then begin
+ Printf.printf
+ "Please, open the following URL in a web browser: %s\n%!"
+ url;
+ end else Utils.start_browser url;
Printf.printf "Please enter the verification code: %!";
input_line stdin
else

0 comments on commit 945bcd8

Please sign in to comment.