summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs2
-rw-r--r--samples/OAuthClient/OAuthClient.csproj5
-rw-r--r--samples/OAuthConsumerWpf/Authorize.xaml.cs17
-rw-r--r--samples/OAuthConsumerWpf/InMemoryTokenManager.cs58
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml19
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml.cs79
-rw-r--r--samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj1
-rw-r--r--samples/OAuthServiceProvider/Code/Constants.cs4
-rw-r--r--samples/OpenIdProviderWebForms/Code/OAuthHybrid.cs4
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Code/State.cs7
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Global.asax.cs32
-rw-r--r--samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs8
-rw-r--r--samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj3
-rw-r--r--samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs5
-rw-r--r--samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs25
15 files changed, 69 insertions, 200 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
index def378f..a7c062e 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
@@ -219,7 +219,7 @@ namespace DotNetOpenAuth.ApplicationBlock {
}
}
- public async Task PostBlogEntryAsync(AccessToken accessToken, string blogUrl, string title, XElement body, CancellationToken cancellationToken) {
+ public async Task PostBlogEntryAsync(AccessToken accessToken, string blogUrl, string title, XElement body, CancellationToken cancellationToken = default(CancellationToken)) {
string feedUrl;
var getBlogHome = WebRequest.Create(blogUrl);
using (var blogHomeResponse = getBlogHome.GetResponse()) {
diff --git a/samples/OAuthClient/OAuthClient.csproj b/samples/OAuthClient/OAuthClient.csproj
index eb216b1..3c94f38 100644
--- a/samples/OAuthClient/OAuthClient.csproj
+++ b/samples/OAuthClient/OAuthClient.csproj
@@ -102,9 +102,7 @@
</None>
</ItemGroup>
<ItemGroup>
- <Compile Include="..\DotNetOpenAuth.ApplicationBlock\InMemoryTokenManager.cs">
- <Link>Code\InMemoryTokenManager.cs</Link>
- </Compile>
+ <Compile Include="Code\Logging.cs" />
<Compile Include="Facebook.aspx.cs">
<DependentUpon>Facebook.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -134,7 +132,6 @@
<Compile Include="TracePage.aspx.designer.cs">
<DependentUpon>TracePage.aspx</DependentUpon>
</Compile>
- <Compile Include="Code\Logging.cs" />
<Compile Include="Code\TracePageAppender.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsLive.aspx.cs">
diff --git a/samples/OAuthConsumerWpf/Authorize.xaml.cs b/samples/OAuthConsumerWpf/Authorize.xaml.cs
index 92035d3..78c9c70 100644
--- a/samples/OAuthConsumerWpf/Authorize.xaml.cs
+++ b/samples/OAuthConsumerWpf/Authorize.xaml.cs
@@ -21,33 +21,28 @@
/// Interaction logic for Authorize.xaml
/// </summary>
public partial class Authorize : Window {
- private DesktopConsumer consumer;
- private string requestToken;
+ private Consumer consumer;
- internal Authorize(DesktopConsumer consumer, Func<DesktopConsumer, Task<Tuple<Uri, string>>> fetchUriCallback) {
+ internal Authorize(Consumer consumer, Func<Consumer, Task<Uri>> fetchUriCallback) {
this.InitializeComponent();
this.consumer = consumer;
Cursor original = this.Cursor;
this.Cursor = Cursors.Wait;
Task.Run(async delegate {
- var tuple = await fetchUriCallback(this.consumer);
- Uri browserAuthorizationLocation = tuple.Item1;
- this.requestToken = tuple.Item2;
+ Uri browserAuthorizationLocation = await fetchUriCallback(this.consumer);
System.Diagnostics.Process.Start(browserAuthorizationLocation.AbsoluteUri);
- this.Dispatcher.BeginInvoke(new Action(() => {
+ await this.Dispatcher.BeginInvoke(new Action(() => {
this.Cursor = original;
finishButton.IsEnabled = true;
}));
});
}
- internal delegate Uri FetchUri(DesktopConsumer consumer, out string requestToken);
-
- internal string AccessToken { get; set; }
+ internal AccessToken AccessToken { get; set; }
private async void finishButton_Click(object sender, RoutedEventArgs e) {
- var grantedAccess = await this.consumer.ProcessUserAuthorizationAsync(this.requestToken, this.verifierBox.Text);
+ var grantedAccess = await this.consumer.ProcessUserAuthorizationAsync(this.verifierBox.Text);
this.AccessToken = grantedAccess.AccessToken;
DialogResult = true;
Close();
diff --git a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
deleted file mode 100644
index 5266404..0000000
--- a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="InMemoryTokenManager.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using DotNetOpenAuth.OAuth.ChannelElements;
- using DotNetOpenAuth.OAuth.Messages;
-
- internal class InMemoryTokenManager : IConsumerTokenManager {
- private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
-
- internal InMemoryTokenManager() {
- }
-
- public string ConsumerKey { get; internal set; }
-
- public string ConsumerSecret { get; internal set; }
-
- #region ITokenManager Members
-
- public string GetConsumerSecret(string consumerKey) {
- if (consumerKey == this.ConsumerKey) {
- return this.ConsumerSecret;
- } else {
- throw new ArgumentException("Unrecognized consumer key.", "consumerKey");
- }
- }
-
- public string GetTokenSecret(string token) {
- return this.tokensAndSecrets[token];
- }
-
- public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response) {
- this.tokensAndSecrets[response.Token] = response.TokenSecret;
- }
-
- public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
- this.tokensAndSecrets.Remove(requestToken);
- this.tokensAndSecrets[accessToken] = accessTokenSecret;
- }
-
- /// <summary>
- /// Classifies a token as a request token or an access token.
- /// </summary>
- /// <param name="token">The token to classify.</param>
- /// <returns>Request or Access token, or invalid if the token is not recognized.</returns>
- public TokenType GetTokenType(string token) {
- throw new NotImplementedException();
- }
-
- #endregion
- }
-}
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml b/samples/OAuthConsumerWpf/MainWindow.xaml
index 48eb0c4..d89d489 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml
@@ -92,23 +92,13 @@
</Grid.ColumnDefinitions>
<Label Grid.Row="0">Request Token URL</Label>
<TextBox Grid.Column="1" x:Name="requestTokenUrlBox" />
- <ComboBox Grid.Column="2" x:Name="requestTokenHttpMethod" SelectedIndex="1">
- <ComboBox.Items>
- <ComboBoxItem>GET</ComboBoxItem>
- <ComboBoxItem>POST</ComboBoxItem>
- </ComboBox.Items>
- </ComboBox>
+ <Label Grid.Column="2">POST</Label>
<Label Grid.Row="1">Authorize URL</Label>
<TextBox Grid.Row="1" Grid.Column="1" x:Name="authorizeUrlBox" />
<Label Grid.Row="1" Grid.Column="2">GET</Label>
<Label Grid.Row="2">Access Token URL</Label>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="accessTokenUrlBox" />
- <ComboBox Grid.Row="2" Grid.Column="2" x:Name="accessTokenHttpMethod" SelectedIndex="1">
- <ComboBox.Items>
- <ComboBoxItem>GET</ComboBoxItem>
- <ComboBoxItem>POST</ComboBoxItem>
- </ComboBox.Items>
- </ComboBox>
+ <Label Grid.Row="2" Grid.Column="2">POST</Label>
<Label Grid.Row="3">Resource URL</Label>
<TextBox Grid.Row="3" Grid.Column="1" x:Name="resourceUrlBox" />
<ComboBox Grid.Row="3" Grid.Column="2" x:Name="resourceHttpMethodList" SelectedIndex="0">
@@ -123,10 +113,9 @@
<Label Grid.Row="5">Consumer secret</Label>
<TextBox Grid.Row="5" Grid.Column="1" x:Name="consumerSecretBox" Grid.ColumnSpan="2"/>
<Label Grid.Row="6">OAuth version</Label>
- <ComboBox Grid.Row="6" Grid.Column="1" SelectedIndex="1" x:Name="oauthVersion">
+ <ComboBox Grid.Row="6" Grid.Column="1" SelectedIndex="0" x:Name="oauthVersion">
<ComboBox.Items>
- <ComboBoxItem>1.0</ComboBoxItem>
- <ComboBoxItem>1.0a</ComboBoxItem>
+ <ComboBoxItem>RFC 5849</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
<Button Grid.Row="7" Grid.Column="1" x:Name="beginButton" Click="beginButton_Click">Begin</Button>
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
index 1e1f1ab..a2cdfe9 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
@@ -28,9 +28,8 @@
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
- private InMemoryTokenManager googleTokenManager = new InMemoryTokenManager();
- private DesktopConsumer google;
- private string googleAccessToken;
+ private GoogleConsumer google;
+ private DotNetOpenAuth.OAuth.AccessToken googleAccessToken;
private UserAgentClient wcf;
private IAuthorizationState wcfAccessToken;
@@ -42,17 +41,12 @@
}
private void InitializeGoogleConsumer() {
- this.googleTokenManager.ConsumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
- this.googleTokenManager.ConsumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
-
string pfxFile = ConfigurationManager.AppSettings["googleConsumerCertificateFile"];
- if (string.IsNullOrEmpty(pfxFile)) {
- this.google = new DesktopConsumer(GoogleConsumer.ServiceDescription, this.googleTokenManager);
- } else {
+ this.google = new GoogleConsumer();
+ if (!string.IsNullOrEmpty(pfxFile)) {
string pfxPassword = ConfigurationManager.AppSettings["googleConsumerCertificatePassword"];
var signingCertificate = new X509Certificate2(pfxFile, pfxPassword);
- var service = GoogleConsumer.CreateRsaSha1ServiceDescription(signingCertificate);
- this.google = new DesktopConsumer(service, this.googleTokenManager);
+ this.google.ConsumerCertificate = signingCertificate;
}
}
@@ -65,7 +59,7 @@
}
private async void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) {
- if (string.IsNullOrEmpty(this.googleTokenManager.ConsumerKey)) {
+ if (string.IsNullOrEmpty(this.google.ConsumerKey)) {
MessageBox.Show(this, "You must modify the App.config or OAuthConsumerWpf.exe.config file for this application to include your Google OAuth consumer key first.", "Configuration required", MessageBoxButton.OK, MessageBoxImage.Stop);
return;
}
@@ -73,15 +67,13 @@
var auth = new Authorize(
this.google,
consumer =>
- GoogleConsumer.RequestAuthorizationAsync(
- consumer,
- GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger));
+ ((GoogleConsumer)consumer).RequestUserAuthorizationAsync(GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger));
bool? result = auth.ShowDialog();
if (result.HasValue && result.Value) {
this.googleAccessToken = auth.AccessToken;
this.postButton.IsEnabled = true;
- XDocument contactsDocument = await GoogleConsumer.GetContactsAsync(this.google, this.googleAccessToken);
+ XDocument contactsDocument = await this.google.GetContactsAsync(this.googleAccessToken);
var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value };
this.contactsGrid.Children.Clear();
@@ -100,7 +92,7 @@
private async void postButton_Click(object sender, RoutedEventArgs e) {
XElement postBodyXml = XElement.Parse(this.postBodyBox.Text);
- await GoogleConsumer.PostBlogEntryAsync(this.google, this.googleAccessToken, this.blogUrlBox.Text, this.postTitleBox.Text, postBodyXml, CancellationToken.None);
+ await this.google.PostBlogEntryAsync(this.googleAccessToken, this.blogUrlBox.Text, this.postTitleBox.Text, postBodyXml);
}
private async void beginWcfAuthorizationButton_Click(object sender, RoutedEventArgs e) {
@@ -136,48 +128,27 @@
private async void beginButton_Click(object sender, RoutedEventArgs e) {
try {
- var service = new ServiceProviderDescription {
- RequestTokenEndpoint =
- new MessageReceivingEndpoint(
- this.requestTokenUrlBox.Text,
- this.requestTokenHttpMethod.SelectedIndex == 0 ? HttpDeliveryMethods.GetRequest : HttpDeliveryMethods.PostRequest),
- UserAuthorizationEndpoint = new MessageReceivingEndpoint(this.authorizeUrlBox.Text, HttpDeliveryMethods.GetRequest),
- AccessTokenEndpoint =
- new MessageReceivingEndpoint(
- this.accessTokenUrlBox.Text,
- this.accessTokenHttpMethod.SelectedIndex == 0 ? HttpDeliveryMethods.GetRequest : HttpDeliveryMethods.PostRequest),
- TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
- ProtocolVersion = this.oauthVersion.SelectedIndex == 0 ? ProtocolVersion.V10 : ProtocolVersion.V10a,
- };
- var tokenManager = new InMemoryTokenManager();
- tokenManager.ConsumerKey = this.consumerKeyBox.Text;
- tokenManager.ConsumerSecret = this.consumerSecretBox.Text;
-
- var consumer = new DesktopConsumer(service, tokenManager);
- string accessToken;
- if (service.ProtocolVersion == ProtocolVersion.V10) {
- var tuple = await consumer.RequestUserAuthorizationAsync(null, null);
- Uri authorizeUrl = tuple.Item1;
- string requestToken = tuple.Item2;
- Process.Start(authorizeUrl.AbsoluteUri);
- MessageBox.Show(this, "Click OK when you've authorized the app.");
- var authorizationResponse = await consumer.ProcessUserAuthorizationAsync(requestToken, null);
- accessToken = authorizationResponse.AccessToken;
+ var service = new ServiceProviderDescription(
+ this.requestTokenUrlBox.Text,
+ this.authorizeUrlBox.Text,
+ this.accessTokenUrlBox.Text);
+
+ var consumer = new Consumer(this.consumerKeyBox.Text, this.consumerSecretBox.Text, service, new MemoryTemporaryCredentialStorage());
+ DotNetOpenAuth.OAuth.AccessToken accessToken;
+ var authorizePopup = new Authorize(consumer, c => c.RequestUserAuthorizationAsync(null, null));
+ authorizePopup.Owner = this;
+ bool? result = authorizePopup.ShowDialog();
+ if (result.HasValue && result.Value) {
+ accessToken = authorizePopup.AccessToken;
} else {
- var authorizePopup = new Authorize(consumer, c => c.RequestUserAuthorizationAsync(null, null));
- authorizePopup.Owner = this;
- bool? result = authorizePopup.ShowDialog();
- if (result.HasValue && result.Value) {
- accessToken = authorizePopup.AccessToken;
- } else {
- return;
- }
+ return;
}
+
HttpMethod resourceHttpMethod = this.resourceHttpMethodList.SelectedIndex < 2 ? HttpMethod.Get : HttpMethod.Post;
using (var handler = consumer.CreateMessageHandler(accessToken)) {
handler.Location = this.resourceHttpMethodList.SelectedIndex == 1
- ? OAuth1HttpMessageHandlerBase.OAuthParametersLocation.AuthorizationHttpHeader
- : OAuth1HttpMessageHandlerBase.OAuthParametersLocation.QueryString;
+ ? OAuth1HttpMessageHandlerBase.OAuthParametersLocation.AuthorizationHttpHeader
+ : OAuth1HttpMessageHandlerBase.OAuthParametersLocation.QueryString;
using (var httpClient = consumer.CreateHttpClient(handler)) {
var request = new HttpRequestMessage(resourceHttpMethod, this.resourceUrlBox.Text);
using (var resourceResponse = await httpClient.SendAsync(request)) {
diff --git a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
index 2ef9b6f..ee06daa 100644
--- a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
+++ b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
@@ -153,7 +153,6 @@
<Compile Include="Authorize.xaml.cs">
<DependentUpon>Authorize.xaml</DependentUpon>
</Compile>
- <Compile Include="InMemoryTokenManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
diff --git a/samples/OAuthServiceProvider/Code/Constants.cs b/samples/OAuthServiceProvider/Code/Constants.cs
index 3e629f0..9115f1c 100644
--- a/samples/OAuthServiceProvider/Code/Constants.cs
+++ b/samples/OAuthServiceProvider/Code/Constants.cs
@@ -10,9 +10,9 @@
public static class Constants {
public static Uri WebRootUrl { get; set; }
- public static ServiceProviderDescription SelfDescription {
+ public static ServiceProviderHostDescription SelfDescription {
get {
- ServiceProviderDescription description = new ServiceProviderDescription {
+ var description = new ServiceProviderHostDescription {
AccessTokenEndpoint = new MessageReceivingEndpoint(new Uri(WebRootUrl, "/OAuth.ashx"), HttpDeliveryMethods.PostRequest),
RequestTokenEndpoint = new MessageReceivingEndpoint(new Uri(WebRootUrl, "/OAuth.ashx"), HttpDeliveryMethods.PostRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint(new Uri(WebRootUrl, "/OAuth.ashx"), HttpDeliveryMethods.PostRequest),
diff --git a/samples/OpenIdProviderWebForms/Code/OAuthHybrid.cs b/samples/OpenIdProviderWebForms/Code/OAuthHybrid.cs
index 8e64bfb..f96e87e 100644
--- a/samples/OpenIdProviderWebForms/Code/OAuthHybrid.cs
+++ b/samples/OpenIdProviderWebForms/Code/OAuthHybrid.cs
@@ -37,8 +37,8 @@ namespace OpenIdProviderWebForms.Code {
internal static ServiceProviderOpenIdProvider ServiceProvider { get; private set; }
- internal static ServiceProviderDescription GetServiceDescription() {
- return new ServiceProviderDescription {
+ internal static ServiceProviderHostDescription GetServiceDescription() {
+ return new ServiceProviderHostDescription {
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
};
}
diff --git a/samples/OpenIdRelyingPartyWebForms/Code/State.cs b/samples/OpenIdRelyingPartyWebForms/Code/State.cs
index c8147e5..c8cef80 100644
--- a/samples/OpenIdRelyingPartyWebForms/Code/State.cs
+++ b/samples/OpenIdRelyingPartyWebForms/Code/State.cs
@@ -1,5 +1,6 @@
namespace OpenIdRelyingPartyWebForms {
using System.Web;
+ using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
@@ -28,8 +29,8 @@ namespace OpenIdRelyingPartyWebForms {
set { HttpContext.Current.Session["PapePolicies"] = value; }
}
- public static string GoogleAccessToken {
- get { return HttpContext.Current.Session["GoogleAccessToken"] as string; }
+ public static AccessToken GoogleAccessToken {
+ get { return (AccessToken)(HttpContext.Current.Session["GoogleAccessToken"] ?? new AccessToken()); }
set { HttpContext.Current.Session["GoogleAccessToken"] = value; }
}
@@ -38,7 +39,7 @@ namespace OpenIdRelyingPartyWebForms {
FetchResponse = null;
FriendlyLoginName = null;
PapePolicies = null;
- GoogleAccessToken = null;
+ GoogleAccessToken = new AccessToken();
}
}
} \ No newline at end of file
diff --git a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
index 6283987..8460d49 100644
--- a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
+++ b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
@@ -18,7 +18,7 @@
get {
var googleWebConsumer = (WebConsumerOpenIdRelyingParty)HttpContext.Current.Application["GoogleWebConsumer"];
if (googleWebConsumer == null) {
- googleWebConsumer = new WebConsumerOpenIdRelyingParty(GoogleConsumer.ServiceDescription, GoogleTokenManager);
+ googleWebConsumer = new WebConsumerOpenIdRelyingParty { ServiceProvider = GoogleConsumer.ServiceDescription };
HttpContext.Current.Application["GoogleWebConsumer"] = googleWebConsumer;
}
@@ -26,36 +26,6 @@
}
}
- internal static InMemoryTokenManager GoogleTokenManager {
- get {
- var tokenManager = (InMemoryTokenManager)HttpContext.Current.Application["GoogleTokenManager"];
- if (tokenManager == null) {
- string consumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
- string consumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
- if (!string.IsNullOrEmpty(consumerKey)) {
- tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
- HttpContext.Current.Application["GoogleTokenManager"] = tokenManager;
- }
- }
-
- return tokenManager;
- }
- }
-
- internal static InMemoryTokenManager OwnSampleOPHybridTokenManager {
- get {
- var tokenManager = (InMemoryTokenManager)HttpContext.Current.Application["OwnSampleOPHybridTokenManager"];
- if (tokenManager == null) {
- string consumerKey = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Request.ApplicationPath).AbsoluteUri;
- string consumerSecret = "some crazy secret";
- tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
- HttpContext.Current.Application["OwnSampleOPHybridTokenManager"] = tokenManager;
- }
-
- return tokenManager;
- }
- }
-
public static string ToString(NameValueCollection collection) {
using (StringWriter sw = new StringWriter()) {
foreach (string key in collection.Keys) {
diff --git a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs
index 2cbac9a..2b3b51d 100644
--- a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs
+++ b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs
@@ -10,7 +10,7 @@
public partial class DisplayGoogleContacts : System.Web.UI.Page {
protected async void Page_Load(object sender, EventArgs e) {
- if (!string.IsNullOrEmpty(State.GoogleAccessToken)) {
+ if (!string.IsNullOrEmpty(State.GoogleAccessToken.Token)) {
this.MultiView1.ActiveViewIndex = 1;
if (State.FetchResponse != null && State.FetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email)) {
this.emailLabel.Text = State.FetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values[0];
@@ -18,7 +18,11 @@
this.emailLabel.Text = "unavailable";
}
this.claimedIdLabel.Text = this.User.Identity.Name;
- var contactsDocument = await GoogleConsumer.GetContactsAsync(Global.GoogleWebConsumer, State.GoogleAccessToken, cancellationToken: Response.ClientDisconnectedToken);
+ var google = new GoogleConsumer {
+ ConsumerKey = Global.GoogleWebConsumer.ConsumerKey,
+ ConsumerSecret = Global.GoogleWebConsumer.ConsumerSecret,
+ };
+ var contactsDocument = await google.GetContactsAsync(State.GoogleAccessToken);
this.RenderContacts(contactsDocument);
}
}
diff --git a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
index cf12262..7c6d03a 100644
--- a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
+++ b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
@@ -100,9 +100,6 @@
</Content>
</ItemGroup>
<ItemGroup>
- <Compile Include="..\DotNetOpenAuth.ApplicationBlock\InMemoryTokenManager.cs">
- <Link>Code\InMemoryTokenManager.cs</Link>
- </Compile>
<Compile Include="ajaxlogin.aspx.cs">
<DependentUpon>ajaxlogin.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs
index bffd539..0e6eae0 100644
--- a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs
+++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs
@@ -4,6 +4,7 @@
using System.Web;
using System.Web.Security;
using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.Messages;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
@@ -25,7 +26,7 @@
switch (authResponse.Status) {
case AuthenticationStatus.Authenticated:
State.FetchResponse = authResponse.GetExtension<FetchResponse>();
- AuthorizedTokenResponse accessToken = await Global.GoogleWebConsumer.ProcessUserAuthorizationAsync(authResponse, Response.ClientDisconnectedToken);
+ AccessTokenResponse accessToken = await Global.GoogleWebConsumer.ProcessUserAuthorizationAsync(authResponse, Response.ClientDisconnectedToken);
if (accessToken != null) {
State.GoogleAccessToken = accessToken.AccessToken;
FormsAuthentication.SetAuthCookie(authResponse.ClaimedIdentifier, false);
@@ -56,7 +57,7 @@
// that is properly registered with Google.
// We will customize the realm to use http or https based on what the
// return_to URL will be (which will be this page).
- Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/";
+ Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + (new GoogleConsumer()).ConsumerKey + "/";
IAuthenticationRequest authReq = await relyingParty.CreateRequestAsync(GoogleOPIdentifier, realm, cancellationToken: Response.ClientDisconnectedToken);
// Prepare the OAuth extension
diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs
index 91ec642..6133a86 100644
--- a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs
+++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs
@@ -1,5 +1,6 @@
namespace OpenIdRelyingPartyWebForms {
using System;
+ using System.Web;
using System.Web.Security;
using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.Messaging;
@@ -23,24 +24,19 @@
}
protected void identifierBox_LoggingIn(object sender, OpenIdEventArgs e) {
- ServiceProviderDescription serviceDescription = new ServiceProviderDescription {
- TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
- };
-
- var consumer = new WebConsumerOpenIdRelyingParty(serviceDescription, Global.OwnSampleOPHybridTokenManager);
+ var consumer = CreateConsumer();
consumer.AttachAuthorizationRequest(e.Request, "http://tempuri.org/IDataApi/GetName");
}
protected async void identifierBox_LoggedIn(object sender, OpenIdEventArgs e) {
State.FetchResponse = e.Response.GetExtension<FetchResponse>();
- ServiceProviderDescription serviceDescription = new ServiceProviderDescription {
- AccessTokenEndpoint = new MessageReceivingEndpoint(new Uri(e.Response.Provider.Uri, "/access_token.ashx"), HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
- TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
+ var serviceDescription = new ServiceProviderDescription {
+ TokenRequestEndpoint = new Uri(e.Response.Provider.Uri, "/access_token.ashx"),
};
- var consumer = new WebConsumerOpenIdRelyingParty(serviceDescription, Global.OwnSampleOPHybridTokenManager);
-
- AuthorizedTokenResponse accessToken = await consumer.ProcessUserAuthorizationAsync(e.Response);
+ var consumer = CreateConsumer();
+ consumer.ServiceProvider = serviceDescription;
+ AccessTokenResponse accessToken = await consumer.ProcessUserAuthorizationAsync(e.Response);
if (accessToken != null) {
this.MultiView1.SetActiveView(this.AuthorizationGiven);
@@ -58,5 +54,12 @@
protected void identifierBox_Failed(object sender, OpenIdEventArgs e) {
this.MultiView1.SetActiveView(this.AuthenticationFailed);
}
+
+ private static WebConsumerOpenIdRelyingParty CreateConsumer() {
+ var consumer = new WebConsumerOpenIdRelyingParty();
+ consumer.ConsumerKey = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Request.ApplicationPath).AbsoluteUri;
+ consumer.ConsumerSecret = "some crazy secret";
+ return consumer;
+ }
}
}