-
Notifications
You must be signed in to change notification settings - Fork 13
/
get-UserToken.pq
56 lines (56 loc) · 2.31 KB
/
get-UserToken.pq
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
let
output =
(AzureADTenantID as text, AzureApplicationClientSecret as text, AzureApplicationClientID as text, Token as text) =>
let
token_uri =
"https://login.windows.net/"
& AzureADTenantID
& "/oauth2/v2.0/token",
tokenResponse =
Json.Document(
Web.Contents(
token_uri,
[
Content =
Text.ToBinary(
Uri.BuildQueryString(
[
client_id = AzureApplicationClientID,
scope = "https://analysis.windows.net/powerbi/api/.default",
grant_type = "refresh_token",
client_secret = AzureApplicationClientSecret,
refresh_token = Token,
redicrect_uri = "http://localhost:8080"
]
)
),
Headers = [
Accept = "application/json"
],
ManualStatusHandling = {
400
}
]
)
),
token_result =
tokenResponse[token_type]
& " "
& tokenResponse[access_token]
in
token_result,
documentation = [
Documentation.Name = " get-UserToken.pq ",
Documentation.Description = " Get User Token by exchanging the refresh token ",
Documentation.Source = "https://www.jaknapowerbi.cz",
Documentation.Version = " 1.0 ",
Documentation.Author = " Štěpán Rešl "
]
in
Value.ReplaceType(
output,
Value.ReplaceMetadata(
Value.Type(output),
documentation
)
)