page_type | languages | products | name | description | ||||
---|---|---|---|---|---|---|---|---|
sample |
|
|
.NET code for generating tokens for "Azure CDN Premium from Verizon" (a.k.a. Edgecast) |
This sample demonstrates how to generate tokens for 'Azure CDN Premium from Verizon', so only authorized parties can download an asset from the CDN. |
This project demonstrates how to generate access tokens for Edgecast in .NET.
The term "Edgecast" refers to the "Verizon Digital Media Services / Edgecast Content Delivery Network CDN", formally known as the "Azure Content Delivery Network Premium from Verizon" in Azure.
The actual implementation in .NET is F#, so you can easily plug it into your .NET core web app, or call it from F# Interactive.
It offers a fluent API for both C# and F#, so token creation is self-explanatory.
Just run dotnet fsi ./edgecast.fsx
#r "nuget: BouncyCastle.NetCore, 1.8.8"
#load "edgecastlib/EdgecastCrypto.fs"
open System
open EdgecastCrypto
let inspect msg a =
printfn "%s: %A" msg a
a
let key = "primary202109099dc4cf480b17a94f5eef938bdb08c18535bcc777cc0420c29133d0134d635aa78a1e28f6b883619ed5f920bd3cd79bfe10c42b5d96b7eeb84571ceee4cb51d89"
createTokenValidFor (TimeSpan.FromDays(365.0))
|> inspect "token"
|> encrypt key
|> inspect "encrypted"
|> decrypt key
|> inspect "decrypted again"
|> ignore
This creates a result, similar to this:
token: { ExpirationDate = 9/14/2022 4:50:46 PM
ClientIPAddress = None
AllowedCountries = ["DE"]
DeniedCountries = []
AllowedReferrers = []
DeniedReferrers = []
AllowedProtocol = []
DeniedProtocol = []
AllowedUrls = ["/assets"] }
encrypted: "6CM31tJXEmlAeh11HC-23FlVO96xW9udR_gCPcoX5uzQXnpQo2ThqPEUHO1AuAuLiCvJ-dijWiZHYZeRmdSUpku6I7twHn1AY0w4oECe9HQm6Z-WiatHKwU"
decrypted again: { ExpirationDate = 9/14/2022 4:50:46 PM
ClientIPAddress = None
AllowedCountries = ["DE"]
DeniedCountries = []
AllowedReferrers = []
DeniedReferrers = []
AllowedProtocol = []
DeniedProtocol = []
AllowedUrls = ["/assets"] }
using System;
using EdgecastCryptoExtensions;
class Program
{
static void Main()
{
var key = "primary202109099dc4cf480b17a94f5eef938bdb08c18535bcc777cc0420c29133d0134d635aa78a1e28f6b883619ed5f920bd3cd79bfe10c42b5d96b7eeb84571ceee4cb51d89";
_ = EdgecastCrypto.createTokenValidFor(TimeSpan.FromDays(365.0))
.AddAllowedCountry("DE")
.AddAllowedUrl("/assets")
.Inspect("token")
.Encrypt(key)
.Inspect("encrypted")
.Decrypt(key)
.Inspect("decrypted");
}
}
static class Util
{
internal static T Inspect<T>(this T t, string message)
{
Console.Out.WriteLine($"{message}: {t}");
return t;
}
}