NOTE: This blog post was written in June 2016 and is based upon a preview of Azure Logic Apps. The functionality is bound to change in the future. I have no additional information about when the new functionality may, or may not, be available.

Recently I have been working on a PoC where I have created an API App that needs to talk to an On-Premise REST Service hosted in a 3rd party platform called Denodo. I will talk about those details in a future post. But for the purpose of this post I want to discuss how I can secure, using Azure AD, my Denodo API App. In the broader solution that I am working on, I know this API App will be called from a Logic App. As a result, I want to prove out that a Logic App can authenticate, with Azure AD, while calling my API App.

Some documentation that did help me out in this journey was the following post from Stephen Siciliano. In the comments, Jeff Hollan also provided some commentary that was helpful. There were still a few bumps in the road, so I figured I would document exactly the steps that I followed, in order to provide a more streamlined experience.

Part 1 – Enabling Authentication on Endpoint

Build your API App in Visual Studio. In my case I am wrapping an existing REST API that is provided by Denodo platform. One of the benefits of wrapping it using App Service is that I can add Swagger meta data, which will help me in Logic Apps. Also, by using an App Service, I can bridge cloud and on-prem using either Hybrid Connections or a VPN connection. More on the hybrid connectivity in next post (promise).

Enable Swagger metadata by uncommenting the .EnableSwaggerUI call in the SwaggerConfig.cs

Publish App Service. You will need to specify/create an Azure APP Service Plan, Azure Subscription and Resource Group.

With the Azure App Service Authentication set to off we will be able to access our API through a browser.

By navigating to our APP Service URL and appending “/Swagger” we will see our API exposed. We can interact with our API by clicking on Try It Out!

At this point we know our API is working and in my case it is calling an on-prem REST API.

NOTE: When you first deploy your API App, a swagger file will be created. You should download this file before you start locking down your endpoint.

At my organization we heavily leverage Azure AD. Whenever we are doing something with cloud, we try to plug-in to Azure AD as we can centrally manage it and it generally plays nice in the Microsoft ecosystem and other SaaS apps.

At first I thought I was going to have to create an Azure AD Application by going into the old portal, but you don’t have to do that any more. Within the new Azure AD Portal there is some slick integration going on.

While in your App Service click on Authentication/Authorization and turn on App Service Authentication and and select Log in with Azure Active Directory.

Click on Azure Active Directory under Authentication Providers

From Management mode select Express

Create New AD App and provide AD App Name.

Save your configuration

If you then navigate to your Web API/Swagger console you should now be challenged to authenticate against Azure AD. Enter your credentials and you can interact with Swagger console.

At this point your endpoint is secure, but how do you connect Logic Apps to use it? Keep reading.

Part 2 – Exposing Swagger Metadata

As of this writing (June 2016), you will have issues with Logic Apps being able to consume your Swagger metadata. The reason for this is that Logic Apps (at least for now) requires that the Swagger metadata is available from a public source and over HTTPS. As soon as you locked down your endpoint, the swagger metadata is not publicly available.

For now (as I fully expect that Microsoft is working on a cleaner solution), Take your swagger metadata and place it in Blob storage without any authentication around it. To do this perform the following steps:

Create the storage account from the new portal

Use the Resource manager Deployment model, it can be General Purpose with Standard Performance, using Locally-redundant storage (LRS) and provide a Resource Group.

With your storage container created, you can then use a tool like Azure Storage Explorer to manage your storage instance.

While logged in with my Storage Account credentials (available from Azure Portal) I created a new Blob Container and then set the access level to Public

Use the Upload button to update your swagger meta data and then you can view your URI for your document by having it selected and clicking on View.

Unfortunately we are not done yet. We now need to deal with CORS. There are ways to enable CORS for blob storage but I decided not to go down that path…at least for now. As part of the original article that I referenced, Jeff Hollan from the Logic Apps team has provided a bit of a work around to get around CORS. With your swagger file in a public blob storage, you can take that URL and use his utility which has a “CORS bypass” enabled. This may not be a long term solution and I can’t speak to how long Jeff will keep this alive but for now it works for me. If you want to enable CORS for your storage account then check out this link.

