Search code examples
asp.net-coreamazon-cognitoblazorblazor-client-side

Not able to get access token with Blazor WASM with AWS Cognito because X-Frame-Options is set to DENY


I am using Blazor WebWebAssembly as my frontend and AWS Cognito as my IDP.

I can successfully login to AWS Cognito, but not able to get the access token with the following code because of the “X-Frame-Options“ directive set to “DENY“ error.

 private async Task WriteTokenToConsole()
    {
        var tokenResult = await TokenProvider.RequestAccessToken();
        if (tokenResult.TryGetToken(out var token))
        {
            System.Diagnostics.Debug.WriteLine(token.Value);
        }
    }

Yet, if I switch the IDP to Identity Server 4, I can get the access token no problem.

According to this comment https://github.com/dotnet/aspnetcore/issues/22651#issuecomment-640565340 , it is because Cognito is not being standard compliant?

Is there a way to work around this?

Thank you


Solution

  • I was able to access it via the code on: How do I get the id_token in Blazor WebAssembly after authenticating with OpenId (Cognito)?

    I've since abstracted that into an extension to JSRuntime to make it easier to re-use across my code. But it seems to work fine for me.