Thinktecture.IdentityModel.Tokens.AccessSecurityTokenHandler.ReadTokenValues C# (CSharp) Method

ReadTokenValues() protected method

Reads the token values.
protected ReadTokenValues ( System.Xml.Linq.XElement xml, X509Certificate2 issuerCertificate ) : AccessSecurityToken
xml System.Xml.Linq.XElement The XML.
issuerCertificate System.Security.Cryptography.X509Certificates.X509Certificate2 The issuer certificate.
return AccessSecurityToken
        protected virtual AccessSecurityToken ReadTokenValues(XElement xml, X509Certificate2 issuerCertificate)
        {
            Contract.Requires(xml != null);
            Contract.Requires(issuerCertificate != null);
            Contract.Ensures(Contract.Result<AccessSecurityToken>() != null);


            var id = xml.Attribute("id").Value;
            var subject = xml.Element(_ns + "subject").Value;
            var resource = xml.Element(_ns + "resource").Value;
            var expires = DateTime.ParseExact(xml.Element(_ns + "expires").Value, DateTimeFormats.Accepted, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();

            if (!String.IsNullOrEmpty(id) && !String.IsNullOrEmpty(subject) && !String.IsNullOrEmpty(resource) && expires != null)
            {
                return new AccessSecurityToken(id, subject, resource, expires, issuerCertificate);
            }
            else
            {
                throw new SecurityTokenException("Missing values in token");
            }
        }