To use Jeff’s workaround I just added my Swagger/Blob Storage URL to his helper api:

I then need to update my API Definition in my API App to use this new URL.

Part 3 – Wiring Logic App to use AAD

In order to complete this part we are going to need some data from Azure AD. In order to get this data we need to get it from the old portal at https://manage.windowsazure.com.

Ultimately, we need to construct a message that looks the following so that we can provide it as an Authentication header in our API Call
{“audience”:”<SignOnURL>”,
“clientId”:”<ClientID>”,
“secret”:”<Secret>”,
“tenant”:”<TenantID>”,
“type”:”ActiveDirectoryOAuth”}

Now the question is where do you get these values? You get them from your Azure AD instance and more specifically the Azure AD App that you created in Part 1 of this blog post. In the following image I have outlined exactly where to get the required values.

With this information in hand we can now create a new Logic App. To keep things simple, I have created a Logic App and use a Recurrence Trigger, mainly so that I can trigger it on demand.

Next, I should be able to select Show APIs for App Services in the same region and my API should show up.

Note: If you have any issues with Swagger meta data, this is where you will see them. You may see the dreaded “Failed to fetch swagger. Ensure you have CORS enabled on the endpoint and are calling an HTTPS endpoint” error. If so you likely have one of two issues:

Swagger Metadata not being publicly accessible

CORS

For my API, I am only performing a GET and as a result do not have any query parameters. The only data I need to send is in my Authentication Header which we covered in a previous step.

When submitting a message and getting an error like the following, then that means something hasn’t been set up correctly with your Authentication header.

{“code”:”BadRequest”,”message”:”Http request failed as there is an error getting AD OAuth token: ‘AADSTS70001: Application with identifier ‘<bad_token>’ was not found in the directory aff3442b-5f55-409c-be77-da97b366435a\r\nTrace ID: 54eb2e86-2e1b-46p9-8d14-983102278428\r\nCorrelation ID: 873a248f-900c-4f19-9684-447b5bfe6da4\r\nTimestamp: 2016-06-27 03:01:28Z’.”}

Conclusion
I fully expect Microsoft to make this a simplier and more streamlined experience but until that time, I think it is important that people are locking down their Azure resources. Lately I have been doing a lot of PoCs with the business and other IT groups. Naturally the question about security is going to come up and I am not going to just say it is secure, or say it is possible for it to be secure – I want to ensure it is secure. Once you have the process down, I also don’t think it is too much effort to get it working once you understand all of the mechanics involved.

I have a scenario at work where we need to provide some simple syncronization between a SQL Azure table and a SharePoint Online Custom List. As a pre-requisite each morning before business users get into the office, we need to purge the contents from the SharePoint list and update it with today’s data + a 6 day forecast of future data.

I have integrated BizTalk with custom SharePoint Lists in the past, and even wrote about it in one of my books. It wasn’t a particularly good experience so I was interested in evaluating how Logic Apps would deal with custom lists.

One difference between BizTalk and Logic Apps, in this case, is that BIzTalk has a SharePoint Adapter but it will only interface with SharePoint Document Libraries. If you wanted to integrate BizTalk with SharePoint Custom lists you are likely going to do so with the Lists.asmx web service. While it is completely possible to use this custom web service approach, be prepared to spend a few hours (if you are lucky) getting everything working.

With Logic Apps, it is a very different experience. From the Logic Apps canvas you need to add a trigger to kick off your workflow. In my case, I used a Recurrence trigger that will run every day at 7:45 am. I can also kick this trigger off manually in the Azure Portal if I wish.

Next, I want to add an action and then search for SharePoint from the Microsoft managed APIs dropdown. After we do that, all available SharePoint Online operations will be displayed.

In my case, I want to purge all items, but there is no Delete List operation. Instead, I need to get all items in my list first, so that I can use the ID from each record to delete that item. In my scenario I expect 7 days * 24 hourly records (168 items) to be in my list at any given time so this load is not a concern.

