带有DMTS_InvalidEncryptionAlgorithmError

时间:2019-07-09 23:48:08

标签: powerbi powerbi-datasource

我正在尝试使用 Microsoft Power BI API 在网关https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource创建新数据源。为了测试,我尝试使用基本身份验证创建到 Azure Sql数据库的连接。我可以使用Power BI在线GUI毫无问题地添加数据源,但是,每当我尝试使用API​​时,都会收到400-DMTS_InvalidEncryptionAlgorithmError。

主体中的关键字段为 encryptionAlgorithm ,但正如API文档中所述,对于云数据源,该字段应为“无”。

我也尝试过使用“ RSA-OAEP”,但这给了我400-DM_GWPipeline_UnknownError。

我目前正在与Postman合作,但我也尝试使用NodeJS复制相同的请求,并获得相同的结果。

任何有关解决方案的提示都会很有帮助。

POST https://api.powerbi.com/v1.0/myorg/gateways/00000000-0000-0000-0000-000000000000/datasources

标题

content-type: application/json,
Autorization: Bearer token

身体

{
"datasourceType": "Sql",
"connectionDetails": "{\"server\":\"servername.database.windows.net\",\"database\":\"dbname\"}",
"credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"myusername\"},{\"name\":\"password\", \"value\":\"mypwd\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
},
"datasourceName": "new-datasource-name"
}

使用“无”时的错误消息-HTTP 400

{
"error": {
    "code": "DMTS_InvalidEncryptionAlgorithmError",
    "pbi.error": {
        "code": "DMTS_InvalidEncryptionAlgorithmError",
        "parameters": {},
        "details": [],
        "exceptionCulprit": 1
    }
}
}

使用“ RSA-OAEP”时出现错误消息-HTTP 400

{
"error": {
    "code": "DM_GWPipeline_UnknownError",
    "pbi.error": {
        "code": "DM_GWPipeline_UnknownError",
        "parameters": {},
        "details": [
            {
                "code": "DM_ErrorDetailNameCode_UnderlyingErrorMessage",
                "detail": {
                    "type": 1,
                    "value": "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. "
                }
            },
            {
                "code": "DM_ErrorDetailNameCode_UnderlyingHResult",
                "detail": {
                    "type": 1,
                    "value": "-2146233033"
                }
            }
        ]
    }
}
}

2 个答案:

答案 0 :(得分:1)

我认为您在加载时需要对凭据进行加密-在文档中没有明确说明。您不能只上传免费文本。

对安全性很有道理!

https://docs.microsoft.com/en-us/power-bi/developer/encrypt-credentials

答案 1 :(得分:0)

仅出于完整性考虑,以下是可用于加密凭据的节点代码。使用库node-rsa

const nodeRSA  = require("node-rsa");

const credentials = '{\"credentialData\":[{\"name\":\"username\", \"value\":\"myusername\"},{\"name\":\"password\", \"value\":\"mypwd\"}]}';

const exponentString = 'AQAB';
const modulusString = 'rasdfsafsdfsadfsdafsdferasdasgfasgsfgdfgsdfgdsfgrgsrareasgasgasfasfasdfasdfsadfsadfgsadfsadfasfasdfsadfsdafasdfrgrhe4t345tge5g54g5gegdrg5tg45efgdfg5t=';

const key = new nodeRSA();

const modulus = new Buffer(modulusString, 'base64');
const exponent = new Buffer(exponentString, 'base64');

const pubKey = key.importKey({ n: modulus, e: exponent }, 'components-public');

const encrypted = pubKey.encrypt(credentials, 'base64');

console.log(encrypted)