示例#1
0
        /// <summary>
        /// Creates a <see cref="ExtensionArgumentsManager"/> instance to process incoming extensions.
        /// </summary>
        /// <param name="query">The parameters in the OpenID message.</param>
        /// <returns>The newly created instance of <see cref="ExtensionArgumentsManager"/>.</returns>
        public static ExtensionArgumentsManager CreateIncomingExtensions(IDictionary <string, string> query)
        {
            Requires.NotNull(query, "query");
            var mgr = new ExtensionArgumentsManager();

            mgr.protocol   = Protocol.Detect(query);
            mgr.isReadMode = true;
            string aliasPrefix = mgr.protocol.openid.ns + ".";

            // First pass looks for namespace aliases
            foreach (var pair in query)
            {
                if (pair.Key.StartsWith(aliasPrefix, StringComparison.Ordinal))
                {
                    mgr.aliasManager.SetAlias(pair.Key.Substring(aliasPrefix.Length), pair.Value);
                }
            }

            // For backwards compatibility, add certain aliases if they aren't defined.
            if (mgr.protocol.Version.Major < 2)
            {
                foreach (var pair in typeUriToAliasAffinity)
                {
                    if (!mgr.aliasManager.IsAliasAssignedTo(pair.Key) &&
                        !mgr.aliasManager.IsAliasUsed(pair.Value))
                    {
                        mgr.aliasManager.SetAlias(pair.Value, pair.Key);
                    }
                }
            }

            // Second pass looks for extensions using those aliases
            foreach (var pair in query)
            {
                if (!pair.Key.StartsWith(mgr.protocol.openid.Prefix, StringComparison.Ordinal))
                {
                    continue;
                }
                string possibleAlias = pair.Key.Substring(mgr.protocol.openid.Prefix.Length);
                int    periodIndex   = possibleAlias.IndexOf(".", StringComparison.Ordinal);
                if (periodIndex >= 0)
                {
                    possibleAlias = possibleAlias.Substring(0, periodIndex);
                }
                string typeUri;
                if ((typeUri = mgr.aliasManager.TryResolveAlias(possibleAlias)) != null)
                {
                    if (!mgr.extensions.ContainsKey(typeUri))
                    {
                        mgr.extensions[typeUri] = new Dictionary <string, string>();
                    }
                    string key = periodIndex >= 0 ? pair.Key.Substring(mgr.protocol.openid.Prefix.Length + possibleAlias.Length + 1) : string.Empty;
                    mgr.extensions[typeUri].Add(key, pair.Value);
                }
            }
            return(mgr);
        }
示例#2
0
        /// <summary>
        /// Creates a <see cref="ExtensionArgumentsManager"/> instance to prepare outgoing extensions.
        /// </summary>
        /// <param name="protocol">The protocol version used for the outgoing message.</param>
        /// <returns>
        /// The newly created instance of <see cref="ExtensionArgumentsManager"/>.
        /// </returns>
        public static ExtensionArgumentsManager CreateOutgoingExtensions(Protocol protocol)
        {
            var mgr = new ExtensionArgumentsManager();

            mgr.protocol = protocol;

            // Affinity for certain alias for backwards compatibility
            foreach (var pair in typeUriToAliasAffinity)
            {
                mgr.aliasManager.SetAlias(pair.Value, pair.Key);
            }
            return(mgr);
        }
		/// <summary>
		/// Creates a <see cref="ExtensionArgumentsManager"/> instance to process incoming extensions.
		/// </summary>
		/// <param name="query">The parameters in the OpenID message.</param>
		/// <returns>The newly created instance of <see cref="ExtensionArgumentsManager"/>.</returns>
		public static ExtensionArgumentsManager CreateIncomingExtensions(IDictionary<string, string> query) {
			Requires.NotNull(query, "query");
			var mgr = new ExtensionArgumentsManager();
			mgr.protocol = Protocol.Detect(query);
			mgr.isReadMode = true;
			string aliasPrefix = mgr.protocol.openid.ns + ".";

			// First pass looks for namespace aliases
			foreach (var pair in query) {
				if (pair.Key.StartsWith(aliasPrefix, StringComparison.Ordinal)) {
					mgr.aliasManager.SetAlias(pair.Key.Substring(aliasPrefix.Length), pair.Value);
				}
			}

			// For backwards compatibility, add certain aliases if they aren't defined.
			if (mgr.protocol.Version.Major < 2) {
				foreach (var pair in typeUriToAliasAffinity) {
					if (!mgr.aliasManager.IsAliasAssignedTo(pair.Key) &&
						!mgr.aliasManager.IsAliasUsed(pair.Value)) {
						mgr.aliasManager.SetAlias(pair.Value, pair.Key);
					}
				}
			}

			// Second pass looks for extensions using those aliases
			foreach (var pair in query) {
				if (!pair.Key.StartsWith(mgr.protocol.openid.Prefix, StringComparison.Ordinal)) {
					continue;
				}
				string possibleAlias = pair.Key.Substring(mgr.protocol.openid.Prefix.Length);
				int periodIndex = possibleAlias.IndexOf(".", StringComparison.Ordinal);
				if (periodIndex >= 0) {
					possibleAlias = possibleAlias.Substring(0, periodIndex);
				}
				string typeUri;
				if ((typeUri = mgr.aliasManager.TryResolveAlias(possibleAlias)) != null) {
					if (!mgr.extensions.ContainsKey(typeUri)) {
						mgr.extensions[typeUri] = new Dictionary<string, string>();
					}
					string key = periodIndex >= 0 ? pair.Key.Substring(mgr.protocol.openid.Prefix.Length + possibleAlias.Length + 1) : string.Empty;
					mgr.extensions[typeUri].Add(key, pair.Value);
				}
			}
			return mgr;
		}
        /// <summary>
        /// Creates a <see cref="ExtensionArgumentsManager"/> instance to prepare outgoing extensions.
        /// </summary>
        /// <param name="protocol">The protocol version used for the outgoing message.</param>
        /// <returns>
        /// The newly created instance of <see cref="ExtensionArgumentsManager"/>.
        /// </returns>
        public static ExtensionArgumentsManager CreateOutgoingExtensions(Protocol protocol)
        {
            var mgr = new ExtensionArgumentsManager();
            mgr.protocol = protocol;

            // Affinity for certain alias for backwards compatibility
            foreach (var pair in typeUriToAliasAffinity) {
                mgr.aliasManager.SetAlias(pair.Value, pair.Key);
            }
            return mgr;
        }