File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
aspnetcore/blazor/security Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -121,9 +121,17 @@ public class TokenHandler(IHttpContextAccessor httpContextAccessor) :
121121 protected override async Task <HttpResponseMessage > SendAsync (
122122 HttpRequestMessage request , CancellationToken cancellationToken )
123123 {
124- var accessToken = httpContextAccessor .HttpContext ?
125- .GetTokenAsync (" access_token" ).Result ??
124+ if (httpContextAccessor .HttpContext is null )
125+ {
126+ throw new Exception (" HttpContext.Current not available." );
127+ }
128+
129+ var accessToken = await httpContextAccessor .HttpContext .GetTokenAsync (" access_token" );
130+
131+ if (accessToken is null )
132+ {
126133 throw new Exception (" No access token" );
134+ }
127135
128136 request .Headers .Authorization =
129137 new AuthenticationHeaderValue (" Bearer" , accessToken );
@@ -868,7 +876,14 @@ public class AuthenticationStateHandler(
868876 {
869877 var authStateProvider = circuitServicesAccessor .Services ?
870878 .GetRequiredService <AuthenticationStateProvider >();
871- var authState = authStateProvider ? .GetAuthenticationStateAsync ().Result ;
879+
880+ if (authStateProvider is null )
881+ {
882+ throw new Exception (" AuthenticationStateProvider not available." );
883+ }
884+
885+ var authState = await authStateProvider .GetAuthenticationStateAsync ();
886+
872887 var user = authState ? .User ;
873888
874889 if (user ? .Identity is not null && user .Identity .IsAuthenticated )
You can’t perform that action at this time.
0 commit comments