diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-15 14:19:22 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-15 14:19:22 -0700 |
commit | c925ab3d2c5697c9f5f6e57aa58a042f49cf8ecd (patch) | |
tree | 22137d6e7d261cc437ed9d9fbd25b13d9d7e7639 /samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs | |
parent | afe5a981369ebbb1436d2f388c448da8451bb609 (diff) | |
download | DotNetOpenAuth-c925ab3d2c5697c9f5f6e57aa58a042f49cf8ecd.zip DotNetOpenAuth-c925ab3d2c5697c9f5f6e57aa58a042f49cf8ecd.tar.gz DotNetOpenAuth-c925ab3d2c5697c9f5f6e57aa58a042f49cf8ecd.tar.bz2 |
Custom OpenID extensions may now exist outside the library.
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs')
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs new file mode 100644 index 0000000..d66bb8d --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/Acme.cs @@ -0,0 +1,80 @@ +//----------------------------------------------------------------------- +// <copyright file="Acme.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions { + using System; + using System.Collections.Generic; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OpenId.ChannelElements; + using DotNetOpenAuth.OpenId.Messages; + using DotNetOpenAuth.OpenId.Provider; + using DotNetOpenAuth.OpenId.RelyingParty; + + /// <summary> + /// A sample custom OpenID extension factory. + /// </summary> + /// <remarks> + /// OpenID extension factories must be registered with the library. This can be + /// done by calling <see cref="Acme.Register"/>, or by adding a snippet + /// such as the following to your web.config file: + /// <example> + /// <dotNetOpenAuth> + /// <openid> + /// <extensionFactories> + /// <add type="DotNetOpenAuth.ApplicationBlock.CustomExtensions.Acme, DotNetOpenAuth.ApplicationBlock" /> + /// </extensionFactories> + /// </openid> + /// </dotNetOpenAuth> + /// </example> + /// </remarks> + public class Acme : IOpenIdExtensionFactory { + internal const string CustomExtensionTypeUri = "testextension"; + internal static readonly Version Version = new Version(1, 0); + + public static void Register(OpenIdRelyingParty relyingParty) { + if (relyingParty == null) { + throw new ArgumentNullException("relyingParty"); + } + + relyingParty.ExtensionFactories.Add(new Acme()); + } + + public static void Register(OpenIdProvider provider) { + if (provider == null) { + throw new ArgumentNullException("provider"); + } + + provider.ExtensionFactories.Add(new Acme()); + } + + #region IOpenIdExtensionFactory Members + + /// <summary> + /// Creates a new instance of some extension based on the received extension parameters. + /// </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> + /// <remarks> + /// This factory method need only initialize properties in the instantiated extension object + /// that are not bound using <see cref="MessagePartAttribute"/>. + /// </remarks> + public IOpenIdMessageExtension Create(string typeUri, IDictionary<string, string> data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole) { + if (typeUri == CustomExtensionTypeUri) { + return isProviderRole ? (IOpenIdMessageExtension)new AcmeRequest() : new AcmeResponse(); + } + + return null; + } + + #endregion + } +} |