3-Legged OAuth2 Authorization code flow for Excel? - excel

This might be a long shot, but I'm using the MYOB Business API which has the same OAuth authorization flow as the LinkedIn API - 3-legged - and am planning on making queries to it through Excel, most likely power query.
The big issue with this is obviously dealing with the sending and receiving of the code=, access_token and refresh_token. Most of the searches I've done relating to using Power Query and OAuth seem to only deal with username and password OAuth and not the authorization flow, shown here https://developer.indeed.com/docs/authorization/3-legged-oauth.
I'm curious if there is Power Query M Language code out there that I haven't come across or if I have to go the route of building an OData Feed (or another method?) on top of the API so that it can be queried in Excel?
Any help or further direction would be appreciated.
I should also note they have a website containing their Postman collection using different languages here; https://accountrightapi.myob.cloud/?version=latest#f2b93dfa-803f-44b9-8a07-756874494227

The short answer for Excel is: No, but Asterisk.
Excel Power Query doesn't support custom connectors (as of 2022-02-07)
To securely use Auth2 flow, it requires a custom connector
There is some built in support, if the connector supports it. ( Like Web or OData)
Here's a summarized version of Chris Web. (He's a Power Query Wizard) Connecting To REST APIs With OAuth2 Authentication In Power Query/Power BI # blog.crossjoin.co.uk
the definitive, Microsoft-endorsed answer to this question is:
If want to connect from Power BI to a REST API that uses OAuth2 authentication then you need to build a custom connector.
You can use OAuth2 credential flow in regular Power Query queries without needing a custom connector.
this is not recommended: it’s not secure and it’s not reliable. In particular, hard-coding usernames/passwords or client ids/client secrets in your M code is a really bad idea
The only exception is that you can connect to some APIs that use AAD authentication using the built-in web or OData connectors
To use a custom connector in the Power BI Service, it requires an on-premises gateway
How to implement OAuth2 flow
Creating a Custom Connector
Using built-in OAuth2 flow using with Azure Active Directory using the Web and OData connectors

I used excel VBA code to handle the MYOB API connection by invoking MS Edge, with Seliumn Basic drivers.
VBA then executes the MYOB API Connector Add-On.
VBA receives the database files I require from MYOB and writes them to a.txt file location on my PC.
VBA then refreshes the data connections for Power Query which runs the M Code I’ve written in advanced editor.
When I close excel, VBA closes all the connections and MYOB add on connector.

Related

Getting 403 Forbidden when Authenticating Non-Interactively to Azure REST API for PowerBi Embedded Report

I am new to both Azure ActiveDirectory as well as Power Bi Embedded.
I have an ASP.net WebForms app that I would like to display some PowerBi Reports in. When I authenticate interactively, all works well, I get my token and am able to access my report. (Follwing the excellent examples found on GitHub) These examples are interactive logins and use the AcquireTokenByAuthorizationCode() method.
However, I don't want my users to have to create / login with any account, just want to render the report for their consumption.
So I have setup a ClientCredential (cc) with my clientID and clientSecret. Am using this with the AquireToken method thusly:
token = AC.AcquireToken("https://analysis.windows.net/powerbi/api",cc).AccessToken;
This successfully gets me a token, however, when I add that to the request header:
request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken.Value));
The Response always fails with a "403 Forbidden" error at:
using (var response = request.GetResponse() as System.Net.HttpWebResponse)
{}
I've looked at other examples, many are using the async methods to aquire a token, which I am not.
Can anyone advise on how I can get past these 403 errors so I can simply serve up reports to my users (I don't want to publish them publicly, due to security concerns).
Thank you kindly in advance!
Doh, I was doing it wrong! Azure Login is not necessarily required to embed reports securely. The 3rd link below is included because my app is not MVC but WebForms, and Mr. Mikami shared a nice code sample which I tweaked to help me achieve my goal.
For anyone else looking to use Power Bi Embedded to embed reports, and authenticate non-interactively, these 3 links helped get me there.
Get started with Microsoft Power BI Embedded
Get started with Power BI Embedded sample
Power BI Embedded using Web Forms and Row Level Security

Import Data from SQL Azure to Excel Using AAD authentication and sharing a link of excel online

The Scenario
Step 1:- User clicks a link which redirects to excel online.
Step 2:- The excel on load will fetch the data from SQL azure (or can use ODATA feed ) using logged in user ID. (some custom logic to filter data based on user).
I did some research and can see excel power query as an option, but i cannot provide SQL server authentication for fetching data from SQL azure, because i need the logged in User details. I tried using Azure AAD authentication for SQL azure, but seems like power query does not have that option either to connect to SQL azure with AAD integrated Authentication. For OData i can use custom authorization implementation but how do i get the user information (logged into excel online) and pass it to Odata.
Looking for help in two major parts:-
1) Any pointers on step 1, do i have to put a excel sheet somewhere in share point (any other options??) and share the link? in that case how does it work if two different set of users (who see data filtered based on permissions) will work?
2) Help on step 2, how do i bring the data to excel with SQL azure or using ODATA but based on logged in user.
P.S :- Correct me if i am in completely wrong direction or any better ideas to implement this scenario.