With this situation in-mind, I will select the Get Items operation.

Once I have selected my Get Items operation, I need to establish my connection to my Office 365 subscription. (I will spare you from the password prompts)

With my connection established, I now need to provide the URL to my SharePoint List. I can also specify optional parameters that control the number of items returned.

I must say the experience in this dialog is a good one. I can click on the Site URL dropdown and all of the sites that I have access to will be in that list. Once I have selected my URL and then click on the List Name dropdown, I then see all the lists that I have access to on that site.

Next, I need to add another activity and this time I will select the Delete Item operation.

I have a similar experience in the Delete Item dialog that I had in the Get Items dialog. With my connection already established, I need to provide the same Site URL and the same List Name. What is different this time is I need to provide an ID for the list item that I would like to delete. In this case it will be an ID that is coming from my Get Items response.

You might be asking yourself – will how is that going to work for all of my items in my list? Don’t you need a for loop to iterate through the Get Items collection? The answer is Yes, but the Logic Apps team has made this very simple – they have done the heavy lifting for you. If you go into Code View you can see it there:

I can now my Logic App from the Azure Portal by clicking on Select Trigger and then recurrence.

I can follow my execution and dive into my Get Items and Delete Items calls. By inspecting my inbound and outbound traces I can see the exact payloads and HTTP Status codes from the underlying operations. In this case I was able to delete 300 items in 23 seconds. For each item in my collection, a Delete Item call is made.

Conclusion

It honestly took me about 10 minutes to figure this out. Part of the reason why I am writing about this is I know how long this would take with BizTalk. I anticipate it would take at least 3 hours to do this in BizTalk if it was your first time. So this isn’t a knock against BizTalk, as Logic Apps has been built, IMO, for these lightweight scenarios with little friction.

In the short term I think Microsoft Integration architects and developers will have many opportunities like this one where you can choose one tool or the other. For me, developer productivity needs to be part of that equation. Where the systems that you are integrating are hosted will also play a role. In this case, I am connecting to SharePoint Online and SQL Azure so it also doesn’t make sense, IMO, to route all of this info back on-premises only to go back up to the cloud.

We may also see a Hybrid approach where a BizTalk process can call out to a Logic App where you can take advantage of these new Logic App connectors. This was something that Microsoft discussed at 2016 Integrate Event in London.

In a future blog post we will talk about the other half of this solution which is how to create items in SharePoint Online from SQL Azure.

BizTalk360 has recently released more details on their annual conference in London. This year there is a name change. Instead of the BizTalk Summit, the name gets altered to align with the “Integrate” brand. In case you were not aware, BizTalk360 organized the last Integrate Summit in Redmond back in December 2014 so it makes sense to carry that name forward. BizTalk360 has been working closely with the Microsoft product groups to put on a great event.

This year the summit looks to be better and bigger than ever. There are more than 20 speakers lined up over 3 days . The speakers have a variety of backgrounds including Microsoft Product Group, Consultants, Customers, System Integrators and MVPs. There is also an opportunity to hear from the Microsoft’s leadership team and get insight into their plans as it pertains to Azure App Service and Integration.

The session abstracts look great! The topics cover a broad set of technologies that will appeal to integration focused professionals. The topics include:

BizTalk Server 2016

Azure Logic Apps

Azure App Service

Azure Service Bus (Event Hubs and Messaging)

Internet of Things (IoT)

Azure API Management

Azure Stream Analytics

Power Bi

My topic will focus on some the recent learnings from an Industrial IoT project. I will talk about tag data ingestion, complex event processing (calculations, reference data, out of bounds, absence of event) and visualization. I will also throw in a little BizTalk and Logic apps for good measure.

This will be my third time speaking in London at a BizTalk360 event. I am once again looking forward to the experience as BizTalk360 always puts on a good show and it is a great opportunity to network with the excellent European Integration community.

For more details, please check out the event page. There are early bird specials so pay close attention to the dates.

