diff options
author | Girish Bablani <girishb@microsoft.com> | 2013-04-16 18:53:13 -0700 |
---|---|---|
committer | Girish Bablani <girishb@microsoft.com> | 2013-04-16 18:53:13 -0700 |
commit | 789f14adf18e65ab416b60341bfbecc6577a1c37 (patch) | |
tree | 3f140b5f1679cb2857cd65a7d14d2c0ec28f2fca /samples/OAuthClient | |
parent | 9e33a9e89ba1973cb3bf923e1303105047094d9c (diff) | |
download | DotNetOpenAuth-789f14adf18e65ab416b60341bfbecc6577a1c37.zip DotNetOpenAuth-789f14adf18e65ab416b60341bfbecc6577a1c37.tar.gz DotNetOpenAuth-789f14adf18e65ab416b60341bfbecc6577a1c37.tar.bz2 |
Enabled AzureAD integration and added TestAzureAD sample app
Diffstat (limited to 'samples/OAuthClient')
-rw-r--r-- | samples/OAuthClient/AzureAD.aspx | 17 | ||||
-rw-r--r-- | samples/OAuthClient/AzureAD.aspx.cs | 50 | ||||
-rw-r--r-- | samples/OAuthClient/AzureAD.aspx.designer.cs | 33 | ||||
-rw-r--r-- | samples/OAuthClient/Default.aspx | 1 | ||||
-rw-r--r-- | samples/OAuthClient/OAuthClient.csproj | 8 | ||||
-rw-r--r-- | samples/OAuthClient/Web.config | 3 |
6 files changed, 112 insertions, 0 deletions
diff --git a/samples/OAuthClient/AzureAD.aspx b/samples/OAuthClient/AzureAD.aspx new file mode 100644 index 0000000..9311efc --- /dev/null +++ b/samples/OAuthClient/AzureAD.aspx @@ -0,0 +1,17 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AzureAD.aspx.cs" Inherits="OAuthClient.AzureAD" Async="true"%> + +<!DOCTYPE html> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head runat="server"> + <title></title> +</head> +<body> + <form id="form1" runat="server"> + <div> + Welcome, + <asp:Label Text="[name]" ID="nameLabel" runat="server" /> + </div> + </form> +</body> +</html> diff --git a/samples/OAuthClient/AzureAD.aspx.cs b/samples/OAuthClient/AzureAD.aspx.cs new file mode 100644 index 0000000..4b601fd --- /dev/null +++ b/samples/OAuthClient/AzureAD.aspx.cs @@ -0,0 +1,50 @@ +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) + { + IAuthorizationState authorization = client.ProcessUserAuthorization(); + if (authorization == null) + { + // Kick off authorization request + client.RequestUserAuthorization(); + } + 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 diff --git a/samples/OAuthClient/AzureAD.aspx.designer.cs b/samples/OAuthClient/AzureAD.aspx.designer.cs new file mode 100644 index 0000000..701a718 --- /dev/null +++ b/samples/OAuthClient/AzureAD.aspx.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace OAuthClient { + + + public partial class AzureAD { + + /// <summary> + /// form1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// <summary> + /// nameLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label nameLabel; + } +} diff --git a/samples/OAuthClient/Default.aspx b/samples/OAuthClient/Default.aspx index f832ccf..423bbe5 100644 --- a/samples/OAuthClient/Default.aspx +++ b/samples/OAuthClient/Default.aspx @@ -11,6 +11,7 @@ <li><a href="SignInWithTwitter.aspx">Sign In With Twitter</a></li> <li><a href="Facebook.aspx">Sign in with Facebook</a></li> <li><a href="WindowsLive.aspx">Sign in with Windows Live</a></li> + <li><a href="AzureAD.aspx">Sign in with Azure Active Directory\Office 365</a></li> <li><a href="SampleWcf2.aspx">Interop with Authorization Server sample (Authorization code grant) and Resource Server using WCF w/ OAuth 2.0 </a></li> <li><a href="SampleWcf2Javascript.html">Interop with Authorization Server sample (implicit grant) and Resource Server using WCF w/ OAuth 2.0 </a></li> </ul> diff --git a/samples/OAuthClient/OAuthClient.csproj b/samples/OAuthClient/OAuthClient.csproj index 036a913..9fbcc5d 100644 --- a/samples/OAuthClient/OAuthClient.csproj +++ b/samples/OAuthClient/OAuthClient.csproj @@ -70,6 +70,7 @@ <Reference Include="System.Xml.Linq" /> </ItemGroup> <ItemGroup> + <Content Include="AzureAD.aspx" /> <Content Include="Default.aspx" /> <Content Include="Facebook.aspx" /> <Content Include="favicon.ico" /> @@ -106,6 +107,13 @@ <Compile Include="..\DotNetOpenAuth.ApplicationBlock\InMemoryTokenManager.cs"> <Link>Code\InMemoryTokenManager.cs</Link> </Compile> + <Compile Include="AzureAD.aspx.cs"> + <DependentUpon>AzureAD.aspx</DependentUpon> + <SubType>ASPXCodeBehind</SubType> + </Compile> + <Compile Include="AzureAD.aspx.designer.cs"> + <DependentUpon>AzureAD.aspx</DependentUpon> + </Compile> <Compile Include="Facebook.aspx.cs"> <DependentUpon>Facebook.aspx</DependentUpon> <SubType>ASPXCodeBehind</SubType> diff --git a/samples/OAuthClient/Web.config b/samples/OAuthClient/Web.config index b17ae43..4311d72 100644 --- a/samples/OAuthClient/Web.config +++ b/samples/OAuthClient/Web.config @@ -55,6 +55,9 @@ <!-- Windows Live sign-up: http://go.microsoft.com/fwlink/p/?LinkId=193157 --> <add key="windowsLiveAppID" value="000000004408E558" /> <add key="windowsLiveAppSecret" value="od8NVdanEIWqmlKu9hOepBE3AfUu4jCw" /> + <!-- AzureAD sign-up: http://manage.windowsazure.com --> + <add key="AzureADAppID" value="64e0b14b-43ae-497c-b1a8-e8a841a341fd" /> + <add key="AzureADAppSecret" value="MySecretPassword" /> </appSettings> <connectionStrings/> |