public static D2LSecurityToken CreateTokenWithTimeRemaining(
TimeSpan remaining,
Guid? id = null
) {
id = id ?? Guid.NewGuid();
var validTo = DateTime.UtcNow + remaining;
var validFrom = validTo - TimeSpan.FromHours( 1 );
RSAParameters privateKey;
using( var csp = new RSACryptoServiceProvider( Keys.Constants.GENERATED_RSA_KEY_SIZE ) {
PersistKeyInCsp = false
} ) {
privateKey = csp.ExportParameters( includePrivateParameters: true );
}
return new D2LSecurityToken(
id.Value,
validFrom,
validTo,
keyFactory: () => {
var csp = new RSACryptoServiceProvider() { PersistKeyInCsp = false };
csp.ImportParameters( privateKey );
var key = new RsaSecurityKey( csp );
return new Tuple<AsymmetricSecurityKey, IDisposable>( key, csp );
}
);
}