Forum Discussion
Get OAuth Custom Connector to check for valid token before initiating login flow again
This sounds promising, but unfortunately I can't get it to even recognize that function name Extension.CurrentCredential(). Also, I found that the AccessToken I need is stored in Properties in the current credential, not "Key", but first thing is simply getting that method Extension.CurrentCredential() to work in the first place. This is what I tried:
Hi pbiftw92
Initially I also got the exact same error in Visual Studio Code SDK, but I did some things (?) and eventually it worked with another query that used Extension.CurrentCredential -> https://github.com/microsoft/DataConnectors/blob/master/samples/DataWorldSwagger/DataWorldSwagger.pq
[DataSource.Kind="DataWorldSwagger", Publish="DataWorldSwagger.Publish"]
shared DataWorldSwagger.Contents = () =>
let
credential = Extension.CurrentCredential(),
token = if (credential[AuthenticationKind] = "Key") then credential[Key] else credential[access_token],
headers = [ Authorization = "Bearer " & token ],
navTable = OpenApi.Document(Web.Contents("https://api.data.world/v0/swagger.json"), [ Headers = headers, ManualCredentials = true ])
in
credential; // <---- changed here to see that it works
The things I did I think were:
Update
Set credential
Test connection
I think that error is caused by missing credentials (try to Set credential!).
But when when i try to do Set credential with your code, I get:
As I don't have the URLs setup etc, there are a lot of moving parts that don't allow me to easily debug.
Please mark this as answer if it helped.
- pbiftw923 years agoFrequent Visitor
Yeah unfortunately still getting the same error in spite of trying the steps you outlined.
Here's the updated code, it's the same logic really, but I figured I'd change it to be more like the DataWorld example you shared just in case that was the issue:
[DataSource.Kind="NetsuiteConnector", Publish= "NetsuiteConnector.Publish"] shared NetsuiteConnector.Contents = (url as text, query as text) => let credential = Extension.CurrentCredential(), token = if (credential[AuthenticationKind] = "Key") then credential[Key] else credential[access_token], headers = [ Authorization = "Bearer " & token,#"Prefer" = "transient"], body = Json.FromValue([q = query]), source = Json.Document(Web.Contents(url,[Headers = headers, Content = body])) in credential;And I tried clearing the credentials, setting them again and then running the test connection but it still returns:
"Details": "The name 'Extension.CurrentCredential' wasn't recognized. Make sure it's spelled correctly."This to me looks more like this function was deprecated or somehow I'm not calling it correctly because it doesn't seem to be making it pastcredential = Extension.CurrentCredential() without erroring.- ams13 years ago
Responsive Resident
Hi pbiftw92
My 4th edit of this post 😊: please confirm the OAuth Flow that you have to use and share the link to the documentation:
Is this the relevant link?
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_158074210415.html
I think we're mixing up the Flows and therefore the auth doesn't work and therefore "The name 'Extension.CurrentCredential' wasn't recognized".
Usually when you see client_id and client_secret, that's usually the Client Credentials Flow which is DIFFERENT than Authorization Code Grant flow that you seem to be using
- pbiftw923 years agoFrequent Visitor
No I'm using authorization code flow: https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_158074210415.html
I think I tried client credentials but couldn't get it to work.