Ran into an interesting situation today. I have some real time Azure Stream Analytics (ASA) streams that feed a couple Power BI dashboards. I also took the plunge with getting enabled with Azure Multi Factor Authentication (MFA). The MFA setup was fine but I logged back into the Azure Portal later to notice that my ASA job had stopped. When I looked in the ASA Monitoring Logs I found the following Send Error:

Followed by a User authentication error:

I was able to put 2 and 2 together and the timelines aligned to when my MFA was turned on but I was still perplexed. I mean this wasn’t a Windows service that had an out of date password. My credentials were never associated to the ASA job. I did use MFA when logging into the portal so that wasn’t it. I tried to restard the ASA job multiplie times as the portal was giving me a “this is a transient error message”….it wasn’t.

It wasn’t until it clued in on me that when you set Power Bi Outputs for Stream Analytics that you need to also authenticate using your credentials. As soon as MFA was enabled, my credentials had expired and I needed to log back in which did result in an MFA challenge. I got through that and could start my job and outstanding events streamed through.

Conclusion

This isn’t a production workload so the damage was minimal. It does beg the question thought that if you are publishing events from ASA to PowerBI, what is the right way to authenticate with Power BI? Should you be creating a “system” account with no MFA and no password being reset? I am open to recommendations if you have them.

The Microsoft Integration team (BizTalk/Logic Apps) recently hit an important milestone. They have launched the Logic Apps Preview Refresh. You can find the original press release here.

The purpose of this post is to highlight some of the recent investments and then take an existing v1 Logic App and rebuild it in v2.

New Designer

Probably the biggest feature released was the new designer experience. As opposed to the Left –> Right workflow we saw in v1 of Logic Apps, we now find ourselves moving top-down. I think for most BizTalk people, moving top-down is more natural.

Search/Intellisense

In addition to top-down, we also have a search/intellisense type experience when looking for new shapes(connectors). It is a neat way to approach the problem as a canvas that contains pages and pages of connectors isn’t the best user experience.

Intelligent Output

Another benefit is we are not as dependent on the Logic Apps Workflow Language. It is still there but Microsoft has abstracted much of that away from us. So if we want to use a value from a previous step in our workflow we can just select it. A great addition!

This is very much welcomed over the v1 equivalent: A new table has been created @{body(‘wearsy.servicenow.apiapp’).TableName}

Decisions…Decisions

Another investment has been in the way you add an action or a condition. No longer is a condition ‘hidden’ at the card/connector level. Very explicit, easy to read and natural.

Moving the furniture

With v1 of Logic Apps, once you had a card on the canvas you were committed. Rearranging the cards was only possible using the json in the code behind. It at times was painful, so this is a great add. You can now move cards back and forth as long as you are not breaking dependencies.

Native Webhook support

Logic Apps now supports Webhooks which allows developers to build ‘callback’ interfaces over HTTP. Many services support Webhooks as a way to extend their offering including Visual Studio Online, GitHub, Stripe and Paypal to name a few. An example the Logic Apps team likes to use is that you can call a Logic App from Visual Studio when code is committed to your master branch as a way to kick off other downstream processes.

Managed APIs

In v1 of Logic Apps, there was always a provisioning exercise when you wanted to use a new connector/API App. This added some delays in your dev experience and also forced you to create multiple instances in the event you had some different connection strings. Now, Microsoft has provisioned a set of Managed API connections. This means that there is zero delay when using out of the box API connections.

This does have an impact on existing v1 API Apps that you have created and that is one of the main reasons for this post. Since a custom v1 API App is not in this Managed API list it will not be immediately discoverable within Logic Apps. (This is bound to change as we are still in preview and Microsoft is working on this) But, since v1 API Apps were decorated with Swagger meta-data, we can take advantage of the Http + Swagger connector in order to consume our existing Swagger “contract”.

Note: There are a few actions that you need to perform in order for your v1 API App to be discoverable. In order to avoid duplications, I will refer you to Jeff Hollan’s (Microsoft) post and Daniel Probert’s post.

As a starting point, here is my v1 Logic App. I documented the use case here so I won’t get into a lot of details about what it does. In summary, on a regular basis I want this Logic App to initiate, create a table in Service Now using my custom Service Now connector and send me a text message when it is complete.

With my configuration set as described in those previous blog posts I am going to create a new logic app.

The first step that I want to perform is to add the Recurrence card to my Logic App. I will then set a frequency. In this case it is set to a minute but I will revert it back to 1 week after I am done testing. Interesting that Microsoft has added a timezone field and a starttime field.

Next, I will add my Http + Swagger connector. When you think about it, this is actually a very powerful feature. Swagger (recently renamed OpenAPI) is the leading API markup language used by IBM, Amazon, Apigee and many others. What this means is that any API that has Swagger metadata can now be “plugged” into Logic Apps. This has already provided many benefits. An example is that the Microsoft Cortana Analytics team has been including Swagger metadata in their APIs so now Logic Apps can plug them in and developers do not have to worry about connectivity or write their own wrappers. This is a big win!

With my Swagger URL in my clipboard I can paste it in to the Endpoint URL text box and click the Next button.

We will now discover all of the different operations that are available for me to use in my Logic App.

For the purpose of this post, I will use the Table_PostByValue operation. There are 4 attributes that need to be set. Since I want my table to be dynamic, I will use the Logic App Workflow Language functions. I did run into a bit of a bug with this one. If you need to use the @utcnow() function, set it in the code behind. The Product Team is aware and will be addressing this issue.

After configuring my ServiceNow Api App, I want to now send a text message using the v2 Twilio API App. I can easily add it by starting to type the word “Twilio”.

I previously had a Twilio account so I needed to log into their website to obtain my credentials.

Next, I need to provide my Twilio phone number and the phone number where I would like to receive a text. I also want to provide some text in the message and include the name of the table that was just created. By using Swagger, Logic Apps knows that the Service Now API App will return the name of the Table that was created and as a result I can simply click on that item and have it added to my message body.

After all my configuration is complete, this is what my Logic App looks like. Pretty clean!!!

The end result when testing is that I have a new table created and receive a text message. Note that Service Now instance is the pacific region which accounts for the 1 hour timestamp delta.

Conclusion

While still in preview, we can see that the Microsoft team is working hard and is focused on providing continuous value to customers. While there are some features I would like to see included, this was a good release and a step in the right direction.

We are currently embarking on an Event Hub project where we will be processing device “reads” on a frequent basis. You can consider the use case to be in the Industrial IoT space but the difference is we do not have to manage the devices. Without geting into a lot of details, we have aggregators responsible for that. For this reason we decided not to pursue the Azure IoT Suite as we really just need Event Hub capabilities.

We will not have a lot of publishers, but the question did come up how can we protect, or restrict where traffic is coming from and how we manage keys to our service. Event Hubs currently does not have an ability to white list a set of IP Addresses. This implies that someone could take your SAS key and potentially ‘pollute’ your Event Hub from a location that has no business publishing to your Event Hub.

Another option is to issue SAS tokens, which do have expiration timestamps attached to them. This will not get you away from the location in which the publisher is pushing events to your Event Hub. But, it does ensure if you have a key leakage that its TTL (time to live) reduces risks. I am going to continue to explore this path in a later post or talk.

But for the purpose of this post, I am going to focus on API Managment (APIM) + Event Hubs to see what we can do. In a previous post, I did speak about using Azure API Management policies to limit where an API can be called from. We will leverage that post in the interest of keeping this post short(er).

The first thing we need to understand is the mechanics of calling an Event Hub using HTTP. The Service Bus team, does prefer AMQP and for good reasons (see Publishing an event section) but back to the whitelisting requirement we are left with HTTP. In order to call an Event Hub via HTTP there is some information that we need to collect including:

Create ServiceBus Namespace

Create Event Hub

Create Shared Access Policy

In this case we will create a Send Access Policy. We do not want to provide uncessary privileges to our publisher; such as the ability to consume from our Event Hub.

