This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.fsx
58 lines (50 loc) · 1.95 KB
/
subscribe.fsx
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
#I "./packages/FSharp.Data/lib/portable-net45+netcore45/"
#r "FSharp.Data.dll"
#r "FSharp.Data.DesignTime.dll"
open System
open FSharp.Data
open FSharp.Data.HttpRequestHeaders
// Your values here ------------------------------------------------------------
let tenant = ""
let tenantId = ""
let clientId = ""
let clientSecret = ""
let webHookUrl = ""
let authId = clientId
// -----------------------------------------------------------------------------
let fetchAuthToken =
let url = "https://login.microsoftonline.com/" + tenant + "/oauth2/token"
let json =
Http.RequestString(url,
headers=[Accept "application/json"],
body=FormValues ["grant_type", "client_credentials";
"client_id", clientId;
"client_secret", clientSecret;
"resource", "https://manage.office.com"])
let res = JsonValue.Parse json
res.GetProperty("access_token").AsString()
printfn "%s" "Begin subscription..."
let token = "Bearer " + fetchAuthToken
let subscribe contentType =
let url = "https://manage.office.com/api/v1.0/" + tenantId +
"/activity/feed/subscriptions/start"
let reqbody =
"{'webhook': {" +
"'address': '" + webHookUrl + "', " +
"'authId': '" + authId + "', " +
"'expiration': ''" +
"}}"
printfn "%s %s %s" "Sending Subscription Request for" contentType "..."
let resp =
Http.Request(url,
headers = [Accept "application/json";
Authorization token;
ContentType HttpContentTypes.Json],
query = ["contentType", contentType],
body = TextRequest reqbody)
printfn "%s %A" "Response Status:" resp.StatusCode
subscribe "Audit.SharePoint"
subscribe "Audit.Exchange"
subscribe "Audit.AzureActiveDirectory"
subscribe "Audit.General"
printfn "%s" "Subscription completed."