Forum Discussion
OAuth for Power BI Custom Connector issues
Hello all!
I am hoping that someone has a solution or guidance. The documentation for using OAuth in custom connectors for Power BI leaves a lot to be desired.....
Here is the experiene I am trying to create when setting up the connector in Power BI Desktop. I am new to M Language, so I'm having trouble understanding the standard OAuth flow.
- When setting up the connector, the user enters the base url for the data source, a client ID, and client Secret.
- These variables get passed into the OAuth flow for the connector to retrieve an API Token that can be appended to the header of REST API requests. The token is generated once, and reused for each 'page' of data retrieved with the request (my data source returns a max of 50 records with each request, so pagination will be necessary).
Where I am having an issue is that my data source doesn't follow the prescribed path for OAuth in Power BI connectors - the API Token is generated with a POST to {client_id}:{client_secret}@{baseurl}/rest/oath/token and a body with grant_type = client_credentials. This API call returns a JSON with access_token that can then be stored as a variable applied in the header.
Here is a screenshot from Postman of a successful token request:
Basically, it does not seem like I need the StartLogin section, or I'm not sure what to put in that section since there is no authorization URL, just a token request URL.
Any guidance on this would be GREATLY appreciated.
- Anonymous2 years ago
Hi pgarman ,
Based on my understanding and research, your approach of generating a Bearer Token via OAuth to access certain APIs seems to support an “anonymous” connection mode. However, it’s important to note that this Bearer Token is dynamic and typically has a validity period of one hour. If you wish to implement a method for dynamically generating the Bearer Token, you’ll need to use M query to obtain the latest Bearer Token in real-time during each data refresh. You can refer to the following links to determine if they provide any helpful insights:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- pgarmanNew Member
I have set up a connector using Anonymous rather than OAuth, but it is not reliable - about 25% of the initial connections or data refreshes return an error from Power BI Desktop that the credentials could not be authenticated.
I suspect this might be due to the connector requesting a new token with each 'page' of records, but it's hard to see what is actually happening since Power BI does not give the actual error message from the data source being queried.
- AnonymousNot applicable
Hi pgarman ,
Based on my understanding and research, your approach of generating a Bearer Token via OAuth to access certain APIs seems to support an “anonymous” connection mode. However, it’s important to note that this Bearer Token is dynamic and typically has a validity period of one hour. If you wish to implement a method for dynamically generating the Bearer Token, you’ll need to use M query to obtain the latest Bearer Token in real-time during each data refresh. You can refer to the following links to determine if they provide any helpful insights:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.