Skip to content

Use AdditionalAuthorizationParameters #848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

martincostello
Copy link
Member

@martincostello martincostello commented Mar 21, 2024

Ensure that overrides of BuildChallengeUrl() that do not call the base implementation add the values from the new AdditionalAuthorizationParameters property.

- Ensure that overrides of `BuildChallengeUrl()` that do not call the base implementation add the values from the new `AdditionalAuthorizationParameters` property.
- Move all static challenge parameters into the `AdditionalAuthorizationParameters` property on the options.
- Remove `BuildChallengeUrl()` overrides, where possible, to just use `AdditionalAuthorizationParameters` instead.
@martincostello martincostello added this to the 9.0.0 milestone Mar 21, 2024
@kevinchalet
Copy link
Member

Move all static challenge parameters into the AdditionalAuthorizationParameters property on the options.

I prefer the old approach: these parameters are actually required for the providers to work correctly so we shouldn't allow users to remove them (which could be accidental, e.g by calling AdditionalAuthorizationParameters.Clear() without realizing the provider implementation now depends on that to send critical parameters)

@martincostello
Copy link
Member Author

we shouldn't allow users to remove them

Didn't consider that, but I did think that it was the more questionable part of the change, hence the review request. I'll undo those parts.

AFAICT, that dictionary can never be null: it's get-only and a default instance is always attached.

I didn't check the definition so assumed it was get-set. Will remove the ?s.

This differs from the OAuthHandler implementation that will throw an exception if you try to add a parameter that the provider already added. Should we change that for consistency?

Depends if you want to remove the ability for the user to be "I know what I'm doing" and override one of our parameters with another value for "{insert reason}". Personally I'd favour the "you can override it if you really want to" behaviour.

- Remove redundant null checks.
- Revert changes to move static parameters into `AdditionalAuthorizationParameters`.
@kevinchalet
Copy link
Member

I'll undo those parts.

👍🏻

Depends if you want to remove the ability for the user to be "I know what I'm doing" and override one of our parameters with another value for "{insert reason}". Personally I'd favour the "you can override it if you really want to" behaviour.

I have no strong preference/opinion on that (FWIW, I opted for the second option in OpenIddict), but if we don't use the same logic as OAuthHandler, things will be extremely inconsistent: only a few providers here override BuildChallengeUrl, which means all the other ones will use the base implementation provided by OAuthHandler and will exhibit a different logic.

If you think allowing users to override the default parameters is the thing to do, maybe we should try to convince the ASP.NET folks the OAuthHandler implementation should be changed?

/cc @halter73

@halter73
Copy link

Depends if you want to remove the ability for the user to be "I know what I'm doing" and override one of our parameters with another value for "{insert reason}". Personally I'd favour the "you can override it if you really want to" behaviour.

I usually like to allow users to say "I know what I'm doing" when working on niche APIs, but a lot of people work with OAuthOptions and OpenIdConnectOptions.

The decision to remove the static challenge parameters from the dictionary so they cannot be accidentally cleared shows that you acknowledge that this API will be used by people who don't know what they're doing and therefore don't want to give them any unnecessary footguns. It seems at least as likely that someone would accidently overwrite a default parameter with a bad value.

If there is any real "{insert reason}" that you can come up with for overwriting a parameter, I'd reconsider. I'm usually more annoyed by being unnecessarily prevented from doing something than I am by footguns.

@martincostello martincostello merged commit f70fdff into aspnet-contrib:dev-v9 Mar 22, 2024
8 checks passed
@martincostello martincostello deleted the Use-AdditionalAuthorizationParameters branch March 22, 2024 12:51
martincostello added a commit that referenced this pull request Nov 12, 2024
* Update to ASP.NET Core 9 preview 1

- Update to preview 1 of ASP.NET Core 9.
- Use xunit's `TheoryData<T>`.
- Fix new code analysis warnings and suggestions.
- Disable noisy new CA1515 warning.
- Update various dependencies to their latest versions.

* Update .NET SDK to 9.0.100-preview.2.24157.14 (#842)

* Update prerelease iteration

Update for preview.2.

* Use AdditionalAuthorizationParameters (#848)

Ensure that overrides of `BuildChallengeUrl()` that do not call the base implementation add the values from the new `AdditionalAuthorizationParameters` property.
See https://github.com/dotnet/aspnetcore/blob/ec293ee75c0c022370951a459b188fa81ec8b7c3/src/Security/Authentication/OAuth/src/OAuthHandler.cs#L331-L334.

* Update .NET SDK to 9.0.100-preview.3.24204.13 (#853)

* Update .NET SDK

Update .NET SDK to version 9.0.100-preview.3.24204.13.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>

* Bump .NET NuGet packages

Bumps .NET dependencies to their latest versions for the .NET 9.0.100-preview.3.24204.13 SDK.

Bumps Microsoft.AspNetCore.Authentication.Google from 9.0.0-preview.2.24128.4 to 9.0.0-preview.3.24172.13.
Bumps Microsoft.AspNetCore.Mvc.Testing from 9.0.0-preview.2.24128.4 to 9.0.0-preview.3.24172.13.
Bumps Microsoft.AspNetCore.TestHost from 9.0.0-preview.2.24128.4 to 9.0.0-preview.3.24172.13.

---
updated-dependencies:
- dependency-name: Microsoft.AspNetCore.Authentication.Google
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: Microsoft.AspNetCore.Mvc.Testing
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: Microsoft.AspNetCore.TestHost
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>

* Update prerelease iteration

Update to preview 3.

---------

Signed-off-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>
Co-authored-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>
Co-authored-by: Martin Costello <[email protected]>

* Update to ASP.NET Core 9 preview 4 (#879)

Update to preview 4 of ASP.NET Core 9.

* Update to ASP.NET Core 9 preview 5 (#893)

Update to preview 5 of ASP.NET Core 9.

* Fix baselines

Fix up package validation baselines.

* Update baseline

Update Docusign baseline for .NET 9.

* Update to ASP.NET Core 9 preview 6

Update to preview 6 of ASP.NET Core 9.

* Update to ASP.NET Core 9 preview 7 (#928)

Update to preview 7 of ASP.NET Core 9.

* Update Arcade (#941)

- Annual update of .NET Arcade for .NET 9.
- Fix new analysis warnings.

* Update to .NET 9 RC1

Update to release candidate 1 of ASP.NET Core 9.

* Bump System.Text.Encodings.Web

Bump transient package reference to fix build.

* Update to .NET 9 RC2

Update to release candidate 2 of .NET 9.

* Remove unused action

Remove unused setup action for NuGet.

* Update to .NET 9 GA
Update to the stable version of .NET 9.

---------

Signed-off-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>
Co-authored-by: aspnet-contrib-service-account[bot] <161750942+aspnet-contrib-service-account[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants