-
-
Save xinmyname/7474217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var serviceRequest = new WebClient()) | |
{ | |
string token = GetAuthorizationToken("yourservice","owner", "NW1wr7/nlgggTFnB5L7nDBrOLC+o1E1P4ZZqPaP2mY4="); | |
serviceRequest.Headers["Authorization"] = string.Format("WRAP access_token=\"{0}\"", token); | |
string response = serviceRequest.DownloadString(new Uri(url)); | |
return response; | |
} | |
// connects to ACS and gets WRAP Authorization token | |
public string GetAuthorizationToken(string serviceNamespace, string issuerName, string issuerPassword) | |
{ | |
string acsEndpoint = "https://" + serviceNamespace + "-sb.accesscontrol.windows.net/WRAPv0.9"; | |
string relyingPartyAddress = "http://" + serviceNamespace + ".servicebus.windows.net"; | |
NameValueCollection postData = new NameValueCollection | |
{ | |
{ "wrap_scope", relyingPartyAddress }, | |
{ "wrap_name", issuerName }, | |
{ "wrap_password", issuerPassword }, | |
}; | |
WebClient webClient = new WebClient(); | |
byte[] responseBuffer = webClient.UploadValues(acsEndpoint, "POST", postData); | |
string response = Encoding.UTF8.GetString(responseBuffer); | |
string encodedtoken = response.Split('&') | |
.Single(value => value.StartsWith("wrap_access_token=")) | |
.Split('=')[1]; | |
string token = System.Web.HttpUtility.UrlDecode(encodedtoken); | |
return token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment