Skip to content

Instantly share code, notes, and snippets.

@ahelland
ahelland / HomeController.cs
Created March 18, 2014 14:48
Office 365 SharePoint/OneDrive REST API snippet.
public ActionResult Stats()
{
var authorizationEndpoint = "https://login.windows.net/";
var resource = "https://graph.windows.net";
//Change port number to whatever your Visual Studio has chosen for you
var redirectURI = "https://localhost:44300/Home/CatchCode";
string authorizationUrl = string.Format("{0}{1}/oauth2/authorize?&response_type=code&client_id={2}&resource={3}&redirect_uri={4}",
authorizationEndpoint,
ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value,
@ahelland
ahelland / ExchangeController.cs
Created March 24, 2014 21:55
Code for the blog post "Microsoft Provides a RESTful API for Exchange - Part 2" on http://mobilitydojo.net/2014/03/24/microsoft-provides-a-restful-api-for-exchange-part-2/
using CustomOffice365OWA.Models;
using System;
using System.Globalization;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace CustomOffice365OWA.Controllers
{
[RoutePrefix("Mail")]
@ahelland
ahelland / AzureADController.cs
Last active August 29, 2015 13:58
Code for the blog post "Extending Your Azure Active Directory - Part 1" - on http://mobilitydojo.net/2014/04/08/extending-your-azure-active-directory-part-1/
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.Globalization;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
@ahelland
ahelland / AzureADModels.cs
Created April 9, 2014 08:44
Code for the blog post "Extending Your Azure Active Directory - Part 2" - on http://mobilitydojo.net/2014/04/09/extending-your-azure-active-directory-part-2/
using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel;
namespace DirectoryExtensionsApp.Models
{
public class UserContext
{
[JsonProperty("odata.metadata")]
public string userContext { get; set; }
#r "Newtonsoft.Json"
#r "System.Configuration"
#r "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
using System.Net;
using System.Configuration;
using System.Security.Claims;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
@ahelland
ahelland / FunctionBotRun.csx
Created April 26, 2016 18:36
An Azure Function implementing the Microsoft Bot Framework to return random quotes
#r "Newtonsoft.Json"
#r "Microsoft.Rest.ClientRuntime.dll"
#r "Microsoft.Bot.Connector.Utilities.dll"
#r "Microsoft.Bot.Connector.dll"
using System.Net;
using Microsoft.Bot.Connector;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Verbose($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
@ahelland
ahelland / EASTimerTrigger.csx
Created May 31, 2016 07:41
TimerTriggered Function for monitoring Exchange ActiveSync
#r "EAS Protocol.dll"
#r "System.Xml.Linq.dll"
using System;
using System.Net.Http.Headers;
using System.Xml.Linq;
using EAS_Protocol.WBXML;
public static void Run(TimerInfo myTimer,out string statuscode, out string responseBlob, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
@ahelland
ahelland / EASQueueTrigger.csx
Created May 31, 2016 08:04
QueueTriggered Function for processing HTTP Status Codes returned from Exchange ActiveSync
using System;
public static void Run(string myQueueItem, out object statusDocument, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
var status = myQueueItem.Split(';');
log.Info($"Guid: {status[0]}, StatusCode: {status[1]}");
var guid = status[0];
var resCode = status[1];
@ahelland
ahelland / EASBlobTrigger.csx
Created May 31, 2016 08:15
BlobTriggered Function for processing WBXML returned from Exchange ActiveSync
#r "EAS Protocol.dll"
#r "System.Xml.Linq.dll"
using System;
using System.Xml.Linq;
using EAS_Protocol.WBXML;
public static void Run(string myBlob, TraceWriter log)
{
log.Info($"C# Blob trigger function processed: {myBlob}");
var response = myBlob.Split(';');
@ahelland
ahelland / JwtCracker.cs
Created June 14, 2016 18:51
Method to decode a JWT and pretty print the JSON contents
//Assume the input is in a control called txtJwtIn,
//and the output will be placed in a control called txtJwtOut
var jwtHandler = new JwtSecurityTokenHandler();
var jwtInput = txtJwtIn.Text;
//Check if readable token (string is in a JWT format)
var readableToken = jwtHandler.CanReadToken(jwtInput);
if(readableToken != true)
{