如何更改Blazor WASM身份网络核心3.1消息“您已注销”,“检查登录状态”和“授权”?

时间:2020-10-16 01:38:59

标签: asp.net-core asp.net-identity identityserver4 blazor webassembly

我想知道如何个性化和/或更改此消息的语言,我想这与IdentityServer4有关。

有什么想法吗?

4 个答案:

答案 0 :(得分:1)

您要寻找的是RemoteAuthenticatorView

您可以在official documentation中找到答案的更多详细信息。

@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; }
}

答案 1 :(得分:0)

有必要在 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.";
}

我在Custom Authentication User Interface中找到了如何做的方法,顺便说一句,

如何使用IdentityServer4保护Blazor WebAssembly

阅读后,我还会检查RemoteAuthenticatorView Class

即使做到了这一点,仍然保留“ 正在授权... ”消息。

答案 2 :(得分:0)

您可以使用<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>

来源:

https://github.com/dotnet/aspnetcore/blob/1ed72f8f5f14dfc5a4ebc9d5d116d63792caa7fc/src/Components/test/testassets/BasicTestApp/AuthTest/AuthorizeViewCases.razor

答案 3 :(得分:0)

更改消息“正在授权...”

需要添加

<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>

您可以找到更多详情official documentation

相关问题