#asp.net-core #asp.net-identity #identityserver4 #blazor #webassembly
#asp.net-core #asp.net-identity #identityserver4 #blazor #webassembly
Вопрос:
Мне нужно знать, как персонализировать и / или изменить язык для этих сообщений, я полагаю, это связано с IdentityServer4.
Есть идеи?
Ответ №1:
То, что вы ищете, это RemoteAuthenticatorView
.
Вы можете найти более подробную информацию о своем ответе в официальной документации.
@page "/security/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action">
@*authentication/login*
<LoggingIn></LoggingIn>
@*authentication/login-callback*
<CompletingLoggingIn></CompletingLoggingIn>
@*authentication/login-failed*
<LogInFailed></LogInFailed>
@*authentication/logout*
<LogOut></LogOut>
@*authentication/logout-callback*
<CompletingLogOut></CompletingLogOut>
@*authentication/logout-failed*
<LogOutFailed></LogOutFailed>
@*authentication/logged-out*
<LogOutSucceeded></LogOutSucceeded>
@*authentication/profile*
<UserProfile></UserProfile>
@*authentication/register*
<Registering></Registering>
</RemoteAuthenticatorView>
@code{
[Parameter]
public string Action { get; set; }
}
Ответ №2:
Необходимо добавить некоторые теги в компонент Authentication.razor:
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action">
<LogInFailed>
<div class="alert alert-danger" role="alert">@strLogInFailed</div>
</LogInFailed>
<LogOut>
<div class="alert alert-info" role="alert">@strLogOut</div>
</LogOut>
<LogOutSucceeded>
<div class="alert alert-success" role="alert">@strLogOutSucceeded</div>
</LogOutSucceeded>
<LoggingIn>
<div class="alert alert-info" role="alert">@strLoggingIn</div>
</LoggingIn>
<CompletingLoggingIn>
<div class="alert alert-success" role="alert">@strCompletingLoggingIn</div>
</CompletingLoggingIn>
</RemoteAuthenticatorView>
@code {
[Parameter] public string Action { get; set; }
string strLogInFailed = "Your login was not successful.";
string strLogOut = "Trying to close your session.";
string strLogOutSucceeded = "Your session has been closed successfully.";
string strLoggingIn = "Redirecting to the login screen.";
string strCompletingLoggingIn = "Your login was successful.";
}
Я нашел, как это сделать в: Пользовательский интерфейс пользователя аутентификации, который, кстати, многое объясняет на
Как защитить Blazor WebAssembly с помощью IdentityServer4
После прочтения я также проверяю класс RemoteAuthenticatorView
Даже после этого все равно сохраняется сообщение «Авторизация …«.
Ответ №3:
Чтобы изменить сообщение «Авторизация …»
Необходимо добавить
<Authorizing>
<h1>Authorization in progress</h1>
<p>Only visible while authorization is in progress.</p>
</Authorizing>
в файл App.razor
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData"
DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<h1>Sorry</h1>
<p>You're not authorized to reach this page.</p>
<p>You may need to log in as a different user.</p>
</NotAuthorized>
<Authorizing>
<h1>Authorization in progress</h1>
<p>Only visible while authorization is in progress.</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<h1>Sorry</h1>
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Вы можете найти более подробную официальную документацию.
Ответ №4:
Вы можете использовать <Authorizing>
тег для переопределения текста по умолчанию.
<AuthorizeView>
<Authorizing>
<p class="authorizing">Authorizing...</p>
</Authorizing>
<Authorized>
<p class="authorized">Welcome, @context.User.Identity.Name!</p>
</Authorized>
<NotAuthorized>
<p class="not-authorized">You're not authorized, @(context.User.Identity.Name ?? "anonymous")</p>
</NotAuthorized>
</AuthorizeView>
Источник: