-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGreeterGrpc.razor
53 lines (42 loc) · 2.28 KB
/
GreeterGrpc.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@page "/greetergrpc"
@using BlazorTemplate.Shared
@inject Greeter.GreeterClient GreeterClient
@inject NavigationManager Navigation
<div>
<h1>Invoke gRPC service</h1>
<p>gRPC response from the server with authorization</p>
</div>
<AuthorizeView Roles="Administrators, Users">
<Authorized>
<div class="w-75 p-3">
<p>If you're logged in as a normal user (<i>user@example.com / Qwerty1234#</i>), you'll see this component but submitting your name won't work, (<i>you'll see an error in your browser's developer console</i>: <b>403: Forbidden</b>) because the gRPC service requires an Administrator Role.</p>
<p>Log in as an administrator (<i>admin@example.com / Qwerty1234#</i>) and this component will work.</p>
<p>
<input @bind="yourName" placeholder="Type your name ..." />
<button @onclick="GetGreeting" class="btn btn-primary">Call gRPC service</button>
</p>
<p>The 403 error, when logged in as a normal user, is expected behaviour. This will show you the gRPC service is working correctly, it only accepts users with an Administators Role</p>
<p>Server response: <b>@serverResponse</b></p>
</div>
</Authorized>
<NotAuthorized>
<div class="w-75 p-3">
<p>You'll need to <a href="" @onclick="IdentityLogin" @onclick:preventDefault><b>login</b></a> to view this component.</p>
<p>When you login as a normal user (<i>email: <b>user@example.com</b> password: <b>Qwerty1234#</b></i>), you'll see this component but when you submit your name you'll see an error (<i>in your browser's developer console</i>: <b>403: Forbidden</b>) because the gRPC service requires you to login as an Administrator (<i>email: <b>admin@example.com</b> Password: <b>Qwerty1234#</b></i>)</p>
</div>
</NotAuthorized>
</AuthorizeView>
@code {
string yourName = string.Empty;
string serverResponse;
async Task GetGreeting()
{
var request = new HelloRequest { Name = yourName };
var reply = await GreeterClient.SayHelloAsync(request);
serverResponse = reply.Message;
}
private void IdentityLogin()
{
Navigation.NavigateTo($"authentication/login?returnUrl=" + Uri.EscapeDataString(Navigation.Uri));
}
}