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.
 
 
 
 
 

61 lines
2.2 KiB

using Duende.IdentityServer.Services;
using Easy.DI;
using Easy.Result;
using IdentityServer.DDD.Contracts.Inputs;
using IdentityServer.DDD.Contracts.Models;
using Microsoft.JSInterop;
namespace IdentityServer.Pages.Authentication;
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<ApiResultValue<string>> PostLogInAsync(LoginInput loginDto)
{
string url = $"{BaseUrl}/login";
return await JS.InvokeAsync<ApiResultValue<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
}