/// <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; }
/// <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; }
public override void SetUp() { base.SetUp(); this.factory = new StandardOpenIdExtensionFactory(); this.factory.RegisterExtension(MockOpenIdExtension.Factory); this.rpElement = new ExtensionsBindingElement(this.factory, new RelyingPartySecuritySettings()); this.rpElement.Channel = new TestChannel(this.MessageDescriptions); this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate); }
/// <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) { foreach (var factory in this.factories) { IOpenIdMessageExtension result = factory.Create(typeUri, data, baseMessage, isProviderRole); if (result != null) { return result; } } return null; }
/// <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> /// <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) { foreach (var factoryMethod in this.registeredExtensions) { IOpenIdMessageExtension result = factoryMethod(typeUri, data, baseMessage); if (result != null) { return result; } } return null; }
/// <summary> /// Reads the extension information on an authentication response from the provider. /// </summary> /// <param name="response">The incoming OpenID response carrying the extension.</param> /// <returns> /// A Javascript snippet that when executed on the user agent returns an object with /// the information deserialized from the extension response. /// </returns> /// <remarks> /// This method is called <b>before</b> the signature on the assertion response has been /// verified. Therefore all information in these fields should be assumed unreliable /// and potentially falsified. /// </remarks> string IClientScriptExtensionResponse.InitializeJavaScriptData(IProtocolMessageWithExtensions response) { var sreg = new Dictionary <string, string>(15); // Although we could probably whip up a trip with MessageDictionary // to avoid explicitly setting each field, doing so would likely // open ourselves up to security exploits from the OP as it would // make possible sending arbitrary javascript in arbitrary field names. sreg[Constants.nickname] = this.Nickname; sreg[Constants.email] = this.Email; sreg[Constants.fullname] = this.FullName; sreg[Constants.dob] = this.BirthDateRaw; sreg[Constants.gender] = this.Gender.HasValue ? this.Gender.Value.ToString() : null; sreg[Constants.postcode] = this.PostalCode; sreg[Constants.country] = this.Country; sreg[Constants.language] = this.Language; sreg[Constants.timezone] = this.TimeZone; return(MessagingUtilities.CreateJsonObject(sreg, false)); }
/// <summary> /// Reads the extension information on an authentication response from the provider. /// </summary> /// <param name="response">The incoming OpenID response carrying the extension.</param> /// <returns> /// A Javascript snippet that when executed on the user agent returns an object with /// the information deserialized from the extension response. /// </returns> /// <remarks> /// This method is called <b>before</b> the signature on the assertion response has been /// verified. Therefore all information in these fields should be assumed unreliable /// and potentially falsified. /// </remarks> string IClientScriptExtensionResponse.InitializeJavaScriptData(IProtocolMessageWithExtensions response) { var sreg = new Dictionary<string, string>(15); // Although we could probably whip up a trip with MessageDictionary // to avoid explicitly setting each field, doing so would likely // open ourselves up to security exploits from the OP as it would // make possible sending arbitrary javascript in arbitrary field names. sreg[Constants.nickname] = this.Nickname; sreg[Constants.email] = this.Email; sreg[Constants.fullname] = this.FullName; sreg[Constants.dob] = this.BirthDateRaw; sreg[Constants.gender] = this.Gender.HasValue ? this.Gender.Value.ToString() : null; sreg[Constants.postcode] = this.PostalCode; sreg[Constants.country] = this.Country; sreg[Constants.language] = this.Language; sreg[Constants.timezone] = this.TimeZone; return MessagingUtilities.CreateJsonObject(sreg, false); }
/// <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); }
/// <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); }
/// <summary> /// Gets the extensions on a message. /// </summary> /// <param name="message">The carrier of the extensions.</param> /// <param name="ignoreUnsigned">If set to <c>true</c> only signed extensions will be available.</param> /// <param name="extensionFilter">A optional filter that takes an extension type URI and /// returns a value indicating whether that extension should be deserialized and /// returned in the sequence. May be null.</param> /// <returns>A sequence of extensions in the message.</returns> private IEnumerable<IOpenIdMessageExtension> GetExtensions(IProtocolMessageWithExtensions message, bool ignoreUnsigned, Func<string, bool> extensionFilter) { bool isAtProvider = message is SignedResponseRequest; // We have a helper class that will do all the heavy-lifting of organizing // all the extensions, their aliases, and their parameters. var extensionManager = ExtensionArgumentsManager.CreateIncomingExtensions(this.GetExtensionsDictionary(message, ignoreUnsigned)); foreach (string typeUri in extensionManager.GetExtensionTypeUris()) { // Our caller may have already obtained a signed version of this extension, // so skip it if they don't want this one. if (extensionFilter != null && !extensionFilter(typeUri)) { continue; } var extensionData = extensionManager.GetExtensionArguments(typeUri); // Initialize this particular extension. IOpenIdMessageExtension extension = this.ExtensionFactory.Create(typeUri, extensionData, message, isAtProvider); if (extension != null) { try { // Make sure the extension fulfills spec requirements before deserializing it. MessageDescription messageDescription = this.Channel.MessageDescriptions.Get(extension); messageDescription.EnsureMessagePartsPassBasicValidation(extensionData); // Deserialize the extension. MessageDictionary extensionDictionary = messageDescription.GetDictionary(extension); foreach (var pair in extensionData) { extensionDictionary[pair.Key] = pair.Value; } // Give extensions that require custom serialization a chance to do their work. var customSerializingExtension = extension as IMessageWithEvents; if (customSerializingExtension != null) { customSerializingExtension.OnReceiving(); } } catch (ProtocolException ex) { Logger.OpenId.ErrorFormat(OpenIdStrings.BadExtension, extension.GetType(), ex); extension = null; } if (extension != null) { yield return extension; } } else { Logger.OpenId.DebugFormat("Extension with type URI '{0}' ignored because it is not a recognized extension.", typeUri); } } }
/// <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) { foreach (var factory in this.factories) { IOpenIdMessageExtension result = factory.Create(typeUri, data, baseMessage, isProviderRole); if (result != null) { return(result); } } return(null); }
/// <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> /// <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) { foreach (var factoryMethod in this.registeredExtensions) { IOpenIdMessageExtension result = factoryMethod(typeUri, data, baseMessage); if (result != null) { return(result); } } return(null); }
private IList <IExtensionMessage> GetResponseExtensions() { IProtocolMessageWithExtensions response = (IProtocolMessageWithExtensions)this.request.Response; return(response.Extensions); }