Forum Discussion
Get OAuth Custom Connector to check for valid token before initiating login flow again
Hi pbiftw92
If you look at https://learn.microsoft.com/en-us/power-query/handling-authentication#accessing-the-current-credentials, you'll see that "M data source functions that have been enabled for extensibility will automatically inherit your extension's credential scope" -> meaning that your "NetsuiteConnector.Contents" that uses Web.Contents should automatically inherit the credentials... and you're saying it doesn't automatically inherit the credentials.
Not sure why 😊, but as a quick workarround (mentioned in the above link), you can try and access the credentials record using Extension.CurrentCredential(), extract the_key_you_need_from_here and add it to the the_header_field_you_need_for_authorization:
[DataSource.Kind="NetsuiteConnector", Publish= "NetsuiteConnector.Publish"]
shared NetsuiteConnector.Contents = (url as text, query as text) =>
let
apiKey = Extension.CurrentCredential()[the_key_you_need_from_here]
headers = [
#"Prefer" = "transient",
"the_header_field_you_need_for_authorization" = apiKey
],
body = Json.FromValue([q = query]),
source = Json.Document(Web.Contents(url,[Headers = headers, Content = body]))
in
source;
Maybe you can also look at: https://learn.microsoft.com/en-us/power-query/handling-authentication#data-source-paths
Please mark this as answer if it helped.