-
Notifications
You must be signed in to change notification settings - Fork 15
[dotnet] Experimental platform-specific token provider with dependency injection support #492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11cf896
Experimental token provider implementation
tmarkovski cc55181
Host tests
tmarkovski d8c858c
Add extension methods
tmarkovski a933f8c
Remove Browser project
tmarkovski ae3359e
Cleanup
tmarkovski 68f29be
Update default tests to staging
tmarkovski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,25 @@ | ||
| <Project> | ||
| <!-- Set common properties regarding assembly information and nuget packages --> | ||
| <PropertyGroup> | ||
| <Authors>Trinsic Engineering Team</Authors> | ||
| <Company>Trinsic</Company> | ||
| <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
| <PackageProjectUrl>https://github.com/trinsic-id/sdk</PackageProjectUrl> | ||
| <PackageTags>Trinsic</PackageTags> | ||
| <Product>Trinsic SDK for NET</Product> | ||
| <RepositoryUrl>https://github.com/trinsic-id/sdk.git</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| <Version>1.0.0</Version> | ||
| <IncludeSymbols>true</IncludeSymbols> | ||
| <SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
| </PropertyGroup> | ||
| <!-- Common compile parameters --> | ||
| <PropertyGroup> | ||
| <!-- We use full (Windows PDBs) until cross platform support for source link will get better --> | ||
| <DebugType>full</DebugType> | ||
| <LangVersion>latest</LangVersion> | ||
| <NoWarn>$(NoWarn);1591</NoWarn> | ||
| <Nullable>enable</Nullable> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| </PropertyGroup> | ||
| <!-- Set common properties regarding assembly information and nuget packages --> | ||
| <PropertyGroup> | ||
| <Authors>Trinsic Engineering Team</Authors> | ||
| <Company>Trinsic</Company> | ||
| <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
| <PackageProjectUrl>https://github.com/trinsic-id/sdk</PackageProjectUrl> | ||
| <PackageTags>Trinsic</PackageTags> | ||
| <Product>Trinsic SDK for NET</Product> | ||
| <RepositoryUrl>https://github.com/trinsic-id/sdk.git</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| <Version>1.0.0</Version> | ||
| <IncludeSymbols>true</IncludeSymbols> | ||
| <SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
| </PropertyGroup> | ||
| <!-- Common compile parameters --> | ||
| <PropertyGroup> | ||
| <!-- We use full (Windows PDBs) until cross platform support for source link will get better --> | ||
| <DebugType>full</DebugType> | ||
| <LangVersion>latest</LangVersion> | ||
| <NoWarn>$(NoWarn);1591</NoWarn> | ||
| <Nullable>enable</Nullable> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Trinsic; | ||
| using Trinsic.Services.Common.V1; | ||
| using Xunit; | ||
|
|
||
| namespace Tests; | ||
|
|
||
| public class HostTests | ||
| { | ||
| [Fact(DisplayName = "Test default service host")] | ||
| public async Task TestGenericHost() { | ||
| var host = Host | ||
| .CreateDefaultBuilder() | ||
| .ConfigureServices(services => { | ||
| services.AddTrinsic(); | ||
| }).Build(); | ||
|
|
||
| await host.StartAsync(); | ||
|
|
||
| var providerService = host.Services.GetService<ProviderService>(); | ||
| var accountService = host.Services.GetRequiredService<AccountService>(); | ||
|
|
||
| providerService.Should().NotBeNull(); | ||
| accountService.Should().NotBeNull(); | ||
|
|
||
| accountService.Options.ServerEndpoint.Should().Be(ServiceBase.DefaultServerEndpoint); | ||
| accountService.Options.ServerPort.Should().Be(ServiceBase.DefaultServerPort); | ||
| accountService.Options.ServerUseTls.Should().Be(ServiceBase.DefaultServerUseTls); | ||
| accountService.Options.DefaultEcosystem.Should().Be(ServiceBase.DefaultEcosystem); | ||
| accountService.Options.AuthToken.Should().Be(string.Empty); | ||
| accountService.TokenProvider.Should().BeOfType<FileTokenProvider>(); | ||
|
|
||
| await host.StopAsync(); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Test configured service host")] | ||
| public async Task TestConfiguredGenericHost() { | ||
| var host = Host | ||
| .CreateDefaultBuilder() | ||
| .ConfigureServices(services => { | ||
| services.AddTrinsic(options => { | ||
| options.AuthToken = "auth"; | ||
| options.DefaultEcosystem = "eco"; | ||
| options.ServerEndpoint = "example.com"; | ||
| options.ServerPort = 42; | ||
| options.ServerUseTls = true; | ||
| }); | ||
| }).Build(); | ||
|
|
||
| await host.StartAsync(); | ||
|
|
||
| var providerService = host.Services.GetService<ProviderService>(); | ||
| var accountService = host.Services.GetRequiredService<AccountService>(); | ||
|
|
||
| providerService.Should().NotBeNull(); | ||
| accountService.Should().NotBeNull(); | ||
|
|
||
| accountService.Options.ServerEndpoint.Should().Be("example.com"); | ||
| accountService.Options.ServerPort.Should().Be(42); | ||
| accountService.Options.ServerUseTls.Should().BeTrue(); | ||
| accountService.Options.DefaultEcosystem.Should().Be("eco"); | ||
| accountService.Options.AuthToken.Should().Be("auth"); | ||
|
|
||
| await host.StopAsync(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that this saves the token as a default name and caches it in the concrete implementations - do we want to standardize on a naming scheme? Something like
<ecosystemID>.<email>? though there might not always be an email.Everything gets saved as the default name now, correct? How will users switch to use another token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The token provider is completely ignored if they pass auth token through the options, this is how they would use multi-user setups.
As you pointed out, the implementation does leave room for named tokens, once we have a clear path on how to do this. I'm curious to dig further on how many use cases there are where multi user tokens would be needed, outside of our unit tests and dev work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think named tokens will be very useful in the future when developers are integrating multiple trinsic ecosystems together. Having an easy way to work with named tokens now will just be icing on the cake in the future. Also, don't forget our unit tests and dev work (as you mentioned).
I am also envisioning a future in which we are developing the sample applications in conjunction with customers @michaeldboyd can back me up on this, and being able to switch between our ecosystem and our customer's ecosystem would be really handy.