-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
[Blazor WASM] UserOptions not bound when published #41998
Comments
@aguacongas thanks for contacting us. We don't have any reason to believe this is a blazor specific behavior. Does the same code work on a console application? I suspect you need to match the casing in the configuration |
Hi @aguacongas. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@javiercn I tried to Pascal case the config but that didn't change the result. Much more weird, if you try to bind builder.Services.AddOidcAuthentication(options =>
{
// here the binding works.
builder.Configuration.Bind(nameof(options.ProviderOptions), options.ProviderOptions);
// doesn't work when published
builder.Configuration.Bind(nameof(options.UserOptions), options.UserOptions);
// options.UserOptions.RoleClaim = "role"; works always.
}).AddAccountClaimsPrincipalFactory<ClaimsPrincipalFactory>(); I updated the repo.
|
@aguacongas does it fail while you are running on development or after you have published the app |
Hi @aguacongas. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Only after published, |
@aguacongas thanks for the additional details. Then it's just a matter of it being trimmed. |
It seems that the type is missing the proper annotation. I think it needs to have something like [DynamicallyAccessedMembers(JsonSerialized)] |
As a workaround, assign a dummy value before you bind the value from config so that the trimmer doesn't discard the property. |
@javiercn is ok to propose a PR to fix it ? |
@aguacongas go for it |
I don't think adding /cc @eerhardt |
The We do have plans for a source generator (dotnet/runtime#44493) to fix this, but that hasn't been prioritized in .NET 7. For now, either not using ConfigurationBinder and bind the config manually, or preserving the properties with DynamicDependency or explicitly using the properties in code are the best options. |
@eerhardt thanks for the additional information. I think based on that, we'll wait for the runtime to deal with better config trimming as there is nothing we can do at our level other than enabling the warnings for RequiresUnreferencedCode which I don't think is something we plan to do in the near future. |
Is there an existing issue for this?
Describe the bug
When the
RemoteAuthenticationOptions.UserOptions
is bound to a configuration section,RoleClaim
is not well read from the configuration when plublished.builder.Services.AddOidcAuthentication(options =>
{
var providerOptions = options.ProviderOptions;
providerOptions.Authority = "https://www.theidserver.com/";
providerOptions.ClientId = "blazorissueclient";
providerOptions.ResponseType = "code";
providerOptions.DefaultScopes.Add("blazorissueapi");
// doesn't work when published
builder.Configuration.Bind(nameof(options.UserOptions), options.UserOptions);
// options.UserOptions.RoleClaim = "role"; works always.
}).AddAccountClaimsPrincipalFactory();
Expected Behavior
RoleClaim
should be read from the configuration and work as usingdotnet run
or when launched with VS.Steps To Reproduce
Using this repo.
The page display the forecast. Everthing is OK.
The page display :
Exceptions (if any)
No response
.NET Version
7.0.100-preview.4.22252.9
Anything else?
The text was updated successfully, but these errors were encountered: