You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.1 KiB
62 lines
2.1 KiB
3 years ago
|
using Duende.IdentityServer.Services;
|
||
|
using Easy.DI;
|
||
|
using Easy.Result;
|
||
|
using Identity.Api.DDD.Contracts.Dtos;
|
||
|
using Identity.Api.DDD.Contracts.Models;
|
||
|
using Microsoft.JSInterop;
|
||
|
|
||
|
namespace Identity.Api.Pages;
|
||
|
|
||
|
public class SpaService : ITransientDependency
|
||
|
{
|
||
|
private readonly IJSRuntime JS;
|
||
|
private readonly string BaseUrl;
|
||
|
public SpaService(IJSRuntime iJSRuntime,
|
||
|
IServerUrls iServerUrls)
|
||
|
{
|
||
|
JS = iJSRuntime;
|
||
|
BaseUrl = $"{iServerUrls.BaseUrl}/api/spa";
|
||
|
}
|
||
|
public async Task<string> PostLogInAsync(LoginDto loginDto)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/login";
|
||
|
return await JS.InvokeAsync<string>("PostLogInAsync", url, loginDto);
|
||
|
}
|
||
|
public async Task<bool> PostConsentAsync(ConsentDto consentDto)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/consent";
|
||
|
return await JS.InvokeAsync<bool>("PostConsentAsync", url, consentDto);
|
||
|
}
|
||
|
public async Task<ContextModel> GetContextAsync(string returnUrl)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/context?returnUrl={Uri.EscapeDataString(returnUrl)}";
|
||
|
var res = await JS.InvokeAsync<ApiResultValue<ContextModel>>("GetContextAsync", url);
|
||
|
return res?.Result ?? new ContextModel();
|
||
|
}
|
||
|
public async Task<LogOutModel> GetLogOutAsync(string logOutId)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/logout/{logOutId}";
|
||
|
var res = await JS.InvokeAsync<ApiResultValue<LogOutModel>>("GetLogOutAsync", url);
|
||
|
return res?.Result ?? new LogOutModel();
|
||
|
}
|
||
|
public async Task<LogOutModel> PostLogOutAsync(string logOutId)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/logout/{logOutId}";
|
||
|
var res = await JS.InvokeAsync<ApiResultValue<LogOutModel>>("PostLogOutAsync", url);
|
||
|
return res?.Result ?? new LogOutModel();
|
||
|
}
|
||
|
public async Task<ErrorModel> GetErrorAsync(string errorId)
|
||
|
{
|
||
|
string url = $"{BaseUrl}/error?errorId={errorId}";
|
||
|
var res = await JS.InvokeAsync<ApiResultValue<ErrorModel>>("GetErrorAsync", url);
|
||
|
return res?.Result ?? new ErrorModel();
|
||
|
}
|
||
|
|
||
|
public async Task LocationAsync(string requestUrl)
|
||
|
{
|
||
|
await JS.InvokeVoidAsync("LocationAsync", requestUrl);
|
||
|
}
|
||
|
|
||
|
//LocationAsync
|
||
|
}
|