Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DemoCorsPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Duende.IdentityServer.Demo
// allows arbitrary CORS origins - only for demo purposes. NEVER USE IN PRODUCTION
public class DemoCorsPolicy : ICorsPolicyService
{
public Task<bool> IsOriginAllowedAsync(string origin)
public Task<bool> IsOriginAllowedAsync(string origin, CancellationToken ct)
{
return Task.FromResult(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DemoRedirectValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Duende.IdentityServer.Demo
// allows arbitrary redirect URIs - only for demo purposes. NEVER USE IN PRODUCTION
public class DemoRedirectValidator : IRedirectUriValidator
{
public Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client)
public Task<bool> IsRedirectUriValidAsync(string requestedUri, Client client)
{
return Task.FromResult(true);
}

public Task<bool> IsRedirectUriValidAsync(string requestedUri, Client client)
public Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client, CancellationToken ct)
{
return Task.FromResult(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Duende.IdentityServer.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" Version="7.4.6" />
<PackageReference Include="Duende.IdentityServer" Version="8.0.0-alpha.1" />
<PackageReference Include="Duende.AspNetCore.Authentication.JwtBearer" Version="0.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Account/Create/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IActionResult OnGet(string? returnUrl)
public async Task<IActionResult> OnPost()
{
// check if we are in the context of an authorization request
var context = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl);
var context = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl, HttpContext.RequestAborted);

// the user clicked the "cancel" button
if (Input.Button != "create")
Expand All @@ -51,7 +51,7 @@ public async Task<IActionResult> OnPost()
// if the user cancels, send a result back into IdentityServer as if they
// denied the consent (even if this client does not require consent).
// this will send back an access denied OIDC error response to the client.
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied, HttpContext.RequestAborted);

// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
if (context.IsNativeClient())
Expand Down
12 changes: 6 additions & 6 deletions src/Pages/Account/Login/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<IActionResult> OnGet(string? returnUrl)
public async Task<IActionResult> OnPost()
{
// check if we are in the context of an authorization request
var context = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl);
var context = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl, HttpContext.RequestAborted);

// the user clicked the "cancel" button
if (Input.Button != "login")
Expand All @@ -74,7 +74,7 @@ public async Task<IActionResult> OnPost()
// if the user cancels, send a result back into IdentityServer as if they
// denied the consent (even if this client does not require consent).
// this will send back an access denied OIDC error response to the client.
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied, HttpContext.RequestAborted);

// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
if (context.IsNativeClient())
Expand All @@ -99,7 +99,7 @@ public async Task<IActionResult> OnPost()
if (_users.ValidateCredentials(Input.Username, Input.Password))
{
var user = _users.FindByUsername(Input.Username);
await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username, clientId: context?.Client.ClientId));
await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.SubjectId, user.Username, clientId: context?.Client.ClientId), HttpContext.RequestAborted);
Telemetry.Metrics.UserLogin(context?.Client.ClientId, IdentityServerConstants.LocalIdentityProvider);

// only set explicit expiration here if user chooses "remember me".
Expand Down Expand Up @@ -152,7 +152,7 @@ public async Task<IActionResult> OnPost()
}

const string error = "invalid credentials";
await _events.RaiseAsync(new UserLoginFailureEvent(Input.Username, error, clientId:context?.Client.ClientId));
await _events.RaiseAsync(new UserLoginFailureEvent(Input.Username, error, clientId:context?.Client.ClientId), HttpContext.RequestAborted);
Telemetry.Metrics.UserLoginFailure(context?.Client.ClientId, IdentityServerConstants.LocalIdentityProvider, error);
ModelState.AddModelError(string.Empty, LoginOptions.InvalidCredentialsErrorMessage);
}
Expand All @@ -169,7 +169,7 @@ private async Task BuildModelAsync(string? returnUrl)
ReturnUrl = returnUrl
};

var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
var context = await _interaction.GetAuthorizationContextAsync(returnUrl, HttpContext.RequestAborted);
if (context?.IdP != null && await _schemeProvider.GetSchemeAsync(context.IdP) != null)
{
var local = context.IdP == Duende.IdentityServer.IdentityServerConstants.LocalIdentityProvider;
Expand Down Expand Up @@ -200,7 +200,7 @@ private async Task BuildModelAsync(string? returnUrl)
displayName: x.DisplayName ?? x.Name
)).ToList();

