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

CreateToken() public method

Creates the token.
public CreateToken ( System.IdentityModel.Tokens.SecurityTokenDescriptor tokenDescriptor ) : System.IdentityModel.Tokens.SecurityToken
tokenDescriptor System.IdentityModel.Tokens.SecurityTokenDescriptor The token descriptor.
return System.IdentityModel.Tokens.SecurityToken
        public override SecurityToken CreateToken(SecurityTokenDescriptor tokenDescriptor)
        {
            if (tokenDescriptor == null)
            {
                throw new ArgumentNullException("tokenDescriptor");
            }
            //Contract.Ensures(Contract.Result<SecurityToken>() != null);
            //Contract.EndContractBlock();
            

            AccessSecurityToken token = new AccessSecurityToken(
                tokenDescriptor.Subject.Name, 
                tokenDescriptor.AppliesToAddress, 
                tokenDescriptor.Lifetime, 
                ((X509SigningCredentials)tokenDescriptor.SigningCredentials).Certificate);

            return token;
        }

Usage Example

        private static SecurityToken CreateToken(AccessSecurityTokenHandler handler)
        {
            var descriptor = new SecurityTokenDescriptor
            {
                AppliesToAddress = "http://tecteacher.thinktecture.com/videos/1",
                Lifetime = new Lifetime(DateTime.Now, DateTime.Now.AddMinutes(60)),
                SigningCredentials = GetSigningCredential(),
                TokenType = AccessSecurityToken.TokenTypeIdentifier,
                Subject = new ClaimsIdentity(new List<Claim> 
                    {
                        new Claim(WSIdentityConstants.ClaimTypes.Name, "bob")
                    })
            };

            var token = handler.CreateToken(descriptor);
            return token;
        }