cancel
Showing results for 
Search instead for 
Did you mean: 

Generate an Azure OAuth2.0 Token from a "service" Flow and keep your Flows simple

My previous post illustrated how to use the Microsoft Graph in your Flows without having to create a custom connector/server side code. My favorite server side code is an Azure function written in PowerShell or in C# ( I know I should try Node.js).

One of the challenge of using the Microsoft Graph is we need to get an Azure/oAuth2.0 access token (see last post).

To make it easier and reusable, I decided to isolate the access token generation code in what I call a "Service Flow", which is a Flow that can be invoked via the Http flow action and can return a value + a status if needed (it can also be a fire and forget service flow if we not interested in any return value.

The Flow must start with the "When a HTTP request is received" action and can be ended with the Response action (renamed here as "Return Access Token'.

serviceFlowaccesstoken

 

Let's get into the detail :

 

httprequest
 
The associated schema is :
 

serviceworkflowschema

 

The Access token generation :

 

generate access token

 

Parsing the returned values:

 

parsevalues

 

The associated schema is here :

 

parsschema

 

And the access token is returned here:

 

returnhttp

 

Now the calling workflow (described in my previous post) looks like this:

 

simplifiedversionofgroupsHighlevel

 

The call to the ServiceFlow is detailed here:

 

simplifiedversionofgroups

 

I think it is a good practice to create reusable services with Microsoft Flow. Of course in many cases an Azure function will be good enough, but in some companies it is not that easy to have an Azure account or it is complicated to use this Azure account as a developer, so we must use the tools we have at our disposal :-)

Comments

Hi Team,

 

I have a requirement that needs to connect an application deployed at Azure from Microsoft Flow. I am using the below reference for the same:

 

https://powerusers.microsoft.com/t5/Microsoft-Flow-Community-Blog/Generate-an-Azure-OAuth2-0-Token-f...

 

I am using grant_type=client_credentials along with the parameters required like client_id, client_secret and resource.

 

The issue I was facing is: The Bearer token I am getting in above step is not able to call the api that I need. Please find below screen shots of my flow for your understanding:

 

 Capture1.PNG

 

From the above step I am getting the Bearer token, I am using this Bearer token to call the rest service.

 

 Capture2.PNG

But I am getting an error that Access Denied Error.

 Capture6.PNG

 

 

Capture5.PNG

 

My question is to use grant_type=client_credentials, Is there anything I need to setup at Azure level?

 

Thanks in advance.

 

Giridhar

 

 

 

 

 

 

 

after getting the access_token from the Get call for the 1st HTTP call. I tried to put the bearer token in header of HTTP call, it is error out with non authorized error message. i also try to put in the body, it failed too.  any ideas how to send this bearer token access in Get call. Thanks

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • Solution Architect with Slalom, and organizer of the Boston Office 365 User Group, and long term SharePoint/Office 365 veteren. Find more at http://www.davidlozzi.com. Follow @DavidLozzi
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)