Skip to content

Instantly share code, notes, and snippets.

@ahelland
ahelland / Dockerfile.CI
Created April 18, 2018 08:06
Dockerfile for api-playground referred to in "Building Microservices with AKS and VSTS — Part 4"
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
@ahelland
ahelland / api-playground.yaml
Created April 18, 2018 08:04
Kubernetes YAML definition for api-playground referred to in "Building Microservices with AKS and VSTS — Part 4"
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: api-playground
spec:
template:
metadata:
labels:
app: api-playground
spec:
@ahelland
ahelland / api-playground-ingress.yaml
Created April 11, 2018 07:06
Kubernetes YAML definition for api-playground-ingress referred to in "Building Microservices with AKS and VSTS — Part 3"
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: api-playground-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/tls-acme: 'true'
spec:
tls:
- hosts:
@ahelland
ahelland / ExternalDNS.yaml
Created April 11, 2018 07:03
Kubernetes YAML definition for ExternalDNS referred to in "Building Microservices with AKS and VSTS — Part 3"
apiVersion: v1
kind: ServiceAccount
metadata:
name: external-dns
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: external-dns
rules:
@ahelland
ahelland / api-playground.yaml
Created April 4, 2018 07:47
Kubernetes YAML definition for api-playground deployment/service referred to in "Building Microservices with AKS and VSTS — Part 2"
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: api-playground
spec:
template:
metadata:
labels:
app: api-playground
spec:
@ahelland
ahelland / DeviceprofileADAL.cs
Created February 14, 2018 09:50
Implementing the OAuth Deviceprofile Flow using ADAL
[HttpGet]
public async Task<IActionResult> LoginADAL()
{
AuthenticationContext ctx = null;
ctx = new AuthenticationContext("https://login.microsoftonline.com/common");
DeviceCodeResult codeResult = ctx.AcquireDeviceCodeAsync(resource, ClientId).Result;
DCR dcr = new DCR { message = codeResult.Message,
device_code = codeResult.DeviceCode,
expires_in = codeResult.ExpiresOn.ToString(),
@ahelland
ahelland / DeviceprofileHTTP.cs
Created February 14, 2018 09:47
Implementing the OAuth Deviceprofile Flow with plain HTTP calls
string ClientId = "guid-from-portal";
string resource = "00000002-0000-0000-c000-000000000000";
public class DCR
{
public string device_code { get; set; }
public string message { get; set; }
public string user_code { get; set; }
public string interval { get; set; }
public string expires_in { get; set; }
var tokenCredentials = new TokenCredentials(token.access_token, "Bearer");
// Create a Power BI Client object. It will be used to call Power BI APIs.
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
// Generate Embed Token.
var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
var tokenResponse = await client.Dashboards.GenerateTokenInGroupAsync(GroupId, dashboardId,
generateTokenRequestParameters);
}
public class PowerBI
{
private static readonly string Username = "[email protected]";
private static readonly string Password = "Pa$$w0rd";
private static readonly string stsFqdn = "https://adfs.contoso.com";
private static readonly string ResourceUrl = "https://analysis.windows.net/powerbi/api";
private static readonly string ClientId = "guid-from-Azure-Portal";
private static readonly string ClientSecret = "secret-from-Azure-Portal";
private static readonly string ApiUrl = "https://api.powerbi.com/";
private static readonly string GroupId = "group-guid";
@ahelland
ahelland / APIMFunction_02.csx
Created December 20, 2017 17:23
Azure Function for acquiring a token from Azure AD, and subsequently use this for auth towards Azure API Management
using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
public static void Run(string input, TraceWriter log)
{
log.Info($"C# manually triggered function called with input: {input}");