Send a request to an API with JWT token from iOS with an Blazor application gets error

Enrico Rossini 201 Reputation points
2022-12-07T13:38:56.27+00:00

I had this behaviour roughly a year ago. Now, in my new application, I'm facing the same issue, but the old solution didn't work. So, I have a Blazor application with NET6. To call the API, I add the user token. I have a function that read the token from the cache or from IAccessTokenProvider.

IAccessTokenProvider _accessToken;  
private async Task<AccessToken> RequestUserToken()  
{  
    try  
    {  
        var tokenResult = await _accessToken.RequestAccessToken();  
        tokenResult.TryGetToken(out var token);  
  
        Console.WriteLine(token);  
  
        return token;  
    }  
    catch (AccessTokenNotAvailableException aex)  
    {  
        throw new ApplicationException($"Exception {aex}");  
    }  
    catch (Exception ex)  
    {  
        throw new ApplicationException(  
            $"AccessTokenNotAvailable Exception Exception {ex}");  
    }  
}  

The application sends successfully requests to the API from Windows and Android. When I run the application on iOS devices, the token is not found and then there is an error. I use the latest version of both iOS and macOS.

268130-image.png]2

In Windows the Developer Console is quite clean

268139-image.png

How can I get the token in Blazor from an iOS/macOS device?

Update

I'm running the web application on a Mac. The application is working fine with Microsoft Edge and Chrome but not with Safari.

On iPhone and iPad, I have issue with the token on Safari and Chrome. It works fine on Microsoft Edge.

Developer technologies .NET Blazor
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.