0

I am getting an unauthorized error when loading images in my app. This is happening because image url is missing the token in authorization header. I want authorize the image url when token is present as a query parameter.

I found this quection is similar, but I am currently not able to use the answer since current application is using AzureAD to authorize the api's.

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(Configuration, "AzureAD");

     app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();

                endpoints.MapControllers().RequireAuthorization();

                endpoints.EnableDependencyInjection();
               
                endpoints.Select().Filter().OrderBy()
                         .Count().Expand().MaxTop(100).Count();  
            });

As in the answer I installed the Invio.Extensions.Authentication.JwtBearer and called AddQueryStringAuthentication().

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
   .AddMicrosoftIdentityWebApi(options =>
    {
      Configuration.Bind("AzureAD", options);
      options.AddQueryStringAuthentication();
    },
 options => { Configuration.Bind("AzureAD", options); });

Then I send the JWT token as a query parameter. But I still get the unauthorized error.

Gevin
  • 37
  • 4
  • Does this answer your question? [asp.net core JWT in uri query parameter?](https://stackoverflow.com/questions/45763149/asp-net-core-jwt-in-uri-query-parameter) – Mohammad Aghazadeh May 11 '22 at 06:26
  • @MohammadAghazadeh nope, since in current application I am working on using AzureAD for the authorization as I have added the sample code. – Gevin May 12 '22 at 16:39

0 Answers0