Esempio n. 1
0
        public static ExtensionArgumentsManager CreateIncomingExtensions(IDictionary <string, string> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("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.
            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);
        }
Esempio n. 2
0
        internal OpenIdException(string message, Identifier identifier, IDictionary <string, string> query, Exception innerException)
            : base(message, innerException)
        {
            this.Query = query;
            Identifier = identifier;
            if (query != null)
            {
                Protocol = Protocol.Detect(query);
            }

            if (query != null)
            {
                Logger.ErrorFormat("OpenIdException: {0}{1}{2}", message, Environment.NewLine, Util.ToString(query));
            }
            else
            {
                Logger.ErrorFormat("OpenIdException: {0}", message);
            }
        }