Skip to content

Commit

Permalink
Close #455
Browse files Browse the repository at this point in the history
Add `redirect_uri` config option and command line option to specify
a custom redirect_uri for OAuth2.
  • Loading branch information
astrada committed Sep 10, 2019
1 parent 3f11dd3 commit 5801092
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bin/gdfuse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type application_params = {
service_account_user_to_impersonate : string;
log_to : string;
scope : string;
redirect_uri : string;
}

let setup_application params =
Expand Down Expand Up @@ -190,6 +191,10 @@ let setup_application params =
if params.scope = ""
then current_config |. Config.scope
else params.scope in
let redirect_uri =
if params.redirect_uri = ""
then current_config |. Config.redirect_uri
else params.redirect_uri in
let headless = params.headless in
let sqlite3_busy_timeout =
(* Previously default timeout was 500ms that's too low for multi-threading.
Expand All @@ -216,6 +221,7 @@ let setup_application params =
service_account_user_to_impersonate;
log_to;
scope;
redirect_uri;
} in
let config =
if params.docs_mode = "libreoffice" then
Expand Down Expand Up @@ -656,6 +662,7 @@ let () =
let service_account_user_to_impersonate = ref "" in
let log_to = ref "" in
let scope = ref "" in
let redirect_uri = ref "" in
let program = Filename.basename Sys.executable_name in
let usage =
Printf.sprintf
Expand Down Expand Up @@ -762,6 +769,9 @@ let () =
"-scope",
Arg.Set_string scope,
" sets a custom Drive API scope.";
"-redirect_uri",
Arg.Set_string redirect_uri,
" sets a custom Drive API redirect URI.";
]) in
let () =
Arg.parse
Expand Down Expand Up @@ -800,6 +810,7 @@ let () =
!service_account_user_to_impersonate;
log_to = !log_to;
scope = !scope;
redirect_uri = !redirect_uri;
} in
if !mountpoint = "" then begin
setup_application { params with mountpoint = "." };
Expand Down
12 changes: 12 additions & 0 deletions src/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type t = {
service_account_user_to_impersonate : string;
(* Specifies a custom Drive API scope. *)
scope : string;
(* Specifies a custom Drive API redirect URI. *)
redirect_uri : string;
}

let metadata_cache_time = {
Expand Down Expand Up @@ -403,6 +405,10 @@ let scope = {
GapiLens.get = (fun x -> x.scope);
GapiLens.set = (fun v x -> { x with scope = v })
}
let redirect_uri = {
GapiLens.get = (fun x -> x.redirect_uri);
GapiLens.set = (fun v x -> { x with redirect_uri = v })
}

let umask =
let prev_umask = Unix.umask 0 in
Expand Down Expand Up @@ -484,6 +490,7 @@ let default = {
service_account_credentials_path = "";
service_account_user_to_impersonate = "";
scope = "";
redirect_uri = "";
}

let default_debug = {
Expand Down Expand Up @@ -551,6 +558,7 @@ let default_debug = {
service_account_credentials_path = "";
service_account_user_to_impersonate = "";
scope = "";
redirect_uri = "";
}

let of_table table =
Expand Down Expand Up @@ -706,6 +714,9 @@ let of_table table =
scope =
get "scope" Std.identity
default.scope;
redirect_uri =
get "redirect_uri" Std.identity
default.redirect_uri;
}

let to_table data =
Expand Down Expand Up @@ -781,6 +792,7 @@ let to_table data =
add "service_account_user_to_impersonate"
data.service_account_user_to_impersonate;
add "scope" data.scope;
add "redirect_uri" data.redirect_uri;
table

let debug_print out_ch start_time curl info_type info =
Expand Down
5 changes: 4 additions & 1 deletion src/oauth2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ let get_access_token headless browser =
let client_id = config_lens |. Config.client_id in
let client_secret = config_lens |. Config.client_secret in
let verification_code = config_lens |. Config.verification_code in
let redirect_uri = "urn:ietf:wg:oauth:2.0:oob" in
let redirect_uri =
match config_lens |. Config.redirect_uri with
| "" -> "urn:ietf:wg:oauth:2.0:oob"
| uri -> uri in
let scope =
match config_lens |. Config.scope with
| "" -> scope
Expand Down

0 comments on commit 5801092

Please sign in to comment.