-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_scope.ml
67 lines (54 loc) · 1.84 KB
/
google_scope.ml
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(*
Non exhaustive list of scopes defined by Google APIs.
*)
type scope = [
| `Profile
| `Email_address
| `Calendar
| `Contacts
| `Gmail
| `Drive
(* Requests *full* access to a user's Google Drive. This is fine for
internal use (ie [email protected]) but too broad for clients. *)
]
type t = scope list
(*
See https://developers.google.com/+/api/oauth#scopes
for details on the profile and email scopes.
*)
let parse_scope = function
| "profile"
(* View your basic profile info *)
| "https://www.googleapis.com/auth/userinfo.profile"
(* synonym for "profile" *)
| "https://www.googleapis.com/auth/plus.login"
(* Know your basic profile info and list of people in your circles. *)
-> Some `Profile
| "email"
(* View your email address *)
| "https://www.googleapis.com/auth/userinfo.email"
(* synonym for "email" *)
| "https://www.googleapis.com/auth/plus.profile.emails.read"
(* get email address + other things *)
-> Some `Email_address
| "https://www.googleapis.com/auth/calendar" -> Some `Calendar
| "https://mail.google.com/" -> Some `Gmail
| "https://www.googleapis.com/auth/drive" -> Some `Drive
| "https://www.googleapis.com/auth/contacts.readonly" -> Some `Contacts
| _ -> None
let string_of_scope : scope -> string = function
| `Profile -> "profile"
| `Email_address -> "email"
| `Calendar -> "https://www.googleapis.com/auth/calendar"
| `Gmail -> "https://mail.google.com/"
| `Drive -> "https://www.googleapis.com/auth/drive"
| `Contacts -> "https://www.googleapis.com/auth/contacts.readonly"
let split =
let rex = lazy (Pcre.regexp " +") in
fun s ->
let l = Pcre.split ~rex: (Lazy.force rex) s in
BatList.filter_map parse_scope l
let concat l =
String.concat " " (BatList.map string_of_scope l)
let wrap s = split s
let unwrap l = concat l