Forum Discussion
Custom Connector OAuth2 Scheduled Refresh Issue
Anonymous Thanks for the reponse, the issue I'm experiencing is actually after I get authenticated and attempt to refresh the data set.
However!!
You did help me identify a bug in my token refresh, so thank you very much. I was doing something very similar in regards to switching the parameter name depending on whether it was an access token request or token refresh. Turns out the documentation was lacking and I had the wrong name for the refresh token tokenField parameter.
Refresh = (resourceUrl, refresh_token) => TokenMethod(resourceUrl, "refresh_token", "refresh_token", refresh_token);
TokenMethod = (resourceUrl, grantType, tokenField, code) =>
let
queryString = [
grant_type = grantType,
redirect_uri = redirect_uri,
client_id = GetEnvironmentVariable(resourceUrl, "client_id"),
client_secret = GetEnvironmentVariable(resourceUrl, "client_secret")
],
queryWithCode = Record.AddField(queryString, tokenField, code),
base_url = GetAuthUrl(resourceUrl),
tokenResponse = Web.Contents(base_url & "connect/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 if (Record.HasFields(body, {"error"})) then
error Error.Record(body[error], "Failed to login.", body)
else
body
in
result;
Cheers!
Glad I could help somehow!
Cheers.