Power BI-从基本身份验证获取JWT令牌

时间:2020-08-10 17:27:56

标签: api rest authentication jwt powerbi

我正在通过Postman的REST API获取令牌,请求如下:

URL:
https://www.wathever.com/fmi/data/v1/databases/sessions

Headers:
Authorization: Basic (binary generated by Postman)==
Postman-Token: <calculated when request is sent>
Content-Length: 0
Host: <calculated when request is sent>
User-Agent: PostmanRuntime/7.26.2
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/json

我成功获得了令牌:

{
    "response": {
        "token": "fff***********************3ecfc7f01a*****716"
    },
    "messages": [
        {
            "code": "0",
            "message": "OK"
        }
    ]
}

现在,我正在尝试使用以下代码(凭据匿名)通过Power BI获取令牌:

let server = "https://www.wathever.com/fmi/data/v1/databases/",
    database = "thedatabase",
    username = "username",
    psw = "apassword",
    url = server & database & "/sessions",
    bytes = Text.ToBinary(username & ":" & psw),
    encoded = Binary.ToText(bytes, BinaryEncoding.Base64),
    body = "",
    data = Json.Document(Web.Contents(url,
    [
        Headers = [
            #"Authorization"=("base64-encoded " &encoded),
            #"Content-Type"="application/json"
        ]
    ]))
in
    data

但是我收到以下错误消息:

我们无法使用提供的凭据进行身份验证。请尝试 再次。

我也尝试使用凭据基础进行连接,而没有传递标题,但是我收到以下消息:

DataSource.Error:Web.Contents无法从中获取内容 'https://www.wathever.com/fmi/data/v1/databases/sessions'(405): 不允许的方法

对我想念的东西有任何想法吗?

谢谢!

0 个答案:

没有答案