Skip to content

Instantly share code, notes, and snippets.

@ahelland
ahelland / APIMFunction_01.csx
Created December 20, 2017 17:20
Azure Function for making an http request to an API behind Azure API Management
using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
public static void Run(string input, TraceWriter log)
{
log.Info($"C# manually triggered function called with input: {input}");
var apimUrl = " https://contosio.azure-api.net/foo/messages";
@ahelland
ahelland / APIMAuth.xml
Created December 20, 2017 17:18
Azure API Management Policy for validating jwt and rewriting authorization header to use a SAS Token
<inbound>
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized">
<openid-config url="https://login.microsoftonline.com/common/.well-known/openid-configuration" />
<audiences>
<audience>https://management.core.windows.net/</audience>
</audiences>
<required-claims />
</validate-jwt>
<set-header name="Authorization" exists-action="override">
<value>@{
@ahelland
ahelland / SASTokenFunction01.csx
Created December 20, 2017 17:14
Azure Function for sending a simple son payload to an Azure Event Hub
using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
public static void Run(string input, TraceWriter log)
{
var resourceUri = "contoso.servicebus.windows.net";
var keyName = "RootManageSharedAccessKey";
@ahelland
ahelland / job.sql
Created July 19, 2017 11:09
Ruter API - ADLA Job
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
DECLARE @out string="adl://contoso.azuredatalakestore.net/foo/delayedDepartures.csv";
@departure =
EXTRACT DataFrameRef string,
DatedVehicleJourneyRef string,
DestinationName string,
AimedArrivalTime string,
@ahelland
ahelland / run.csx
Created July 19, 2017 11:04
Ruter API - Azure Function
using System;
using System.IO;
using System.Threading;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Microsoft.Azure.Management.DataLake.Store;
using Microsoft.Azure.Management.DataLake.Store.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest.Azure.Authentication;
@ahelland
ahelland / CSharp.cshtml
Created March 29, 2017 09:39
API Playground - loadGet Template
function loadGet() {
document.getElementById("csxEditor").innerHTML = "";
var strGetTemplate = [
'using System;',
'using System.Net.Http;',
'\npublic class HelloAPI',
'{',
'\tpublic static void Main()',
'\t{',
'\t\tusing (var client = new HttpClient())',
@ahelland
ahelland / HomeController.cs
Created March 29, 2017 09:35
API Playground - C#
[HttpPost]
public async Task<IActionResult> CSharp(Code code)
{
string output = code.csx;
var apiURL = "https://www.microsoft.com/net/api/code";
using (var client = new HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(apiURL));
@ahelland
ahelland / HomeController.cs
Created March 29, 2017 09:31
Api Playground - HTTP
[HttpPost]
public async Task<IActionResult> Http(Code code)
{
string output = code.csx;
using (var client = new HttpClient())
{
var reqInput = code.csx;
var req = JsonConvert.DeserializeObject<HttpTestRequest>(reqInput);
var requestUrl = req.url;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace BenderPreCompiled
{
public class BenderDll
@ahelland
ahelland / MailDaemon.csx
Created December 9, 2016 18:27
Azure Function for sending a mail as a user after authenticating using the Password Grant flow
#r "Newtonsoft.Json"
using System;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json;
using static System.Environment;
using System.Collections.Generic;
public async static void Run(string input, TraceWriter log)