summaryrefslogtreecommitdiffstats
path: root/samples/OAuthClient
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OAuthClient')
-rw-r--r--samples/OAuthClient/Default.aspx1
-rw-r--r--samples/OAuthClient/OAuthClient.csproj9
-rw-r--r--samples/OAuthClient/SampleWcf2.aspx.cs6
-rw-r--r--samples/OAuthClient/Web.config3
-rw-r--r--samples/OAuthClient/WindowsLive.aspx29
-rw-r--r--samples/OAuthClient/WindowsLive.aspx.cs45
-rw-r--r--samples/OAuthClient/WindowsLive.aspx.designer.cs51
7 files changed, 141 insertions, 3 deletions
diff --git a/samples/OAuthClient/Default.aspx b/samples/OAuthClient/Default.aspx
index 0452033..f832ccf 100644
--- a/samples/OAuthClient/Default.aspx
+++ b/samples/OAuthClient/Default.aspx
@@ -10,6 +10,7 @@
<li><a href="Twitter.aspx">Get your Twitter updates</a></li>
<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="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 9c0b57a..65af47d 100644
--- a/samples/OAuthClient/OAuthClient.csproj
+++ b/samples/OAuthClient/OAuthClient.csproj
@@ -52,6 +52,7 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
+ <Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
@@ -75,6 +76,7 @@
<Content Include="SampleWcf2Javascript.js" />
<Content Include="Scripts\jquery-1.6.1.js" />
<Content Include="Scripts\jquery-1.6.1.min.js" />
+ <Content Include="WindowsLive.aspx" />
<Content Include="Yammer.aspx" />
<None Include="Service References\SampleResourceServer\DataApi.disco" />
<None Include="Service References\SampleResourceServer\configuration91.svcinfo" />
@@ -159,6 +161,13 @@
<Compile Include="Twitter.aspx.designer.cs">
<DependentUpon>Twitter.aspx</DependentUpon>
</Compile>
+ <Compile Include="WindowsLive.aspx.cs">
+ <DependentUpon>WindowsLive.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="WindowsLive.aspx.designer.cs">
+ <DependentUpon>WindowsLive.aspx</DependentUpon>
+ </Compile>
<Compile Include="Yammer.aspx.cs">
<DependentUpon>Yammer.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
diff --git a/samples/OAuthClient/SampleWcf2.aspx.cs b/samples/OAuthClient/SampleWcf2.aspx.cs
index 64a58e7..f4d2dd5 100644
--- a/samples/OAuthClient/SampleWcf2.aspx.cs
+++ b/samples/OAuthClient/SampleWcf2.aspx.cs
@@ -84,7 +84,7 @@
protected void getNameButton_Click(object sender, EventArgs e) {
try {
- this.nameLabel.Text = CallService(client => client.GetName());
+ this.nameLabel.Text = this.CallService(client => client.GetName());
} catch (SecurityAccessDeniedException) {
this.nameLabel.Text = "Access denied!";
}
@@ -92,7 +92,7 @@
protected void getAgeButton_Click(object sender, EventArgs e) {
try {
- int? age = CallService(client => client.GetAge());
+ int? age = this.CallService(client => client.GetAge());
this.ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
} catch (SecurityAccessDeniedException) {
this.ageLabel.Text = "Access denied!";
@@ -101,7 +101,7 @@
protected void getFavoriteSites_Click(object sender, EventArgs e) {
try {
- string[] favoriteSites = CallService(client => client.GetFavoriteSites());
+ string[] favoriteSites = this.CallService(client => client.GetFavoriteSites());
this.favoriteSitesLabel.Text = string.Join(", ", favoriteSites);
} catch (SecurityAccessDeniedException) {
this.favoriteSitesLabel.Text = "Access denied!";
diff --git a/samples/OAuthClient/Web.config b/samples/OAuthClient/Web.config
index 9fa30d9..1a54474 100644
--- a/samples/OAuthClient/Web.config
+++ b/samples/OAuthClient/Web.config
@@ -64,6 +64,9 @@
<!-- Facebook sign-up: http://developers.facebook.com/setup/ -->
<add key="facebookAppID" value="367207604173"/>
<add key="facebookAppSecret" value="1df77e64055c4d7d3583cefdf2bc62d7"/>
+ <!-- Windows Live sign-up: http://go.microsoft.com/fwlink/p/?LinkId=193157 -->
+ <add key="windowsLiveAppID" value="000000004408E558" />
+ <add key="windowsLiveAppSecret" value="od8NVdanEIWqmlKu9hOepBE3AfUu4jCw" />
</appSettings>
<connectionStrings/>
diff --git a/samples/OAuthClient/WindowsLive.aspx b/samples/OAuthClient/WindowsLive.aspx
new file mode 100644
index 0000000..5b8c8d4
--- /dev/null
+++ b/samples/OAuthClient/WindowsLive.aspx
@@ -0,0 +1,29 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WindowsLive.aspx.cs" Inherits="OAuthClient.WindowsLive" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title></title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <asp:Panel runat="server" ID="localhostDoesNotWorkPanel" Visible="False">
+ <p>
+ Windows Live requires a public domain (not localhost) that matches the registered
+ client app's callback URL. You can either host this sample on a public URL and register
+ your own client, or you can modify your "%windows%\system32\drivers\etc\hosts" file
+ to temporarily add this entry:
+ </p>
+ <pre>127.0.0.1 samples.dotnetopenauth.net</pre>
+ <p>
+ Then access this sample via this url:
+ <asp:HyperLink ID="publicLink" NavigateUrl="http://samples.dotnetopenauth.net:59721/WindowsLive.aspx"
+ runat="server">http://samples.dotnetopenauth.net:59721/WindowsLive.aspx</asp:HyperLink></p>
+ </asp:Panel>
+ <div>
+ Welcome,
+ <asp:Label Text="[name]" ID="nameLabel" runat="server" />
+ </div>
+ </form>
+</body>
+</html>
diff --git a/samples/OAuthClient/WindowsLive.aspx.cs b/samples/OAuthClient/WindowsLive.aspx.cs
new file mode 100644
index 0000000..b550e17
--- /dev/null
+++ b/samples/OAuthClient/WindowsLive.aspx.cs
@@ -0,0 +1,45 @@
+namespace OAuthClient {
+ using System;
+ using System.Collections.Generic;
+ using System.Configuration;
+ using System.Linq;
+ using System.Net;
+ using System.Web;
+ using System.Web.UI;
+ using System.Web.UI.WebControls;
+ using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.ApplicationBlock.Facebook;
+ using DotNetOpenAuth.OAuth2;
+
+ public partial class WindowsLive : System.Web.UI.Page {
+ private static readonly WindowsLiveClient client = new WindowsLiveClient {
+ ClientIdentifier = ConfigurationManager.AppSettings["windowsLiveAppID"],
+ ClientSecret = ConfigurationManager.AppSettings["WindowsLiveAppSecret"],
+ };
+
+ protected void Page_Load(object sender, EventArgs e) {
+ if (string.Equals("localhost", this.Request.Headers["Host"].Split(':')[0], StringComparison.OrdinalIgnoreCase)) {
+ this.localhostDoesNotWorkPanel.Visible = true;
+ var builder = new UriBuilder(this.publicLink.NavigateUrl);
+ builder.Port = this.Request.Url.Port;
+ this.publicLink.NavigateUrl = builder.Uri.AbsoluteUri;
+ this.publicLink.Text = builder.Uri.AbsoluteUri;
+ } else {
+ IAuthorizationState authorization = client.ProcessUserAuthorization();
+ if (authorization == null) {
+ // Kick off authorization request
+ client.RequestUserAuthorization(scope: new[] { WindowsLiveClient.Scopes.Basic }); // this scope isn't even required just to log in
+ } else {
+ var request =
+ WebRequest.Create("https://apis.live.net/v5.0/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
+ using (var response = request.GetResponse()) {
+ using (var responseStream = response.GetResponseStream()) {
+ var graph = WindowsLiveGraph.Deserialize(responseStream);
+ this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/samples/OAuthClient/WindowsLive.aspx.designer.cs b/samples/OAuthClient/WindowsLive.aspx.designer.cs
new file mode 100644
index 0000000..aa47128
--- /dev/null
+++ b/samples/OAuthClient/WindowsLive.aspx.designer.cs
@@ -0,0 +1,51 @@
+//------------------------------------------------------------------------------
+// <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 WindowsLive {
+
+ /// <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>
+ /// localhostDoesNotWorkPanel 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.Panel localhostDoesNotWorkPanel;
+
+ /// <summary>
+ /// publicLink 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.HyperLink publicLink;
+
+ /// <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;
+ }
+}