diff options
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
4 files changed, 54 insertions, 1 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestAtRelyingPartyFactory.cs b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestAtRelyingPartyFactory.cs new file mode 100644 index 0000000..e8adfe3 --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestAtRelyingPartyFactory.cs @@ -0,0 +1,47 @@ +//----------------------------------------------------------------------- +// <copyright file="UIRequestAtRelyingPartyFactory.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions { + using System.Collections.Generic; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OpenId.ChannelElements; + using DotNetOpenAuth.OpenId.Extensions.UI; + + /// <summary> + /// An extension factory that allows the <see cref="UIRequest"/> extension to be received by the relying party. + /// </summary> + /// <remarks> + /// Typically UIRequest is only received by the Provider. But Google mirrors back this data to the relying party + /// if our web user is already logged into Google. + /// See the OpenIdRelyingPartyWebForms sample's DetectGoogleSession.aspx page for usage of this factory. + /// </remarks> + public class UIRequestAtRelyingPartyFactory : IOpenIdExtensionFactory { + /// <summary> + /// The Type URI for the UI extension. + /// </summary> + private const string UITypeUri = "http://specs.openid.net/extensions/ui/1.0"; + + /// <summary> + /// Allows UIRequest extensions to be received by the relying party. Useful when Google mirrors back the request + /// to indicate that a user is logged in. + /// </summary> + /// <param name="typeUri">The type URI of the extension.</param> + /// <param name="data">The parameters associated specifically with this extension.</param> + /// <param name="baseMessage">The OpenID message carrying this extension.</param> + /// <param name="isProviderRole">A value indicating whether this extension is being received at the OpenID Provider.</param> + /// <returns> + /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes + /// the extension described in the input parameters; <c>null</c> otherwise. + /// </returns> + public DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension Create(string typeUri, IDictionary<string, string> data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole) { + if (typeUri == UITypeUri && !isProviderRole) { + return new UIRequest(); + } + + return null; + } + } +} diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj index adb1998..5a3e532 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj +++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj @@ -87,6 +87,7 @@ <Compile Include="CustomExtensions\Acme.cs" /> <Compile Include="CustomExtensions\AcmeRequest.cs" /> <Compile Include="CustomExtensions\AcmeResponse.cs" /> + <Compile Include="CustomExtensions\UIRequestAtRelyingPartyFactory.cs" /> <Compile Include="GoogleConsumer.cs" /> <Compile Include="InMemoryTokenManager.cs"> <SubType>Code</SubType> diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs index 558d4bc..474a569 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs @@ -222,6 +222,11 @@ namespace DotNetOpenAuth.ApplicationBlock { { "max-results", maxResults.ToString(CultureInfo.InvariantCulture) }, }; var request = consumer.PrepareAuthorizedRequest(GetContactsEndpoint, accessToken, extraData); + + // Enable gzip compression. Google only compresses the response for recognized user agent headers. - Mike Lim + request.AutomaticDecompression = DecompressionMethods.GZip; + request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16"; + var response = consumer.Channel.WebRequestHandler.GetResponse(request); string body = response.GetResponseReader().ReadToEnd(); XDocument result = XDocument.Parse(body); diff --git a/samples/DotNetOpenAuth.ApplicationBlock/Util.cs b/samples/DotNetOpenAuth.ApplicationBlock/Util.cs index 4b4113d..0bec372 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/Util.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/Util.cs @@ -124,7 +124,7 @@ private readonly Action<HttpWebRequest> action; /// <summary> - /// Initializes a new instance of the <see cref="Util.WrappingWebRequestHandler"/> class. + /// Initializes a new instance of the <see cref="WrappingWebRequestHandler"/> class. /// </summary> /// <param name="wrappedHandler">The HTTP handler to wrap.</param> /// <param name="action">The action to perform on outgoing HTTP requests.</param> |