AzUrlShortener icon indicating copy to clipboard operation
AzUrlShortener copied to clipboard

URL Manager Error

Open bseran opened this issue 4 years ago • 4 comments

After logging into TinyBlazorAdmin and going to the URL Manager, I receive a message stating "an unhandled error has occured. Reload". When I click reload, it brings me to a 404: Not Found Azure screen.

bseran avatar Jun 03 '21 18:06 bseran

I also have this behaviour on a fresh deploy.

DamienCalvert avatar Jun 08 '21 11:06 DamienCalvert

gents, this is related to the user authentication method which has changed since version 1. In the UrlList api endpoint, it requires a specific claim for "GivenName" which doesn't exist if you haven't set up AD, in the source code the CanAuthorize method these lines in file utility.cs:

        if (principal.FindFirst(ClaimTypes.GivenName) is null)
        {
            log.LogError("Claim not Found");
            return new BadRequestObjectResult(new
            {
                message = "Claim not Found",
                StatusCode = System.Net.HttpStatusCode.BadRequest
            });
        }

And also immeduately after calling the "CanAuthorize" method, if the request is now valid (if you removed the section above), it will try get the missing claim still and fail:

            if (invalidRequest != null)
            {
                return invalidRequest;
            }
            else
            {
              userId = principal.FindFirst(ClaimTypes.GivenName).Value;
               log.LogInformation("Authenticated user {user}.", userId);**
            }

If you don't want to use AD you can comment out these out in your own branch/version of the project.

I'm in the process of setting up AD on mine, but I used the commented out method and it works great again.

ThDJRenton avatar Jun 08 '21 11:06 ThDJRenton

I don't know what should be done more. In "Tiny Blazor Admin" works only "Log in" functionality. When I'm trying to open "URLs Manager" or "Click Statistics" I receive An unhandled error has occurred. Reload In console following output:

blazor.webassembly.js:1 info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful.
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: net_http_client_http_browser_baseaddress_required Arg_ParamName_Name, value
System.ArgumentException: net_http_client_http_browser_baseaddress_required Arg_ParamName_Name, value
   at System.Net.Http.HttpClient.CheckBaseAddress(Uri baseAddress, String parameterName)
   at System.Net.Http.HttpClient.set_BaseAddress(Uri value)
   at TinyBlazorAdmin.Program.<>c__DisplayClass0_0.<Main>b__3(HttpClient client)
   at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateClient(String name)
   at TinyBlazorAdmin.Data.UrlShortenerSecuredService..ctor(IHttpClientFactory factory)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, Object[] parameters, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__1(ServiceProviderEngineScope p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass6_0.<CreateInitializer>g__Initialize|2(IServiceProvider serviceProvider, IComponent component)
   at Microsoft.AspNetCore.Components.ComponentFactory.PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance)
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateComponent(Type componentType)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame& frame, Int32 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
d.printErr @ blazor.webassembly.js:1

Firstly I changed ClaimTypes.GivenName to ClaimTypes.Name then to ClaimTypes.NameIdentifier and in the last commit I comment all calls of ClaimTypes and it still does not work.

mccsoft avatar Jun 11 '21 05:06 mccsoft

I suppose MS has changed something in workflow with an authorization. If compare the screenshot from an instruction https://github.com/FBoucher/TinyBlazorAdmin/blob/main/medias/ConfigAzFuncADapp.png with what we have image there is a huge difference in a protocol. As result if I push to my repo TinyBlazorAdmin\src\TinyBlazorAdmin\wwwroot\appsettings.json file with following settings

  "UrlShortenerSecuredServiceApi": {
    "Endpoint": "https://__Function_URL__.azurewebsites.net/"
  },

as it's written in the instruction I won't be able to do authorization with following error:

Request Id: a859d214-610d-416c-a308-69c72d460e00
Correlation Id: 4af7e331-5f29-424d-a6be-f4fe3d1ff6f0
Timestamp: 2021-06-08T07:37:34Z
Message: AADSTS500011: The resource principal named https://__Function_URL__.azurewebsites.net was not found in the tenant named xxxx-xx-xx-xx-xxxx. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.

and if I push the file with following settings

  "UrlShortenerSecuredServiceApi": {
    "Endpoint": "api://www-ww-ww-www/"
  },

then I will be able to pass authorization but will start receiving the error from previous comment. So, look like you have to use in the appsetting.json file two different endpoints. One for authorization and another one for backend.

mccsoft avatar Jun 11 '21 09:06 mccsoft