mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
chore: WG login redirection and parameters parsing implemented
This commit is contained in:
1 parent
83681c6b42
commit
8a5d286560
4 files changed
+95
-4
No files matched your search
@@ -0,0 +1,28 @@
|
||||
using MediatR;
|
||||
using WotBlitzStatisticsPro.Blazor.GraphQl;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Messages
|
||||
{
|
||||
public class RedirectFromWgLoginMessage : INotification
|
||||
{
|
||||
public RealmType Realm { get; }
|
||||
public string NickName { get; }
|
||||
public long AccountId { get; }
|
||||
public string AccessToken { get; }
|
||||
public long ExpiresAt { get; }
|
||||
|
||||
public RedirectFromWgLoginMessage(
|
||||
RealmType realm,
|
||||
string nickName,
|
||||
long accountId,
|
||||
string accessToken,
|
||||
long expiresAt)
|
||||
{
|
||||
Realm = realm;
|
||||
NickName = nickName;
|
||||
AccountId = accountId;
|
||||
AccessToken = accessToken;
|
||||
ExpiresAt = expiresAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
@page "/login/{Realm}"
|
||||
@using WotBlitzStatisticsPro.Blazor.Messages
|
||||
@using MediatR
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IMediator Mediator
|
||||
<h3>Login</h3>
|
||||
|
||||
<p>@realmValue | @accountId | @nickName | @accessToken | @expiresAt</p>
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string Realm { get; set; } = "Asia";
|
||||
|
||||
string nickName;
|
||||
long accountId;
|
||||
string accessToken;
|
||||
long expiresAt;
|
||||
RealmType realmValue = RealmType.Asia;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var query = QueryHelpers.ParseQuery(NavigationManager.Uri);
|
||||
if (query.ContainsKey("status") &&
|
||||
query.ContainsKey("access_token") &&
|
||||
query.ContainsKey("nickname") &&
|
||||
query.ContainsKey("account_id") &&
|
||||
query.ContainsKey("expires_at"))
|
||||
{
|
||||
string status = query["status"].FirstOrDefault();
|
||||
if (status == "ok")
|
||||
{
|
||||
nickName = query["nickname"].FirstOrDefault();
|
||||
accountId = Convert.ToInt64(query["account_id"].FirstOrDefault());
|
||||
accessToken = query["access_token"].FirstOrDefault();
|
||||
expiresAt = Convert.ToInt64(query["expires_at"].FirstOrDefault());
|
||||
Enum.TryParse(Realm, out realmValue);
|
||||
|
||||
await Mediator.Publish(new RedirectFromWgLoginMessage(realmValue, nickName, accountId, accessToken, expiresAt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Radzen;
|
||||
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||
@@ -9,20 +10,26 @@ using WotBlitzStatisticsPro.Blazor.Pages;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
public class WargamingLoginService: INotificationHandler<LoginToWgMessage>, INotificationHandler<RedirectToWgLoginMessage>
|
||||
public class WargamingLoginService:
|
||||
INotificationHandler<LoginToWgMessage>,
|
||||
INotificationHandler<RedirectToWgLoginMessage>,
|
||||
INotificationHandler<RedirectFromWgLoginMessage>
|
||||
{
|
||||
private readonly IGraphQlBackendService _graphQlBackendService;
|
||||
private readonly DialogService _dialogService;
|
||||
private readonly IStringLocalizer<App> _localizer;
|
||||
private readonly NavigationManager _navigationManager;
|
||||
|
||||
public WargamingLoginService(
|
||||
IGraphQlBackendService graphQlBackendService,
|
||||
DialogService dialogService,
|
||||
IStringLocalizer<App> localizer)
|
||||
IStringLocalizer<App> localizer,
|
||||
NavigationManager navigationManager)
|
||||
{
|
||||
_graphQlBackendService = graphQlBackendService;
|
||||
_dialogService = dialogService;
|
||||
_localizer = localizer;
|
||||
_navigationManager = navigationManager;
|
||||
}
|
||||
|
||||
public async Task Handle(LoginToWgMessage notification, CancellationToken cancellationToken)
|
||||
@@ -36,8 +43,17 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
public async Task Handle(RedirectToWgLoginMessage notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var url = await _graphQlBackendService.GetWgLoginUrl(notification.Realm);
|
||||
// ToDo: take a look to redirect message in previous app reincarnation
|
||||
url = $"{url}&redirect_uri=https://developers.wargaming.net/reference/all/wot/auth/login/";
|
||||
var baseUri = _navigationManager.BaseUri;
|
||||
url = $"{url}&redirect_uri={baseUri}login/{notification.Realm}";
|
||||
|
||||
_navigationManager.NavigateTo(url);
|
||||
}
|
||||
|
||||
public Task Handle(RedirectFromWgLoginMessage notification, CancellationToken cancellationToken)
|
||||
{
|
||||
// ToDo: Store login info to local storage
|
||||
// ToDo: Send OpenPlayerInfoMessage with isLoggedIn = true
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.5" />
|
||||
|
||||
Reference in new issue
Block a user