Skip to content

Commit 1d59a11

Browse files
committed
Preserve RemoteAuthenticationContext during JS interop
1 parent aefa4ca commit 1d59a11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
108108
RemoteAuthenticationContext<TRemoteAuthenticationState> context)
109109
{
110110
await EnsureAuthService();
111-
var result = await JsRuntime.InvokeAsync<RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signIn", context);
111+
var result = await JSInvokeWithContextAsync<RemoteAuthenticationContext<TRemoteAuthenticationState>, RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signIn", context);
112112
await UpdateUserOnSuccess(result);
113113

114114
return result;
@@ -130,7 +130,7 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
130130
RemoteAuthenticationContext<TRemoteAuthenticationState> context)
131131
{
132132
await EnsureAuthService();
133-
var result = await JsRuntime.InvokeAsync<RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signOut", context);
133+
var result = await JSInvokeWithContextAsync<RemoteAuthenticationContext<TRemoteAuthenticationState>, RemoteAuthenticationResult<TRemoteAuthenticationState>>("AuthenticationService.signOut", context);
134134
await UpdateUserOnSuccess(result);
135135

136136
return result;
@@ -187,6 +187,11 @@ public virtual async ValueTask<AccessTokenResult> RequestAccessToken(AccessToken
187187
} : null);
188188
}
189189

190+
// JSRuntime.InvokeAsync does not properly annotate all arguments with DynamicallyAccessedMembersAttribute. https://github.com/dotnet/aspnetcore/issues/39839
191+
// Calling JsRuntime.InvokeAsync directly results allows the RemoteAuthenticationContext.State getter to be trimmed. https://github.com/dotnet/aspnetcore/issues/49956
192+
private ValueTask<TResult> JSInvokeWithContextAsync<[DynamicallyAccessedMembers(JsonSerialized)] TContext, [DynamicallyAccessedMembers(JsonSerialized)] TResult>(
193+
string identifier, TContext context) => JsRuntime.InvokeAsync<TResult>(identifier, context);
194+
190195
private string GetReturnUrl(string? customReturnUrl) =>
191196
customReturnUrl != null ? Navigation.ToAbsoluteUri(customReturnUrl).AbsoluteUri : Navigation.Uri;
192197

0 commit comments

Comments
 (0)