summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient/AzureAD.aspx.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-05-27 09:32:17 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-05-27 09:32:17 -0700
commit5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba (patch)
tree026bb7a58fc6b80b680f2b5be2a25ddf1efbf0f5 /samples/OAuthClient/AzureAD.aspx.cs
parente4c746826690259eddba106e8a44d1b52b542faf (diff)
parent064220dbab72b00f23abd041bf4a30ea87a00d88 (diff)
downloadDotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.zip
DotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.tar.gz
DotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.tar.bz2
Merge branch 'v4.3'
Conflicts: samples/OAuthClient/Default.aspx samples/OAuthClient/Facebook.aspx.cs samples/OAuthClient/Web.config samples/OAuthClient/WindowsLive.aspx.cs samples/OAuthClient/packages.config src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs src/DotNetOpenAuth.Core/Messaging/StandardWebRequestHandler.cs src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs src/packages/repositories.config src/version.txt
Diffstat (limited to 'samples/OAuthClient/AzureAD.aspx.cs')
-rw-r--r--samples/OAuthClient/AzureAD.aspx.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/samples/OAuthClient/AzureAD.aspx.cs b/samples/OAuthClient/AzureAD.aspx.cs
new file mode 100644
index 0000000..3943cc8
--- /dev/null
+++ b/samples/OAuthClient/AzureAD.aspx.cs
@@ -0,0 +1,49 @@
+namespace OAuthClient {
+ using System;
+ using System.Configuration;
+ using System.Net;
+ using System.Runtime.Serialization.Json;
+ using System.Web;
+ using System.Web.UI;
+
+ using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuth2;
+
+ public partial class AzureAD : System.Web.UI.Page {
+ private static readonly AzureADClient client = new AzureADClient {
+ ClientIdentifier = ConfigurationManager.AppSettings["AzureADAppID"],
+ ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["AzureADAppSecret"]),
+ };
+
+ protected void Page_Load(object sender, EventArgs e) {
+ this.RegisterAsyncTask(
+ new PageAsyncTask(
+ async ct => {
+ IAuthorizationState authorization = await client.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), ct);
+ if (authorization == null) {
+ // Kick off authorization request
+ var request = await client.PrepareRequestUserAuthorizationAsync(cancellationToken: ct);
+ await request.SendAsync();
+ this.Context.Response.End();
+ } else {
+ string token = authorization.AccessToken;
+ AzureADClaims claimsAD = client.ParseAccessToken(token);
+
+ // Request to AD needs a {tenantid}/users/{userid}
+ var request =
+ WebRequest.Create("https://graph.windows.net/" + claimsAD.Tid + "/users/" + claimsAD.Oid + "?api-version=0.9");
+ request.Headers = new WebHeaderCollection();
+ request.Headers.Add("authorization", token);
+ using (var response = request.GetResponse()) {
+ using (var responseStream = response.GetResponseStream()) {
+ var serializer = new DataContractJsonSerializer(typeof(AzureADGraph));
+ AzureADGraph graphData = (AzureADGraph)serializer.ReadObject(responseStream);
+ this.nameLabel.Text = HttpUtility.HtmlEncode(graphData.DisplayName);
+ }
+ }
+ }
+ }));
+ }
+ }
+} \ No newline at end of file