var dynamicSchemes = (await _identityProviderStore.GetAllSchemeNamesAsync())
var dynamicSchemes = (await _identityProviderStore.GetAllSchemeNamesAsync(HttpContext.RequestAborted))
.Where(x => x.Enabled)
.Select(x => new ViewModel.ExternalProvider
(
Expand Down
6 changes: 3 additions & 3 deletions src/Pages/Account/Logout/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<IActionResult> OnGet(string? logoutId)
}
else
{
var context = await _interaction.GetLogoutContextAsync(LogoutId);
var context = await _interaction.GetLogoutContextAsync(LogoutId, HttpContext.RequestAborted);
if (context?.ShowSignoutPrompt == false)
{
// it's safe to automatically sign-out
Expand All @@ -66,7 +66,7 @@ public async Task<IActionResult> OnPost()
// if there's no current logout context, we need to create one
// this captures necessary info from the current logged in user
// this can still return null if there is no context needed
LogoutId ??= await _interaction.CreateLogoutContextAsync();
LogoutId ??= await _interaction.CreateLogoutContextAsync(HttpContext.RequestAborted);

// delete local authentication cookie
await HttpContext.SignOutAsync();
Expand All @@ -75,7 +75,7 @@ public async Task<IActionResult> OnPost()
var idp = User.FindFirst(JwtClaimTypes.IdentityProvider)?.Value;

// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()), HttpContext.RequestAborted);
Telemetry.Metrics.UserLogout(idp);

// if it's a local login we can ignore this workflow
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Account/Logout/LoggedOut.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LoggedOut(IIdentityServerInteractionService interactionService)
public async Task OnGet(string? logoutId)
{
// get context information (client name, post logout redirect URI and iframe for federated signout)
var logout = await _interactionService.GetLogoutContextAsync(logoutId);
var logout = await _interactionService.GetLogoutContextAsync(logoutId, HttpContext.RequestAborted);

View = new LoggedOutViewModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Ciba/All.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public AllModel(IBackchannelAuthenticationInteractionService backchannelAuthenti

public async Task OnGet()
{
Logins = await _backchannelAuthenticationInteraction.GetPendingLoginRequestsForCurrentUserAsync();
Logins = await _backchannelAuthenticationInteraction.GetPendingLoginRequestsForCurrentUserAsync(HttpContext.RequestAborted);
}
}
10 changes: 5 additions & 5 deletions src/Pages/Ciba/Consent.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<IActionResult> OnGet(string? id)
public async Task<IActionResult> OnPost()
{
// validate return url is still valid
var request = await _interaction.GetLoginRequestByInternalIdAsync(Input.Id ?? throw new ArgumentNullException(nameof(Input.Id)));
var request = await _interaction.GetLoginRequestByInternalIdAsync(Input.Id ?? throw new ArgumentNullException(nameof(Input.Id)), HttpContext.RequestAborted);
if (request == null || request.Subject.GetSubjectId() != User.GetSubjectId())
{
_logger.InvalidId(Input.Id);
Expand All @@ -68,7 +68,7 @@ public async Task<IActionResult> OnPost()
result = new CompleteBackchannelLoginRequest(Input.Id);

// emit event
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues));
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName));
}
// user clicked 'yes' - validate the data
Expand All @@ -90,7 +90,7 @@ public async Task<IActionResult> OnPost()
};

// emit event
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, result.ScopesValuesConsented, false));
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, result.ScopesValuesConsented, false), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentGranted(request.Client.ClientId, result.ScopesValuesConsented, false);
var denied = request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName).Except(result.ScopesValuesConsented);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, denied);
Expand All @@ -108,7 +108,7 @@ public async Task<IActionResult> OnPost()
if (result != null)
{
// communicate outcome of consent back to identityserver
await _interaction.CompleteLoginRequestAsync(result);
await _interaction.CompleteLoginRequestAsync(result, HttpContext.RequestAborted);

return RedirectToPage("/Ciba/All");
}
Expand All @@ -125,7 +125,7 @@ private async Task<bool> SetViewModelAsync(string? id)
{
ArgumentNullException.ThrowIfNull(id);

var request = await _interaction.GetLoginRequestByInternalIdAsync(id);
var request = await _interaction.GetLoginRequestByInternalIdAsync(id, HttpContext.RequestAborted);
if (request != null && request.Subject.GetSubjectId() == User.GetSubjectId())
{
View = CreateConsentViewModel(request);
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Ciba/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public IndexModel(IBackchannelAuthenticationInteractionService backchannelAuthen

public async Task<IActionResult> OnGet(string id)
{
var result = await _backchannelAuthenticationInteraction.GetLoginRequestByInternalIdAsync(id);
var result = await _backchannelAuthenticationInteraction.GetLoginRequestByInternalIdAsync(id, HttpContext.RequestAborted);
if (result == null)
{
_logger.InvalidBackchannelLoginId(id);
Expand Down
10 changes: 5 additions & 5 deletions src/Pages/Consent/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<IActionResult> OnGet(string? returnUrl)
public async Task<IActionResult> OnPost()
{
// validate return url is still valid
var request = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl);
var request = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl, HttpContext.RequestAborted);
if (request == null) return RedirectToPage("/Home/Error/Index");

ConsentResponse? grantedConsent = null;
Expand All @@ -65,7 +65,7 @@ public async Task<IActionResult> OnPost()
grantedConsent = new ConsentResponse { Error = AuthorizationError.AccessDenied };

// emit event
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues));
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName));
}
// user clicked 'yes' - validate the data
Expand All @@ -88,7 +88,7 @@ public async Task<IActionResult> OnPost()
};

// emit event
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent));
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentGranted(request.Client.ClientId, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent);
var denied = request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName).Except(grantedConsent.ScopesValuesConsented);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, denied);
Expand All @@ -108,7 +108,7 @@ public async Task<IActionResult> OnPost()
ArgumentNullException.ThrowIfNull(Input.ReturnUrl, nameof(Input.ReturnUrl));

// communicate outcome of consent back to identityserver
await _interaction.GrantConsentAsync(request, grantedConsent);
await _interaction.GrantConsentAsync(request, grantedConsent, HttpContext.RequestAborted);

// redirect back to authorization endpoint
if (request.IsNativeClient() == true)
Expand All @@ -133,7 +133,7 @@ private async Task<bool> SetViewModelAsync(string? returnUrl)
{
ArgumentNullException.ThrowIfNull(returnUrl);

var request = await _interaction.GetAuthorizationContextAsync(returnUrl);
var request = await _interaction.GetAuthorizationContextAsync(returnUrl, HttpContext.RequestAborted);
if (request != null)
{
View = CreateConsentViewModel(request);
Expand Down
10 changes: 5 additions & 5 deletions src/Pages/Device/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<IActionResult> OnGet(string? userCode)

public async Task<IActionResult> OnPost()
{
var request = await _interaction.GetAuthorizationContextAsync(Input.UserCode ?? throw new ArgumentNullException(nameof(Input.UserCode)));
var request = await _interaction.GetAuthorizationContextAsync(Input.UserCode ?? throw new ArgumentNullException(nameof(Input.UserCode)), HttpContext.RequestAborted);
if (request == null) return RedirectToPage("/Home/Error/Index");

ConsentResponse? grantedConsent = null;
Expand All @@ -77,7 +77,7 @@ public async Task<IActionResult> OnPost()
};

// emit event
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues));
await _events.RaiseAsync(new ConsentDeniedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName));
}
// user clicked 'yes' - validate the data
Expand All @@ -100,7 +100,7 @@ public async Task<IActionResult> OnPost()
};

// emit event
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent));
await _events.RaiseAsync(new ConsentGrantedEvent(User.GetSubjectId(), request.Client.ClientId, request.ValidatedResources.RawScopeValues, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent), HttpContext.RequestAborted);
Telemetry.Metrics.ConsentGranted(request.Client.ClientId, grantedConsent.ScopesValuesConsented, grantedConsent.RememberConsent);
var denied = request.ValidatedResources.ParsedScopes.Select(s => s.ParsedName).Except(grantedConsent.ScopesValuesConsented);
Telemetry.Metrics.ConsentDenied(request.Client.ClientId, denied);
Expand All @@ -118,7 +118,7 @@ public async Task<IActionResult> OnPost()
if (grantedConsent != null)
{
// communicate outcome of consent back to identityserver
await _interaction.HandleRequestAsync(Input.UserCode, grantedConsent);
await _interaction.HandleRequestAsync(Input.UserCode, grantedConsent, HttpContext.RequestAborted);

// indicate that's it ok to redirect back to authorization endpoint
return RedirectToPage("/Device/Success");
Expand All @@ -135,7 +135,7 @@ public async Task<IActionResult> OnPost()

private async Task<bool> SetViewModelAsync(string userCode)
{
var request = await _interaction.GetAuthorizationContextAsync(userCode);
var request = await _interaction.GetAuthorizationContextAsync(userCode, HttpContext.RequestAborted);
if (request != null)
{
View = CreateConsentViewModel(request);
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/ExternalLogin/Callback.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public async Task<IActionResult> OnGet()
var returnUrl = result.Properties.Items["returnUrl"] ?? "~/";

// check if external login is in the context of an OIDC request
var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
await _events.RaiseAsync(new UserLoginSuccessEvent(provider, providerUserId, user.SubjectId, user.Username, true, context?.Client.ClientId));
var context = await _interaction.GetAuthorizationContextAsync(returnUrl, HttpContext.RequestAborted);
await _events.RaiseAsync(new UserLoginSuccessEvent(provider, providerUserId, user.SubjectId, user.Username, true, context?.Client.ClientId), HttpContext.RequestAborted);
Telemetry.Metrics.UserLogin(context?.Client.ClientId, provider!);

if (context != null)
Expand Down
Loading