Skip to content

Instantly share code, notes, and snippets.

@nihaue nihaue/Program.cs
Created Jan 20, 2017

Embed
What would you like to do?
SAS Token Generator Console App
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="WindowsAzure.ServiceBus" version="3.4.4" targetFramework="net461" />
</packages>
using Microsoft.ServiceBus;
using System;
using System.Threading.Tasks;
public class Program
{
public static void Main(string[] args)
{
// Setup your values here
var keyName = "YOUR SHARED ACCESS POLICY NAME HERE";
var key = "YOUR KEY NAME HERE";
var relayNamespace = "YOUR RELAY NAME HERE";
Func<Task<string>> method = async () =>
{
var provider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
keyName: keyName,
sharedAccessKey: key,
tokenScope: TokenScope.Namespace);
var token = await provider
.GetWebTokenAsync(
appliesTo: string.Format("https://{0}.servicebus.windows.net/", relayNamespace),
action: "Send",
bypassCache: false,
timeout: TimeSpan.FromDays(365));
return token;
};
var resultToken = method.Invoke().Result;
Console.WriteLine(resultToken);
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.