sotsera / sotsera.blazor.oidc

OpenID Connect client for Blazor client-side projects
https://blazor-oidc.sotsera.com/
Apache License 2.0
20 stars 8 forks source link

Redirection does not work when UsePathBase is used #10

Closed pablopioli closed 4 years ago

pablopioli commented 4 years ago

When the autentication finishes NavigationManager throws an exception

WASM: System.AggregateException: One or more errors occurred. (The URI 'http://192.168.11.101:16370/' is not contained by the base URI 'http://192.168.11.101:16370/app1/'.)
WASM:   at Microsoft.AspNetCore.Components.NavigationManager.Validate (System.Uri baseUri, System.String uri) <0x23bd400 + 0x0004c> in <cbf249d7f04d4fa18d15bfae8ef7f389>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.AspNetCore.Components.NavigationManager.set_Uri (System.String value) <0x23bd338 + 0x0000a> in <cbf249d7f04d4fa18d15bfae8ef7f389>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.AspNetCore.Components.NavigationManager.Initialize (System.String baseUri, System.String uri) <0x23c0998 + 0x00076> in <cbf249d7f04d4fa18d15bfae8ef7f389>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.AspNetCore.Blazor.Services.WebAssemblyNavigationManager.EnsureInitialized () <0x23b2108 + 0x0004c> in <02062f8b8dc04354a1a18488dffb79d7>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.AspNetCore.Components.NavigationManager.AssertInitialized () <0x23b1ec8 + 0x00010> in <cbf249d7f04d4fa18d15bfae8ef7f389>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.AspNetCore.Components.NavigationManager.get_BaseUri () <0x23b1e10 + 0x00002> in <cbf249d7f04d4fa18d15bfae8ef7f389>:0 
blazor.webassembly.js:1
WASM:   at Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions+<>c__DisplayClass0_0.<AddOidc>b__0 (System.IServiceProvider b) <0x238aa38 + 0x00040> in <9f01b729dbce4393b36d431eab24bcc9>:0 
blazor.webassembly.js:1
WASM:   at (wrapper delegate-invoke) System.Func`2[System.IServiceProvider,Sotsera.Blazor.Oidc.OidcSettings].invoke_TResult_T(System.IServiceProvider)
pablopioli commented 4 years ago

Closing this as it's totally my fault.

I was trying to use this library in a ASP.NET Core hosted app. As outlined in the guidance (included in the readme) in this case the better option are server cookies and not JWT in the client.

ghidello commented 4 years ago

Hi and sorry for the late response: this has been a busy period! :smile:

I'll reopen this issue because there could be a problem with blazor wasm too when the application is not hosted in the site root. The issue belongs to this line https://github.com/sotsera/sotsera.blazor.oidc/blob/085d8276447f30118928440b958690c625450485/src/Sotsera.Blazor.Oidc/CallbackPages/AuthenticationRedirect.razor#L17 where there is a default redirect to the / route after a redirect login. The same happens in the redirect logout. I'll have to think about how to make these redirect routes configurable or, at the very least, redirect to NavigationManager.BaseUri.

Thanks for reaching out!

ghidello commented 4 years ago

In the mean time you can copy these pages in your application, change the offending redirect and configure them as callback URIs using the AuthenticationRedirectCallbackUri and LogoutRedirectCallbackUri configuration options.

ghidello commented 4 years ago

Hi, for now I ended up using NavigationManager.BaseUri in the redirect callback pages. Can you please test this new version and see if the problem have been fixed?

pablopioli commented 4 years ago

Hi and sorry for the late response: this has been a busy period! 😄

Don't worry. I assume everyone has a life to live, if you have problems here is the source code, go and fix it yourself.

I will test it in the context of static file hosting https://github.com/sotsera/sotsera.blazor.oidc/issues/11 will publish a complete sample if I can make to work.

Thanks!

pablopioli commented 4 years ago

Working with and without PathBase, so closing the issue.