Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void OnServiceConfigurationCreated( object sender, ServiceConfigurationCreatedEventArgs e )
- {
- List<CookieTransform> sessionTransforms = new List<CookieTransform>( new CookieTransform[]
- {
- new DeflateCookieTransform(),
- new RsaEncryptionCookieTransform( e.ServiceConfiguration.ServiceCertificate ),
- new RsaSignatureCookieTransform( e.ServiceConfiguration.ServiceCertificate )
- } );
- SessionSecurityTokenHandler sessionHandler =
- new SessionSecurityTokenHandler( sessionTransforms.AsReadOnly() );
- e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace( sessionHandler );
- }
- <microsoft.identityModel>
- <service>
- <serviceCertificate>
- <certificateReference x509FindType="FindByThumbprint" findValue="C7FD338059CCB374798923A915BC91B718814A8E" storeLocation="LocalMachine" storeName="TrustedPeople" />
- </serviceCertificate>
- </service>
- </microsoft.identityModel>
- System.Security.Cryptography.CryptographicException: ID1014: The signature is not valid. The data may have been tampered with.
- at Microsoft.IdentityModel.Web.RsaSignatureCookieTransform.Decode(Byte[] encoded)
- at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound)
- at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
- at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver)
- at Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie)
- at Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)
- at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
- at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
- at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
- void CustomSessionAuthenticationModule_SessionSecurityTokenReceived( object sender, SessionSecurityTokenReceivedEventArgs e )
- {
- DateTime now = DateTime.UtcNow;
- DateTime validFrom = e.SessionToken.ValidFrom;
- DateTime validTo = e.SessionToken.ValidTo;
- double tokenLifetime = (validTo - validFrom).TotalMinutes;
- SessionAuthenticationModule sam = sender as SessionAuthenticationModule;
- if( now < validTo && now > validFrom.AddMinutes( tokenLifetime / 2 ) )
- {
- e.SessionToken = sam.CreateSessionSecurityToken(
- e.SessionToken.ClaimsPrincipal, e.SessionToken.Context,
- now, now.AddMinutes( tokenLifetime ), e.SessionToken.IsPersistent );
- e.ReissueCookie = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment