예제 #1
0
        private void Parse()
        {
            this.Claims = new NameValueCollection();

            if (RawToken.StartsWith("wrap_access_token="))
            {
                RawToken = RawToken.Replace("wrap_access_token=", "");
            }

            foreach (var rawNameValue in RawToken.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (rawNameValue.StartsWith("HMACSHA256="))
                {
                    continue;
                }

                var nameValue = rawNameValue.Split('=');

                if (nameValue.Length != 2)
                {
                    throw new InvalidSecurityTokenException(string.Format(
                                                                "Invalid token contains a name/value pair missing an = character: '{0}'", rawNameValue));
                }

                var key = HttpUtility.UrlDecode(nameValue[0]);

                if (this.Claims.AllKeys.Contains(key))
                {
                    throw new InvalidSecurityTokenException("Duplicated name token.");
                }

                var values = HttpUtility.UrlDecode(nameValue[1]);

                switch (key)
                {
                case Saml2Constants.Elements.Audience:
                    this.Audience = values;
                    break;

                case "ExpiresOn":
                    this.ExpiresOn = ulong.Parse(values).ToDateTimeFromEpoch();
                    break;

                case Saml2Constants.Elements.Issuer:
                    this.Issuer = values;
                    break;

                default:
                    foreach (var value in values.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        this.Claims.Add(key, value);
                    }
                    break;
                }
            }
        }