React to DI change for GetService
This commit is contained in:
parent
06c64826ee
commit
0df5dfd36b
|
|
@ -55,17 +55,22 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
var issuedUtc = context.Properties.IssuedUtc;
|
var issuedUtc = context.Properties.IssuedUtc;
|
||||||
|
|
||||||
|
if (context.HttpContext.RequestServices == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("TODO: RequestServices is null, missing Use[Request]Services?");
|
||||||
|
}
|
||||||
|
|
||||||
// Only validate if enough time has elapsed
|
// Only validate if enough time has elapsed
|
||||||
var validate = (issuedUtc == null);
|
var validate = (issuedUtc == null);
|
||||||
if (issuedUtc != null)
|
if (issuedUtc != null)
|
||||||
{
|
{
|
||||||
var timeElapsed = currentUtc.Subtract(issuedUtc.Value);
|
var timeElapsed = currentUtc.Subtract(issuedUtc.Value);
|
||||||
var identityOptions = context.HttpContext.RequestServices.GetService<IOptions<IdentityOptions>>().Options;
|
var accessor = context.HttpContext.RequestServices.GetRequiredService<IOptions<IdentityOptions>>();
|
||||||
validate = timeElapsed > identityOptions.SecurityStampValidationInterval;
|
validate = timeElapsed > accessor.Options.SecurityStampValidationInterval;
|
||||||
}
|
}
|
||||||
if (validate)
|
if (validate)
|
||||||
{
|
{
|
||||||
var validator = context.HttpContext.RequestServices.GetService<ISecurityStampValidator>();
|
var validator = context.HttpContext.RequestServices.GetRequiredService<ISecurityStampValidator>();
|
||||||
return validator.Validate(context, context.Identity);
|
return validator.Validate(context, context.Identity);
|
||||||
}
|
}
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
var id = new ClaimsIdentity(IdentityOptions.ApplicationCookieAuthenticationType);
|
var id = new ClaimsIdentity(IdentityOptions.ApplicationCookieAuthenticationType);
|
||||||
var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow });
|
var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow });
|
||||||
var context = new CookieValidateIdentityContext(httpContext.Object, ticket, new CookieAuthenticationOptions());
|
var context = new CookieValidateIdentityContext(httpContext.Object, ticket, new CookieAuthenticationOptions());
|
||||||
await Assert.ThrowsAsync<Exception>(() => SecurityStampValidator.ValidateIdentityAsync(context));
|
var ex = await Assert.ThrowsAsync<Exception>(() => SecurityStampValidator.ValidateIdentityAsync(context));
|
||||||
|
Assert.True(ex.Message.Contains("No service for type 'Microsoft.Framework.OptionsModel.IOptions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue