Forum Discussion
JoeFields
4 years agoFrequent Visitor
Custom Connector failing on refreshing data with multiple calls to get a refresh token
We have a custom connector that is using the PKCE OAuth2 flow based around the provided example here and we are having users report occasional issues where they need to sign in again on Power BI Desk...
AlexZak
4 years agoFrequent Visitor
Hi,
not sure if this will solve your issue but here is my tokenMethode with works.
TokenMethod = (dataSourcePath, grantType, tokenField, tokenFieldValue, optional verifier) =>
let
codeVerifier = if (verifier <> null) then [code_verifier = verifier] else [],
queryString = codeVerifier & [
client_id = Settings(dataSourcePath)[client_id],
grant_type = grantType,
redirect_uri = redirect_uri,
code_verifier = verifier
],
queryWithCode = Record.AddField(queryString, tokenField, tokenFieldValue),
tokenResponse = Web.Contents(baseAuthentificationURL(Settings(dataSourcePath)[tenant]) & "/token", [
Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
Headers = [
#"Content-type" = "application/x-www-form-urlencoded",
#"Accept" = "application/json"
],
ManualStatusHandling = {400}
]),
body = Json.Document(tokenResponse),
result = if (Record.HasFields(body, {"error", "error_description"})) then
error Error.Record(body[error], body[error_description], body)
else
body
in
result;
//Called on token experation
Refresh = (dataSourcePath, refresh_token) => TokenMethod(dataSourcePath, "refresh_token", "refresh_token", refresh_token);- JoeFields4 years agoFrequent Visitor
Does the authentication API you are calling allow the refresh token to be used more than once? Our authentication endpoint allows refresh tokens to be used only once. I have seen some other strategies where the authentication endpoint accepts additional calls using the same refresh token if they occur within a short period. Would be best if the connector code could lock the authentication to one thread.