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) :
121
121
protected override async Task <HttpResponseMessage > SendAsync (
122
122
HttpRequestMessage request , CancellationToken cancellationToken )
123
123
{
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
+ {
126
133
throw new Exception (" No access token" );
134
+ }
127
135
128
136
request .Headers .Authorization =
129
137
new AuthenticationHeaderValue (" Bearer" , accessToken );
@@ -868,7 +876,14 @@ public class AuthenticationStateHandler(
868
876
{
869
877
var authStateProvider = circuitServicesAccessor .Services ?
870
878
.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
+
872
887
var user = authState ? .User ;
873
888
874
889
if (user ? .Identity is not null && user .Identity .IsAuthenticated )
You can’t perform that action at this time.
0 commit comments