summaryrefslogtreecommitdiffstats
path: root/samples/OAuthConsumer
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OAuthConsumer')
-rw-r--r--samples/OAuthConsumer/Default.aspx2
-rw-r--r--samples/OAuthConsumer/OAuthConsumer.csproj8
-rw-r--r--samples/OAuthConsumer/SampleWcf.aspx23
-rw-r--r--samples/OAuthConsumer/SampleWcf.aspx.cs119
-rw-r--r--samples/OAuthConsumer/SampleWcf.aspx.designer.cs96
-rw-r--r--samples/OAuthConsumer/SampleWcf2.aspx2
-rw-r--r--samples/OAuthConsumer/SampleWcf2.aspx.cs5
7 files changed, 5 insertions, 250 deletions
diff --git a/samples/OAuthConsumer/Default.aspx b/samples/OAuthConsumer/Default.aspx
index f3bceb6..140f002 100644
--- a/samples/OAuthConsumer/Default.aspx
+++ b/samples/OAuthConsumer/Default.aspx
@@ -10,6 +10,6 @@
<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="SampleWcf.aspx">Interop with Service Provider sample using WCF w/ OAuth</a></li>
+ <li><a href="SampleWcf2.aspx">Interop with Service Provider sample using WCF w/ OAuth 2.0</a></li>
</ul>
</asp:Content>
diff --git a/samples/OAuthConsumer/OAuthConsumer.csproj b/samples/OAuthConsumer/OAuthConsumer.csproj
index 698de7a..a4ae9ec 100644
--- a/samples/OAuthConsumer/OAuthConsumer.csproj
+++ b/samples/OAuthConsumer/OAuthConsumer.csproj
@@ -63,7 +63,6 @@
<Content Include="Global.asax" />
<Content Include="GoogleAddressBook.aspx" />
<Content Include="images\Sign-in-with-Twitter-darker.png" />
- <Content Include="SampleWcf.aspx" />
<Content Include="Yammer.aspx" />
<None Include="Service References\SampleServiceProvider\DataApi.disco" />
<None Include="Service References\SampleServiceProvider\configuration91.svcinfo" />
@@ -101,13 +100,6 @@
<Compile Include="GoogleAddressBook.aspx.designer.cs">
<DependentUpon>GoogleAddressBook.aspx</DependentUpon>
</Compile>
- <Compile Include="SampleWcf.aspx.cs">
- <DependentUpon>SampleWcf.aspx</DependentUpon>
- <SubType>ASPXCodeBehind</SubType>
- </Compile>
- <Compile Include="SampleWcf.aspx.designer.cs">
- <DependentUpon>SampleWcf.aspx</DependentUpon>
- </Compile>
<Compile Include="SampleWcf2.aspx.cs">
<DependentUpon>SampleWcf2.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
diff --git a/samples/OAuthConsumer/SampleWcf.aspx b/samples/OAuthConsumer/SampleWcf.aspx
deleted file mode 100644
index fcec089..0000000
--- a/samples/OAuthConsumer/SampleWcf.aspx
+++ /dev/null
@@ -1,23 +0,0 @@
-<%@ Page Title="OAuth 1.0a consumer" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="OAuthConsumer.SampleWcf" Codebehind="SampleWcf.aspx.cs" %>
-
-<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server">
- <fieldset title="Authorization">
- <asp:CheckBoxList runat="server" ID="scopeList">
- <asp:ListItem Value="http://tempuri.org/IDataApi/GetName">GetName</asp:ListItem>
- <asp:ListItem Value="http://tempuri.org/IDataApi/GetAge">GetAge</asp:ListItem>
- <asp:ListItem Value="http://tempuri.org/IDataApi/GetFavoriteSites">GetFavoriteSites</asp:ListItem>
- </asp:CheckBoxList>
- <asp:Button ID="getAuthorizationButton" runat="server" Text="Get Authorization" OnClick="getAuthorizationButton_Click" />
- <asp:Label ID="authorizationLabel" runat="server" />
- </fieldset>
- <br />
- <asp:Button ID="getNameButton" runat="server" Text="Get Name" OnClick="getNameButton_Click" />
- <asp:Label ID="nameLabel" runat="server" />
- <br />
- <asp:Button ID="getAgeButton" runat="server" Text="Get Age" OnClick="getAgeButton_Click" />
- <asp:Label ID="ageLabel" runat="server" />
- <br />
- <asp:Button ID="getFavoriteSites" runat="server" Text="Get Favorite Sites"
- onclick="getFavoriteSites_Click" />
- <asp:Label ID="favoriteSitesLabel" runat="server" />
-</asp:Content>
diff --git a/samples/OAuthConsumer/SampleWcf.aspx.cs b/samples/OAuthConsumer/SampleWcf.aspx.cs
deleted file mode 100644
index 74c6e6a..0000000
--- a/samples/OAuthConsumer/SampleWcf.aspx.cs
+++ /dev/null
@@ -1,119 +0,0 @@
-namespace OAuthConsumer {
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Net;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Security;
- using System.Web.UI.WebControls;
- using DotNetOpenAuth;
- using DotNetOpenAuth.ApplicationBlock;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth;
- using DotNetOpenAuth.OAuth.ChannelElements;
- using OAuthConsumer.SampleServiceProvider;
-
- /// <summary>
- /// Sample consumer of our Service Provider sample's WCF service.
- /// </summary>
- public partial class SampleWcf : System.Web.UI.Page {
- protected void Page_Load(object sender, EventArgs e) {
- if (!IsPostBack) {
- if (Session["WcfTokenManager"] != null) {
- WebConsumer consumer = this.CreateConsumer();
- var accessTokenMessage = consumer.ProcessUserAuthorization();
- if (accessTokenMessage != null) {
- Session["WcfAccessToken"] = accessTokenMessage.AccessToken;
- this.authorizationLabel.Text = "Authorized! Access token: " + accessTokenMessage.AccessToken;
- }
- }
- }
- }
-
- protected void getAuthorizationButton_Click(object sender, EventArgs e) {
- WebConsumer consumer = this.CreateConsumer();
- UriBuilder callback = new UriBuilder(Request.Url);
- callback.Query = null;
- string[] scopes = (from item in this.scopeList.Items.OfType<ListItem>()
- where item.Selected
- select item.Value).ToArray();
- string scope = string.Join(" ", scopes);
- var requestParams = new Dictionary<string, string> {
- { "scope", scope },
- };
- var response = consumer.PrepareRequestUserAuthorization(callback.Uri, requestParams, null);
- consumer.Channel.Send(response);
- }
-
- protected void getNameButton_Click(object sender, EventArgs e) {
- try {
- this.nameLabel.Text = CallService(client => client.GetName());
- } catch (SecurityAccessDeniedException) {
- this.nameLabel.Text = "Access denied!";
- }
- }
-
- protected void getAgeButton_Click(object sender, EventArgs e) {
- try {
- int? age = CallService(client => client.GetAge());
- this.ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
- } catch (SecurityAccessDeniedException) {
- this.ageLabel.Text = "Access denied!";
- }
- }
-
- protected void getFavoriteSites_Click(object sender, EventArgs e) {
- try {
- string[] favoriteSites = CallService(client => client.GetFavoriteSites());
- this.favoriteSitesLabel.Text = string.Join(", ", favoriteSites);
- } catch (SecurityAccessDeniedException) {
- this.favoriteSitesLabel.Text = "Access denied!";
- }
- }
-
- private T CallService<T>(Func<DataApiClient, T> predicate) {
- DataApiClient client = new DataApiClient();
- var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
- var accessToken = Session["WcfAccessToken"] as string;
- if (accessToken == null) {
- throw new InvalidOperationException("No access token!");
- }
- WebConsumer consumer = this.CreateConsumer();
- WebRequest httpRequest = consumer.PrepareAuthorizedRequest(serviceEndpoint, accessToken);
-
- var httpDetails = new HttpRequestMessageProperty();
- httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
- using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) {
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
- return predicate(client);
- }
- }
-
- private WebConsumer CreateConsumer() {
- string consumerKey = "sampleconsumer";
- string consumerSecret = "samplesecret";
- var tokenManager = Session["WcfTokenManager"] as InMemoryTokenManager;
- if (tokenManager == null) {
- tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
- Session["WcfTokenManager"] = tokenManager;
- }
- MessageReceivingEndpoint oauthEndpoint = new MessageReceivingEndpoint(
- new Uri("http://localhost:65169/OAuth.ashx"),
- HttpDeliveryMethods.PostRequest);
- WebConsumer consumer = new WebConsumer(
- new ServiceProviderDescription {
- RequestTokenEndpoint = oauthEndpoint,
- UserAuthorizationEndpoint = oauthEndpoint,
- AccessTokenEndpoint = oauthEndpoint,
- TamperProtectionElements = new DotNetOpenAuth.Messaging.ITamperProtectionChannelBindingElement[] {
- new HmacSha1SigningBindingElement(),
- },
- },
- tokenManager);
-
- return consumer;
- }
- }
-} \ No newline at end of file
diff --git a/samples/OAuthConsumer/SampleWcf.aspx.designer.cs b/samples/OAuthConsumer/SampleWcf.aspx.designer.cs
deleted file mode 100644
index c041338..0000000
--- a/samples/OAuthConsumer/SampleWcf.aspx.designer.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-//------------------------------------------------------------------------------
-// <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 OAuthConsumer {
-
-
- public partial class SampleWcf {
-
- /// <summary>
- /// scopeList 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.CheckBoxList scopeList;
-
- /// <summary>
- /// getAuthorizationButton 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.Button getAuthorizationButton;
-
- /// <summary>
- /// authorizationLabel 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 authorizationLabel;
-
- /// <summary>
- /// getNameButton 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.Button getNameButton;
-
- /// <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;
-
- /// <summary>
- /// getAgeButton 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.Button getAgeButton;
-
- /// <summary>
- /// ageLabel 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 ageLabel;
-
- /// <summary>
- /// getFavoriteSites 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.Button getFavoriteSites;
-
- /// <summary>
- /// favoriteSitesLabel 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 favoriteSitesLabel;
- }
-}
diff --git a/samples/OAuthConsumer/SampleWcf2.aspx b/samples/OAuthConsumer/SampleWcf2.aspx
index 797a2fc..0e58c74 100644
--- a/samples/OAuthConsumer/SampleWcf2.aspx
+++ b/samples/OAuthConsumer/SampleWcf2.aspx
@@ -7,7 +7,7 @@
<asp:ListItem Value="http://tempuri.org/IDataApi/GetAge">GetAge</asp:ListItem>
<asp:ListItem Value="http://tempuri.org/IDataApi/GetFavoriteSites">GetFavoriteSites</asp:ListItem>
</asp:CheckBoxList>
- <asp:Button ID="getAuthorizationButton" runat="server" Text="Get Authorization" OnClick="getAuthorizationButton_Click" />
+ <asp:Button ID="getAuthorizationButton" runat="server" Text="Request Authorization" OnClick="getAuthorizationButton_Click" />
<asp:Label ID="authorizationLabel" runat="server" />
</fieldset>
<br />
diff --git a/samples/OAuthConsumer/SampleWcf2.aspx.cs b/samples/OAuthConsumer/SampleWcf2.aspx.cs
index deef073..7978f91 100644
--- a/samples/OAuthConsumer/SampleWcf2.aspx.cs
+++ b/samples/OAuthConsumer/SampleWcf2.aspx.cs
@@ -19,8 +19,8 @@
/// The details about the sample OAuth-enabled WCF service that this sample client calls into.
/// </summary>
private static AuthorizationServerDescription AuthServerDescription = new AuthorizationServerDescription {
- TokenEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/token"),
- AuthorizationEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/auth"),
+ TokenEndpoint = new Uri("http://localhost:65169/OAuth.ashx"),
+ AuthorizationEndpoint = new Uri("http://localhost:65169/Members/Authorize.aspx"),
};
/// <summary>
@@ -55,6 +55,7 @@
if (authorization != null) {
// We are receiving an authorization response. Store it and associate it with this user.
Authorization = authorization;
+ Response.Redirect(Request.Path); // get rid of the /?code= parameter
}
}
}