Generate a SAS token. To accomplish this feat, I used a tool by Sandrino Di Mattia which is available here: https://github.com/sandrinodimattia/RedDog/releases/tag/0.2.0.1 When you run the tool, you will be prompted for some of your ServiceBus information including Namespace, Event Hub Name, an arbitrary Publisher Name and details from the SAS Policy you just created. Once you provide this infromation and click on the Generate button you will have a SAS Token based upon the TTL that you specified. Copy this token as we will need it in future steps.

We now can assemble our URL for our Event Hub based upon the following information:

This is somewhat arbitrary. What I used here was the name of my Shared Access Policy. Make sure to use the same value that you used to generate SAS Token.

TESTING

We can now test our ability to send a message to our Event Hub using HTTP and PostMan. In order to call our Event Hub using HTTP we will need our SAS token that we just generated and our URL.

In order to call the Event Hub endpoint we will need to create an Authorization Header and populate it with our SAS token.

Following that we can provide our URL and a message body that we want to send to Event Hubs. After clicking on the Send button we will see we get an HTTP 201 status code.

Azure API Management

We now know we can use HTTP to populate our Event Hub. With this done, lets configure our API Management instance. I am not going to go into a lot of detail on how to set up Azure API Management. I will refer you to a previous presentation video and tutorial on the subject.

Within Azure API Management we want to do the following

Create an API In order to do this we will need our Event Hub URL that we used in PostMan.

Create an Operation (and meta data). In this case there is no URL rewriting that needs to be performed. Our requests will be passed through.

Apply our policies to Operation. In this case we will add two policies:

IP Filter where I will include my IP Address and set action = “allow”

Set Header where I will provide my SAS Token that will allow my API Management instance to talk to Event Hubs.

Create Product

Add API to Product

Publish Product

Assign Access to Product

Testing

Since we are using IP Whitelisting, I will make a call using PostMan, but this time I will send it through the API Management Proxy.

In order to call our endpoint through API Management, we will need our API Key which is available from the Azure Portal. We can access this information from the Users menu. We can then click on the Show link where we can then copy our key.

In PostMan, we will want to add an Authorization Header called ocp-apim-subscription-key and then provide our API Key that we just copied.

Next, we can provide our URL, message body and click Send button.

As you can see we have a successful publish through APIM and receive an HTTP 201 back.

To ensure our IP Whitelist is working, let’s try to call our service from the API Management Developer’s Console. As expected, we get an HTTP Status code of 403 Forbidden back which is as expected.

I have been learning Stream Analytics recently and ran across an issue that I couldn’t find any good examples of how to solve the problem so I figured I would post my solution.

I fully expect to expand on this scenario in coming months, but for now will keep the scenario light. What I am doing is getting device reads off of an Azure Event Hub. These reads are being aggregated on the publisher side and placed into a single message/event. Since the publisher is creating a message structure that contains many device reads for that specific interval I wanted to ensure I can process each element in the array within my Stream Analytics query.

From a Stream Analytics perspective, here is what my query looks like:

SELECT tagDetails.ArrayValue AS tag FROM inputeventhub AS e CROSS APPLY GetArrayElements(e.tagDetails) AS tagDetails

When I execute my query, my result looks like this:

The key to making this query works is the “CROSS APPLY” operators. MSDN describes these operators as: “The APPLY operator allows you to invoke a table-valued function for each row returned by an outer table expression of a query. The table-valued function acts as the right input and the outer table expression acts as the left input. The right input is evaluated for each row from the left input and the rows produced are combined for the final output. The list of columns produced by the APPLY operator is the set of columns in the left input followed by the list of columns returned by the right input.

There are two forms of APPLY: CROSS APPLY and OUTER APPLY. CROSS APPLY returns only rows from the outer table that produce a result set from the table-valued function. OUTER APPLY returns both rows that produce a result set, and rows that do not, with NULL values in the columns produced by the table-valued function.”

Then as part of the SELECT statement, we are able to iterate through each value in the array which gives us our columns.

Stay tuned for more info on Event Hubs and Stream Analytics as I continue to get more familiar with them. One thing I have learned early is that they are very powerful together.

Also, as an additional resource, I encourage you to visit the MSDN Complex Data Typespost which will give you some examples of other more complex scenarios.