Microsoft.IdentityModel.Swt.SimpleWebToken.Parse C# (CSharp) Method

Parse() private method

private Parse ( ) : void
return void
		private void Parse()
		{
			this.Claims = new NameValueCollection();

			foreach (var rawNameValue in this.RawToken.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries))
			{
				if (rawNameValue.StartsWith(SwtConstants.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 SwtConstants.Audience:
						this.Audience = values;
						break;
					case SwtConstants.ExpiresOn:
						this.ExpiresOn = ulong.Parse(values).ToDateTimeFromEpoch();
						break;
					case SwtConstants.Issuer:
						this.Issuer = values;
						break;
					default:
						// We may have more than one value in SWT.
						foreach (var value in values.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
						{
							this.Claims.Add(key, value);
						}
						break;
				}
			}
		}