DataConnectors
DataConnectors copied to clipboard
Avoid Authorization headers when using Credential Type UsernamePassword
I use UsernamePassword to get information needed to build the uri string in a custom connector. The Password bit is unique for the file I want to retrieve when combined with the uri part in the Username bit.
[DataSource.Kind="MyConnector", Publish="MyConnector.Publish"]
shared MyConnector.Contents = () as table =>
let
baseUri = try Extension.CurrentCredential()[Username] otherwise "https://MyEndpoint",
token = try Extension.CurrentCredential()[Password] otherwise "MySecretToken"
in
GetMyData(baseUri, token);
MyConnector = [
Authentication = [
UsernamePassword = [
UsernameLabel = "Url",
PasswordLabel = "SecretToken"
],
Implicit = []
],
Label = "Uri token access"
];
GetMyData = (uri, token) =>
let
_uri = uri & '?' & token
source = Json.Document(Web.Contents(_uri)),
value = source[value],
ConvertedToTable = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
fieldNames = Record.FieldNames(ConvertedToTable{0}[Column1]),
final = Table.ExpandRecordColumn(ConvertedToTable, "Column1", fieldNames, fieldNames)
in
final;
Running the connector with Anonymous the call works. When selecting UsernamePassword authentication in my connector and filling in the exact same values as used in Anonymous, I get this error:
Authentication is not given in the correct format. Check the value of Authorization header
I assume this is caused by the built-in functionality, but I would like an option, where I can make my Web.Contents(_uri) call whithout an altered authentication header.
I have tried different ways to "heal" the header, to get my call through. Including;
Headers = []
and
Web.Contents(_uri), [ExcludedFromCacheKey = {"Authorization"}]
I might be going about this in the wrong way: What I really want to do is to give the enduser og my connector an option to fill in two variables that the connector then uses to build a Web.Contents() call that runs anonymous. How can this be achieved?