using FitConnect.Encryption; using FitConnect.Models; using FitConnect.Services; using FitConnect.Services.Interfaces; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.JsonWebTokens; using Route = FitConnect.Services.Models.v1.Routes.Route; namespace FitConnect; public class Router : IRouter { private readonly IRouteService _routeService; private readonly ISelfServicePortalService _selfServicePortalService; public Router(FitConnectEnvironment environment, ILogger logger = null) { _routeService = new RouteService(environment.RoutingUrl, "v1", logger); _selfServicePortalService = new SelfServicePortalService(environment.SspUrl, "v1", logger); } public async Task<List<Route>> FindDestinationsAsync(string leiaKey, string? ags = null, string? ars = null, string? areaId = null, bool skipValidation = false) { var routes = await _routeService.GetDestinationIdAsync(leiaKey, ags, ars, areaId); if (skipValidation) return routes; var validation = await _selfServicePortalService.GetSelfServiceValidationJwk(); foreach (var route in routes) { var token = new JsonWebToken(route.DestinationSignature); FitEncryption.VerifyJwt(route.DestinationSignature, validation.Keys.First(k => k.Kid == token.Kid)); } return routes; } /// <summary> /// Finding Areas /// </summary> /// <param name="filter"></param> /// <param name="totalCount"></param> /// <param name="offset"></param> /// <param name="limit"></param> /// <returns></returns> public IEnumerable<Area> GetAreas(string filter, out int totalCount, int offset = 0, int limit = 100) { var dto = _routeService.GetAreas(filter, offset, limit).Result; totalCount = dto?.TotalCount ?? 0; return dto?.Areas ?? new List<Area>(); } public async Task<List<Route>> FindDestinationsAsync(string leiaKey, string? ags = null, string? ars = null, string? areaId = null) { throw new NotImplementedException(); } }