Skip to content
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

Fix for #2371 #2374

Merged
merged 11 commits into from
Aug 13, 2023
Merged

Fix for #2371 #2374

merged 11 commits into from
Aug 13, 2023

Conversation

jmprieur
Copy link
Collaborator

Fix for #2371

Description

In .NET 5+, we now use the DefaultTokenAcquisitionHost (the host for SDK apps) instead of the Asp.NET core one, when the service collection was not initialized by ASP.NET Core (that is the IWebHostEnvironment is not present in the collection.

If developers want the ASP.NET Core host, they would need to use the WebApplication.CreateBuilder().Services instead of instanciating a simple service collection.

Fixes #2371

In .NET 5+, we now use the DefaultTokenAcquisitionHost (the host for SDK apps) instead of the
Asp.NET core one, when the service collection was not initialized by ASP.NET Core (that is
the `IWebHostEnvironment` is not present in the collection.

If developers want the ASP.NET Core host, they would need to use the WebApplication.CreateBuilder().Services instead
of instanciating a simple service collection.
@jmprieur jmprieur requested review from jennyf19 and MZOLN August 10, 2023 23:03
@@ -33,6 +33,16 @@ public TokenAcquirer()
TokenAcquirerFactory.ResetDefaultInstance(); // Test only
}

[Fact]
public void TokenAcquirerFactoryDoesNotUseAspNetCoreHost()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test project only tests NET7.0 and NET8.0 it will never test netstandard, which is part of the change.
Would it make sense to add netstandard as part of the target to the test project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed with the fix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we should still test the whole library for netstandard2.0 dont you think? It`s a release target after all.

- Adds a PrincipalExtensionsForSecurityTokens.GetBootstrapToken method that extracts
  a Security token from the bootstrap context (+unit tests)
- In Web APIs, GetAuthenticationResultForUserAsync tries the BootstrapContext first
Copy link
Collaborator

@jennyf19 jennyf19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

jmprieur and others added 9 commits August 13, 2023 13:47
- Supports extended strings (StringsValues) as the BootstrapContext
…sForSecurityTokens.cs

Co-authored-by: jennyf19 <jeferrie@microsoft.com>
…sForSecurityTokens.cs

Co-authored-by: jennyf19 <jeferrie@microsoft.com>
…tyTokensTests.cs

Co-authored-by: jennyf19 <jeferrie@microsoft.com>
@jmprieur jmprieur merged commit a233610 into master Aug 13, 2023
@jmprieur jmprieur deleted the jmprieur/Fix2371 branch October 12, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Downstream API calls to be used outside of ASP.NET Core Hosting environment [Feature Request]
3 participants