Authenticating Excel Task Pane app to CRM Online

I would like to write an Excel Task Pane app to interact with CRM Online - to take data from the Excel worksheet, process it and push it into a CRM entity record. My Excel users are on Office 365, as is CRM Online (obviously). We are using ADFS 2.0.
The specific problem I am experiencing is that I do not know how to get authentication to work for the Task Pane app: specifically, to the OData endpoint via JavaScript. Authentication is not my area, so I don't know how to precisely phrase this next requirement, but as we are using Office 365/CRM Online/ADFS then I need to use the logged-in user's Windows AD credentials to authenticate the request.
As far as I can tell, it is not possible to authenticate the Task Pane app directly with CRM Online, and I would like to know if that is known to be true, and if not what method(s) I can use.
I do know that there is a hack for indirect authentication published by a couple of people (http://survivingcrm.com/2013/12/connecting-crm-online-odata-feed-excel-2013-power-query/ or http://www.crmconsult.co.uk/connecting-to-crm-20112013-with-odata-in-excel-2013/) which authenticates the user via the CRM plug-in and then allows other OData connections to succeed - but it doesn't work for me, and I'm averse to rolling out functionality to users which relies on back-door methods.
In the end, I ended used using SOAP in VBA instead of oData in the Task Pane, which meant I was able to use Jason Lattimer's hard work from http://jlattimer.blogspot.co.uk/2015/02/soap-only-authentication-using-vba.html - I don't think there is any way I would have figured out the Authentication piece without that post, so many thanks to him.

Power Query Facebook Access Token

I am trying to query the feed of a Facebook group page using Microsoft Power Query.
This particular query requires an access token. I have tried it out successfully in Facebook's Graph API Explorer, however it seems that Power Query does not include the access token when querying the Facebook Graph API. Thus Power Query is returning the "[DataSource.Error] The returned value has no columns." message. Any ideas on how to include\refresh the access token within Excel?
Power Query absolutely does include the access token when using the Facebook Graph API. However, the set of queries that Facebook allows us to run is considerably smaller than what you can do via the API explorer. This is probably why you don't get any data.
I find that the best way to explore or troubleshoot this kind of issue is to use a tool like Fiddler to see the network traffic as the requests are made.

How to Connect to CRM Dynamics Online Odata endpoint LinqPad?

I'm able to connect to self-hosted CRM sites just fine with the default Odata driver within LinqPad. The URI I use in the "WCF Data Services (OData) Connection" dialog for self-hosted is in the format http://MyServer.com/MyOrgName/xrmservices/2011/OrganizationData.svc. The user name is in the format "domain\username".
When I attempt to follow the same format for an CRM Online instance, it doesn't work.
I'm guessing it's either because of the https, or the windows live credentials, but don't know what steps to take to fix the problem...
Please note, I want to use the odata provider, not the CRM 2011 provider. The odata provider gives me the URL to retrieve the data which is extremely helpful for javascript. The CRM 2011 provider gives the fetch XML, which isn't what I want to use in this case...
I contacted LinqPad and they said they don't currently support Windows Live Authentication. I'm guessing that one would have to write a plugin and use the logic from this page to handle the authentication issues.

Resources