The autogenerated oidc configuration file gives localhost instead of my public URL. How do I set it up so that it gives the right URL?
http://167.172.118.170/.well-known/openid-configuration
In the login link on my test site: http://167.172.118.170/authentication/login the login redirects to a localhost address instead of the public 167.172.118.170 address, like this:
http://localhost:5008/connect/authorize?client_id=MyProject.Web.Client&redirect_uri=http%3A%2F%2F167.172.118.170%2Fauthentication%2Flogin-callback&response_type=code&scope=MyProject.Web.ServerAPI%20openid%20profile&state=b18bc58127b54ea9aaff1a210b7899de&code_challenge=OOIuUi2yJnYcjZZIu4LveJfbLz0Na7IKkzlDTKb81IE&code_challenge_method=S256&response_mode=query
How do I configure it so that it goes to http://167.172.118.170/connect/authorize instead?
This is the content of the authentication razor file:
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />
@code{
[Parameter] public string Action { get; set; }
}
There is no option to provide the server URL.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Your application is not configured properly.
You need to configure your identity sever using similar code like below in your Program.cs
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("OidcConfiguration", options.ProviderOptions);
});
“OidcConfiguration” comes from your configuration file and will have parameters like below:
"OidcConfiguration": {
"Authority": "https://YourIdentityServerIP",
"ClientId": "YourClienId",
"DefaultScopes": [
"openid",
"profile",
"api"
],
"RedirectUri": "https://yourclientapp/authentication/login-callback",
"PostLogoutRedirectUri": "https://yourclientapp/authentication/logout-callback",
"ResponseType": "code"
}
You can use this two links to see how i configured mine in a pet project
Program Files:
https://github.com/oteebest/edu-client-blazor/blob/master/CBTClient/Program.cs
appsetting.json
https://github.com/oteebest/edu-client-blazor/blob/master/CBTClient/wwwroot/appsettings.json
Method 2
The solution was to add the following:
using IdentityServer4.Extensions;
//...
app.Use((ctx, next) =>
{
ctx.SetIdentityServerOrigin("http://167.172.118.170");
return next();
});
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0