Update Asp.Net Core 2.1 to 3.1

This commit is contained in:
Thomas Fransolet 2020-12-16 21:35:51 +01:00
parent c896f5fbed
commit e0fe54d98f
93 changed files with 807 additions and 311 deletions

View File

@ -0,0 +1,37 @@
using MyCore.Framework.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.Framework.Business
{
public class ProfileLogic
{
private readonly ILogger<ProfileLogic> _logger;
public ProfileLogic(ILogger<ProfileLogic> logger)
: base()
{
_logger = logger;
}
public bool Authenticate(string email, string password)
{
if (string.IsNullOrWhiteSpace(email))
{
_logger.LogError($"Authenticate error: No e-mail provided");
throw new RequestException(StatusCodes.Status401Unauthorized, "Authentication error");
}
if (string.IsNullOrEmpty(password))
{
_logger.LogError($"Authenticate error: No password provided");
throw new RequestException(StatusCodes.Status401Unauthorized, "Authentication error");
}
return true;
}
}
}

View File

@ -0,0 +1,26 @@
using System.Text.Json;
namespace MyCore.Framework.Models
{
[System.Serializable]
public class RequestException : System.Exception
{
public int StatusCode { get; set; }
public object Payload {get;set;}
protected RequestException() { }
public RequestException(int statusCode) : this() { StatusCode = statusCode; }
public RequestException(int statusCode, string message) : base(message) { StatusCode = statusCode; }
public RequestException(int statusCode, string message, System.Exception inner) : base(message, inner) { StatusCode = statusCode; }
protected RequestException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
public string GetJson()
{
return JsonSerializer.Serialize(new { StatusCode, Message, Payload });
}
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="1.1.21" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
</Project>

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.Common namespace MyCore.Interfaces.DTO
{ {
public enum ConnectionStatus public enum ConnectionStatus
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.Common namespace MyCore.Interfaces.DTO
{ {
public enum DeviceType // TO BE Continued public enum DeviceType // TO BE Continued
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.Common namespace MyCore.Interfaces.DTO
{ {
public enum MeansOfCommunication public enum MeansOfCommunication
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO namespace MyCore.Interfaces.DTO
{ {
public class RequestParam public class RequestParam
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.Energy namespace MyCore.Interfaces.DTO
{ {
public enum ViewBy public enum ViewBy
{ {

View File

@ -0,0 +1,8 @@
namespace MyCore.Interfaces.DTO
{
public class LoginDTO
{
public string Email { get; set; }
public string Password { get; set; }
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.MyControlPanel namespace MyCore.Interfaces.DTO
{ {
public class AutomationDTO public class AutomationDTO
{ {

View File

@ -1,11 +1,9 @@
using MyCore.DTO.Common; using System;
using MyCore.Models.MyControlPanel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.MyControlPanel namespace MyCore.Interfaces.DTO
{ {
public class DeviceSummaryDTO public class DeviceSummaryDTO
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.MyControlPanel namespace MyCore.Interfaces.DTO
{ {
public class GroupDTO public class GroupDTO
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.MyControlPanel namespace MyCore.Interfaces.DTO
{ {
public class LocationDTO public class LocationDTO
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.DTO.MyControlPanel namespace MyCore.Interfaces.DTO
{ {
public class ProviderDTO public class ProviderDTO
{ {

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.Interfaces
{
public class Odd
{
public string Sport_nice { get; set; }
public List<string> Teams { get; set; }
public int Commence_time { get; set; }
public string Home_team { get; set; }
public List<OddSite> Sites { get; set; }
}
public class OddSite
{
public string Site_key { get; set; }
public string Site_nice { get; set; }
public int Last_update { get; set; }
public OddMatch Odds { get; set; }
}
public class OddMatch
{
public IEnumerable<double> H2h { get; set; }
}
public class OddH2H
{
public double HomeOdd { get; set; }
public double DrawOdd { get; set; }
public double VisitOdd { get; set; }
}
public class OddNice
{
public List<string> Teams { get; set; }
public int Commence_time { get; set; }
public string Home_team { get; set; }
public OddH2H Odds { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace MyCore.Interfaces.DTO
{
/// <summary>
/// Swagger test client authentication data
/// </summary>
public class SwaggerTokenRequest
{
public string grant_type { get; set; }
public string username { get; set; }
public string password { get; set; }
public string client_id { get; set; }
public string client_secret { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
namespace MyCore.Interfaces.DTO
{
public class TokenDTO
{
public string access_token { get; set; }
public string refresh_token { get; set; }
public string scope { get; set; }
public string token_type { get; set; }
public int expires_in { get; set; }
public DateTimeOffset expiration { get; set; }
}
}

View File

@ -5,7 +5,7 @@ using System.Threading.Tasks;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class Book public class Book
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public enum LightState public enum LightState
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Common namespace MyCore.Interfaces.Models
{ {
public class LogDatabase // TODO public class LogDatabase // TODO
{ {

View File

@ -1,11 +1,10 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Automation /// Automation

View File

@ -1,14 +1,12 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.Models;
using MyCore.Models.MyControlPanel.Database;
using MyCore.Services.MyControlPanel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Group of devices /// Group of devices

View File

@ -1,10 +1,9 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Group of devices /// Group of devices

View File

@ -1,8 +1,8 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.DTO;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Location of a device (Room name, garden, ..) /// Location of a device (Room name, garden, ..)

View File

@ -1,11 +1,10 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Provider of a device (provider of informations) - e.g. : Meross, Arlo, IoThomas, ... /// Provider of a device (provider of informations) - e.g. : Meross, Arlo, IoThomas, ...

View File

@ -2,17 +2,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AspNetCore.Security.Jwt; //using AspNetCore.Security.Jwt;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.Models.MyControlPanel; using MyCore.Interfaces.Models;
namespace MyCore.Models.MyControlPanel.Database namespace MyCore.Interfaces.Models
{ {
/// <summary> /// <summary>
/// User Information /// User Information
/// </summary> /// </summary>
public class UserInfo : IAuthenticationUser public class UserInfo //: IAuthenticationUser // TODO !
{ {
[BsonId] [BsonId]
[BsonRepresentation(BsonType.ObjectId)] [BsonRepresentation(BsonType.ObjectId)]

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Layout namespace MyCore.Interfaces.Models
{ {
public class PanelSection public class PanelSection
{ {

View File

@ -0,0 +1,8 @@
namespace MyCore.Interfaces.Models
{
public class Policy
{
public string Name { get; set; }
public string[] Claims { get; set; }
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Arlo namespace MyCore.Interfaces.Models
{ {
public class ArloDevice public class ArloDevice
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Arlo namespace MyCore.Interfaces.Models
{ {
public class UserLocation public class UserLocation
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Arlo namespace MyCore.Interfaces.Models
{ {
public class UserMedia public class UserMedia
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Energy namespace MyCore.Interfaces.Models
{ {
public class ElectricityProduction public class ElectricityProduction
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class SmartGardenMessage public class SmartGardenMessage
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class SmartPrinterMessage public class SmartPrinterMessage
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Meross namespace MyCore.Interfaces.Models
{ {
public class DeviceAbilities public class DeviceAbilities
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Meross namespace MyCore.Interfaces.Models
{ {
public class MerossDevice public class MerossDevice
{ {

View File

@ -1,12 +1,12 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using MyCore.Models.Providers.Zigbee.Aqara; using MyCore.Interfaces.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Aqara namespace MyCore.Interfaces.Models
{ {
public class AqaraCube : AqaraDevice public class AqaraCube : AqaraDevice
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Providers.Zigbee.Aqara namespace MyCore.Interfaces.Models
{ {
public class AqaraDevice public class AqaraDevice
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Providers.Zigbee.Aqara namespace MyCore.Interfaces.Models
{ {
public class AqaraSwitch : AqaraDevice public class AqaraSwitch : AqaraDevice
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Ikea namespace MyCore.Interfaces.Models
{ {
public class LightBulb public class LightBulb
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models.Providers.Zigbee.Zigbee2Mqtt namespace MyCore.Interfaces.Models
{ {
public class Zigbee2MqttDevice public class Zigbee2MqttDevice
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class ScreenConfiguration public class ScreenConfiguration
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class ScreenDevice public class ScreenDevice
{ {

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class Widget public class Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetAgenda : Widget public class WidgetAgenda : Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetHourAndDate : Widget public class WidgetHourAndDate : Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetMessage : Widget public class WidgetMessage : Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetNews : Widget public class WidgetNews : Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetRadio : Widget public class WidgetRadio : Widget
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetTraffic : Widget public class WidgetTraffic : Widget
{ {

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MyCore.Models namespace MyCore.Interfaces.Models
{ {
public class WidgetWeather : Widget public class WidgetWeather : Widget
{ {

View File

@ -0,0 +1,18 @@
namespace MyCore.Interfaces.Models
{
public class TokensSettings
{
/// <summary>
/// Application secret for tokens generation
/// </summary>
public string Secret { get; set; }
/// <summary>
/// Access token expiration in minutes
/// </summary>
public int AccessTokenExpiration { get; set; } = 30;
/// <summary>
/// Refresh token expiration in minutes
/// </summary>
public int RefreshTokenExpiration { get; set; } = 4 * 60;
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.8.0" />
</ItemGroup>
</Project>

View File

@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCore", "MyCore\MyCore.csproj", "{017065F0-FC61-4566-A432-F414FC217AAA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCore", "MyCore\MyCore.csproj", "{017065F0-FC61-4566-A432-F414FC217AAA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCore.Devices", "MyCore.Devices\MyCore.Devices.csproj", "{7B9FE719-FBF7-42D5-BCF5-BDA31B05D66D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCore.Interfaces", "MyCore.Interfaces\MyCore.Interfaces.csproj", "{6FD8EE93-D8BD-43AD-A126-A8ECBF4451E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCore.Framework", "MyCore.Framework\MyCore.Framework.csproj", "{AA56B2F3-A871-4C99-89FB-038F957399F2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,10 +19,14 @@ Global
{017065F0-FC61-4566-A432-F414FC217AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {017065F0-FC61-4566-A432-F414FC217AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{017065F0-FC61-4566-A432-F414FC217AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU {017065F0-FC61-4566-A432-F414FC217AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{017065F0-FC61-4566-A432-F414FC217AAA}.Release|Any CPU.Build.0 = Release|Any CPU {017065F0-FC61-4566-A432-F414FC217AAA}.Release|Any CPU.Build.0 = Release|Any CPU
{7B9FE719-FBF7-42D5-BCF5-BDA31B05D66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6FD8EE93-D8BD-43AD-A126-A8ECBF4451E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B9FE719-FBF7-42D5-BCF5-BDA31B05D66D}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FD8EE93-D8BD-43AD-A126-A8ECBF4451E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B9FE719-FBF7-42D5-BCF5-BDA31B05D66D}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FD8EE93-D8BD-43AD-A126-A8ECBF4451E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B9FE719-FBF7-42D5-BCF5-BDA31B05D66D}.Release|Any CPU.Build.0 = Release|Any CPU {6FD8EE93-D8BD-43AD-A126-A8ECBF4451E4}.Release|Any CPU.Build.0 = Release|Any CPU
{AA56B2F3-A871-4C99-89FB-038F957399F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA56B2F3-A871-4C99-89FB-038F957399F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA56B2F3-A871-4C99-89FB-038F957399F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA56B2F3-A871-4C99-89FB-038F957399F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,91 @@
using MyCore.Interfaces.DTO;
using MyCore.Service.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using NSwag.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace MyCore.Service.Controllers
{
/// <summary>
/// Authentication controller
/// </summary>
[ApiController, Route("api/[controller]")]
[Authorize]
[OpenApiTag("Authentication", Description = "Authentication management")]
public class AuthenticationController : ControllerBase
{
private readonly ILogger<AuthenticationController> _logger;
private readonly TokensService _tokensService;
/// <summary>
/// Constructor
/// </summary>
/// <param name="logger">Logger</param>
/// <param name="tokensService">Tokens service</param>
public AuthenticationController(ILogger<AuthenticationController> logger, TokensService tokensService)
{
_logger = logger;
_tokensService = tokensService;
}
private ActionResult<LoginDTO> Authenticate(string email, string password)
{
try
{
var token = _tokensService.Authenticate(email.ToLower(), password);
return Ok(token);
}
/*catch (UnauthorizedAccessException ex)
{
_logger?.LogError(ex, $"Authentication error for user '{email}': unauthorized access");
return Unauthorized(ex);
}*/
catch (Exception ex)
{
_logger?.LogError(ex, $"Authenticate error for user '{email}'");
return Problem($"Authenticate error for user '{email}': {ex.Message}");
}
}
/// <summary>
/// Authenticate with form parameters (used by Swagger test client)
/// </summary>
/// <param name="tokenRequest">Swagger token request</param>
/// <returns>Token descriptor</returns>
[AllowAnonymous]
[HttpPost("Token")]
[Consumes("application/x-www-form-urlencoded")]
[SwaggerResponse(HttpStatusCode.OK, typeof(LoginDTO), Description = "Success")]
[SwaggerResponse(HttpStatusCode.Unauthorized, typeof(string), Description = "Invalid credentials")]
[SwaggerResponse(HttpStatusCode.InternalServerError, typeof(string), Description = "Error")]
public ActionResult<LoginDTO> AuthenticateWithForm([FromForm] SwaggerTokenRequest tokenRequest)
{
return Authenticate(tokenRequest.username, tokenRequest.password);
}
/// <summary>
/// Authenticate with Json parameters (used by most clients)
/// </summary>
/// <param name="login">Login DTO</param>
/// <returns>Token descriptor</returns>
[AllowAnonymous]
[HttpPost("Authenticate")]
[Consumes("application/json")]
[SwaggerResponse(HttpStatusCode.OK, typeof(LoginDTO), Description = "Success")]
[SwaggerResponse(HttpStatusCode.Unauthorized, typeof(string), Description = "Invalid credentials")]
[SwaggerResponse(HttpStatusCode.InternalServerError, typeof(string), Description = "Error")]
public ActionResult<LoginDTO> AuthenticateWithJson([FromBody] LoginDTO login)
{
return Authenticate(login.Email.ToLower(), login.Password);
}
}
}

View File

@ -1,12 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using MyCore.Models;
using MyCore.Services; using MyCore.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using MyCore.Interfaces.Models;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize]
[Route("api/books")] [Route("api/books")]
[ApiController] [ApiController]
public class BooksController : ControllerBase public class BooksController : ControllerBase

View File

@ -8,18 +8,15 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson; using MongoDB.Bson;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.Models;
using MyCore.Models;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
using MyCore.Services; using MyCore.Services;
using MyCore.Services.Devices; using MyCore.Services.Devices;
using MyCore.Services.MyControlPanel; using MyCore.Services.MyControlPanel;
namespace MyCore.Controllers.Devices namespace MyCore.Controllers.Devices
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/device")] [Route("api/device")]
[ApiController] [ApiController]
public class DeviceController : ControllerBase public class DeviceController : ControllerBase

View File

@ -7,15 +7,14 @@ using Microsoft.AspNetCore.Mvc;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Server; using MQTTnet.Server;
using MyCore.DTO.Energy; using MyCore.Interfaces.DTO;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Models.Energy;
using MyCore.Services; using MyCore.Services;
using static MyCore.Services.OddService; using static MyCore.Services.OddService;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/energy")] [Route("api/energy")]
[ApiController] [ApiController]
public class EnergyController : ControllerBase public class EnergyController : ControllerBase

View File

@ -6,12 +6,12 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson; using MongoDB.Bson;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Services; using MyCore.Services;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/iot")] [Route("api/iot")]
[ApiController] [ApiController]
public class IOTController : ControllerBase public class IOTController : ControllerBase

View File

@ -4,23 +4,33 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Server; using MQTTnet.Server;
using MyCore.DTO; using MyCore.Interfaces;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Services; using MyCore.Services;
using static MyCore.Services.OddService; using static MyCore.Services.OddService;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES Authorize(Roles = "Admin")
[Route("api/odd")] [Route("api/odd")]
[ApiController] [ApiController]
public class OddController : ControllerBase public class OddController : ControllerBase
{ {
private OddService oddService = new OddService(OddService.RegionOdd.UK); private OddService oddService = new OddService(OddService.RegionOdd.UK);
private readonly ILogger<OddController> _logger;
public OddController(ILogger<OddController> logger) : base()
{
_logger = logger;
}
/// <summary> /// <summary>
/// Get odds for one country and one odd value maximum /// Get odds for one country and one odd value maximum
/// </summary> /// </summary>
@ -46,7 +56,7 @@ namespace MyCore.Controllers
var result = await GetOddsForCountry(id, oddRequest); var result = await GetOddsForCountry(id, oddRequest);
return new OkObjectResult(result); return Ok(result);
} }
catch (Exception e) catch (Exception e)
{ {
@ -60,7 +70,6 @@ namespace MyCore.Controllers
/// Get odds for one country and one odd value maximum /// Get odds for one country and one odd value maximum
/// </summary> /// </summary>
/// <param name="oddRequest">Odd Maximum value</param> /// <param name="oddRequest">Odd Maximum value</param>
[AllowAnonymous]
[ProducesResponseType(typeof(List<OddNice>), 200)] [ProducesResponseType(typeof(List<OddNice>), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
@ -80,7 +89,7 @@ namespace MyCore.Controllers
} }
} }
return new OkObjectResult(oddToSend); return Ok(oddToSend);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -6,11 +6,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson; using MongoDB.Bson;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.Models;
using MyCore.Models;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
using MyCore.Services; using MyCore.Services;
using MyCore.Services.Devices; using MyCore.Services.Devices;
using MyCore.Services.MyControlPanel; using MyCore.Services.MyControlPanel;

View File

@ -6,12 +6,12 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson; using MongoDB.Bson;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Services; using MyCore.Services;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/device/screen")] [Route("api/device/screen")]
[ApiController] [ApiController]
public class ScreenDeviceController : ControllerBase public class ScreenDeviceController : ControllerBase

View File

@ -16,7 +16,7 @@ namespace MyCore.Controllers
[ApiController] [ApiController]
public class MQTTController : ControllerBase public class MQTTController : ControllerBase
{ {
private string _mqttServer = "192.168.0.8"; private string _mqttServer = "192.168.31.140";
/// <summary> /// <summary>
/// It's a mqtt publish test ! :) /// It's a mqtt publish test ! :)
/// </summary> /// </summary>

View File

@ -7,14 +7,13 @@ using Microsoft.AspNetCore.Mvc;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Server; using MQTTnet.Server;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Models.Layout;
using MyCore.Services; using MyCore.Services;
using static MyCore.Services.OddService; using static MyCore.Services.OddService;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "User")] [Authorize] // TODO Add ROLES (Roles = "User")
[Route("api/layout")] [Route("api/layout")]
[ApiController] [ApiController]
public class LayoutController : ControllerBase public class LayoutController : ControllerBase

View File

@ -10,9 +10,9 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using MyCore.DTO; using MyCore.Interfaces.DTO;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Models.MyControlPanel.Database; using MyCore.Service.Services;
using MyCore.Services; using MyCore.Services;
namespace MyCore.Controllers namespace MyCore.Controllers
@ -22,10 +22,10 @@ namespace MyCore.Controllers
[ApiController] [ApiController]
public class TokenController : ControllerBase public class TokenController : ControllerBase
{ {
private TokenService _tokenService; private TokensService _tokenService;
private UserDatabaseService _userService; private UserDatabaseService _userService;
public TokenController(TokenService tokenService, UserDatabaseService userService) public TokenController(TokensService tokenService, UserDatabaseService userService)
{ {
_tokenService = tokenService; _tokenService = tokenService;
_userService = userService; _userService = userService;
@ -33,14 +33,14 @@ namespace MyCore.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
public ActionResult<UserInfo> ConnectUser([FromBody] TokenDTO tokenDTO) public ActionResult<UserInfo> ConnectUser([FromBody] LoginDTO loginDTO)
{ {
//string test = _TokenService.GenerateSHA256String(password); //string test = _TokenService.GenerateSHA256String(password);
if (IsValidUserAndPasswordCombination(tokenDTO.Email, tokenDTO.Password)) if (IsValidUserAndPasswordCombination(loginDTO.Email, loginDTO.Password))
{ {
UserInfo user = _userService.GetByEmail(tokenDTO.Email); UserInfo user = _userService.GetByEmail(loginDTO.Email);
user.Token = _tokenService.GenerateToken(tokenDTO.Email).ToString(); user.Token = _tokenService.GenerateToken(loginDTO.Email).ToString();
return user; return user;
} }

View File

@ -7,21 +7,21 @@ using Microsoft.AspNetCore.Mvc;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Server; using MQTTnet.Server;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Models.MyControlPanel.Database; using MyCore.Service.Services;
using MyCore.Services; using MyCore.Services;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/user")] [Route("api/user")]
[ApiController] [ApiController]
public class UserController : ControllerBase public class UserController : ControllerBase
{ {
private UserDatabaseService _userService; private UserDatabaseService _userService;
private TokenService _tokenService; private TokensService _tokenService;
public UserController(UserDatabaseService userService, TokenService tokenService) public UserController(UserDatabaseService userService, TokensService tokenService)
{ {
_userService = userService; _userService = userService;
_tokenService = tokenService; _tokenService = tokenService;

View File

@ -7,13 +7,13 @@ using Microsoft.AspNetCore.Mvc;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Server; using MQTTnet.Server;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Services; using MyCore.Services;
using static MyCore.Services.OddService; using static MyCore.Services.OddService;
namespace MyCore.Controllers namespace MyCore.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize] // TODO Add ROLES (Roles = "Admin")
[Route("api/test")] [Route("api/test")]
[ApiController] [ApiController]
public class ValuesController : ControllerBase public class ValuesController : ControllerBase

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.DTO
{
public class TokenDTO
{
public string Email { get; set; }
public string Password { get; set; }
}
}

View File

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.DTO
{
public class Odd
{
public string Sport_nice;
public List<string> Teams;
public int Commence_time;
public string Home_team;
public List<OddSite> Sites;
}
public class OddSite
{
public string Site_key;
public string Site_nice;
public int Last_update;
public OddMatch Odds;
}
public class OddMatch
{
public IEnumerable<double> H2h;
}
public class OddH2H
{
public double HomeOdd;
public double DrawOdd;
public double VisitOdd;
}
public class OddNice
{
public List<string> Teams;
public int Commence_time;
public string Home_team;
public OddH2H Odds;
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>6d53b0c4-74d6-41aa-8816-2ec3cf42767a</UserSecretsId> <UserSecretsId>6d53b0c4-74d6-41aa-8816-2ec3cf42767a</UserSecretsId>
</PropertyGroup> </PropertyGroup>
@ -9,6 +9,8 @@
<PropertyGroup> <PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn> <NoWarn>$(NoWarn);1591</NoWarn>
<AssemblyName>MyCore.Service</AssemblyName>
<RootNamespace>MyCore.Service</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -25,9 +27,15 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.8.0" /> <PackageReference Include="MongoDB.Driver" Version="2.8.0" />
<PackageReference Include="MQTTnet" Version="3.0.8" /> <PackageReference Include="MQTTnet" Version="3.0.8" />
<PackageReference Include="NSwag.AspNetCore" Version="13.9.2" />
<PackageReference Include="ServiceStack.Client" Version="5.8.0" /> <PackageReference Include="ServiceStack.Client" Version="5.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="YeelightAPI" Version="1.7.0" /> <PackageReference Include="YeelightAPI" Version="1.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyCore.Framework\MyCore.Framework.csproj" />
<ProjectReference Include="..\MyCore.Interfaces\MyCore.Interfaces.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace MyCore namespace MyCore
@ -14,11 +15,14 @@ namespace MyCore
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
CreateWebHostBuilder(args).Build().Run(); CreateHostBuilder(args).Build().Run();
} }
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.UseStartup<Startup>(); .ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
} }
} }

View File

@ -4,7 +4,7 @@
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:25049", "applicationUrl": "http://localhost:25049",
"sslPort": 0 "sslPort": 44341
} }
}, },
"$schema": "http://json.schemastore.org/launchsettings.json", "$schema": "http://json.schemastore.org/launchsettings.json",

60
MyCore/Security.cs Normal file
View File

@ -0,0 +1,60 @@
using MyCore.Interfaces.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.Service
{
internal static class Security
{
public const string Scope = "MyCore-api";
/// <summary>
/// Permissions
/// </summary>
private class Permissions
{
/// <summary>
/// Dpos admin access
/// </summary>
public const string Admin = "MyCore.admin";
}
/// <summary>
/// Custom claims types
/// </summary>
public class ClaimTypes
{
public const string Permission = "Permission";
}
/// <summary>
/// Permissions for each type of profile
/// </summary>
public static readonly Dictionary<Type, string[]> ProfilesConfiguration = new Dictionary<Type, string[]>()
{
// An admin has access to everything
//{ typeof(AdminProfile), new[] { Permissions.Admin} },
};
/// <summary>
/// Policies names
/// </summary>
public class Policies
{
/// <summary>
/// Administration
/// </summary>
public const string Admin = "MyCore.Administration";
}
/// <summary>
/// Policies
/// </summary>
public static readonly Policy[] PoliciesConfiguration = new[]
{
new Policy() { Name = Policies.Admin, Claims = new[] { Permissions.Admin} }
};
}
}

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MyCore.DTO.Common; using MyCore.Interfaces.DTO;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.Models;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
using MyCore.Services.MyControlPanel; using MyCore.Services.MyControlPanel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -86,11 +84,11 @@ namespace MyCore.Services.Devices
switch (provider.Name) switch (provider.Name)
{ {
case "Arlo": case "Arlo":
List<Models.Arlo.ArloDevice> arloDevices = new ArloService(provider.Username, provider.Password).GetAllDevices(); List<ArloDevice> arloDevices = new ArloService(provider.Username, provider.Password).GetAllDevices();
createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, arloDevices, provider); createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, arloDevices, provider);
break; break;
case "Meross": case "Meross":
List<Models.Meross.MerossDevice> merossDevices = new MerossService(provider.Username, provider.Password).GetMerossDevices(); List<MerossDevice> merossDevices = new MerossService(provider.Username, provider.Password).GetMerossDevices();
createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, merossDevices, provider); createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, merossDevices, provider);
break; break;
case "Yeelight": case "Yeelight":
@ -131,7 +129,7 @@ namespace MyCore.Services.Devices
return createdDevice; return createdDevice;
} }
public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Arlo.ArloDevice> arloDevices, Provider provider) public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<ArloDevice> arloDevices, Provider provider)
{ {
List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>(); List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>();
@ -181,7 +179,7 @@ namespace MyCore.Services.Devices
return createdArloDevices; return createdArloDevices;
} }
public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Meross.MerossDevice> merossDevices, Provider provider) public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<MerossDevice> merossDevices, Provider provider)
{ {
List<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>(); List<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>();

View File

@ -2,10 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.Energy;
namespace MyCore.Services namespace MyCore.Services
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -1,4 +1,4 @@
using MyCore.DTO; using MyCore.Interfaces;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;

View File

@ -1,11 +1,7 @@
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Client.Options; using MQTTnet.Client.Options;
using MyCore.Models; using MyCore.Interfaces.Models;
using MyCore.Models.Aqara;
using MyCore.Models.Ikea;
using MyCore.Models.Providers.Zigbee.Aqara;
using MyCore.Models.Providers.Zigbee.Zigbee2Mqtt;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -1,5 +1,5 @@
using EvtSource; using EvtSource;
using MyCore.Models.Arlo; using MyCore.Interfaces.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using ServiceStack; using ServiceStack;

View File

@ -3,7 +3,7 @@ using MQTTnet.Client;
using MQTTnet.Client.Options; using MQTTnet.Client.Options;
using MQTTnet.Formatter; using MQTTnet.Formatter;
using MQTTnet.Implementations; using MQTTnet.Implementations;
using MyCore.Models.Meross; using MyCore.Interfaces.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
@ -15,7 +15,7 @@ using System.Security.Authentication;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using static MyCore.Models.Meross.DeviceAbilities; using static MyCore.Interfaces.Models.DeviceAbilities;
namespace MyCore.Services namespace MyCore.Services
{ {

View File

@ -2,11 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services.MyControlPanel namespace MyCore.Services.MyControlPanel
{ {

View File

@ -2,11 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services.MyControlPanel namespace MyCore.Services.MyControlPanel
{ {

View File

@ -2,11 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services.MyControlPanel namespace MyCore.Services.MyControlPanel
{ {

View File

@ -2,11 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services.MyControlPanel namespace MyCore.Services.MyControlPanel
{ {

View File

@ -2,10 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services.MyControlPanel namespace MyCore.Services.MyControlPanel
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -2,10 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyCore.Models; using MyCore.Interfaces.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
using MyCore.Models.MyControlPanel.Database;
namespace MyCore.Services namespace MyCore.Services
{ {

View File

@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MyCore.DTO.MyControlPanel; using MyCore.Interfaces.DTO;
using MyCore.Models.MyControlPanel.Database; using MyCore.Interfaces.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,57 +0,0 @@
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace MyCore.Services
{
public class TokenService
{
public object GenerateToken(string username)
{
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("%G2YZ=\tgN7fC9M$FXDt#q*a&]Z")); // Put the secret in a file or something
var claims = new Claim[] {
new Claim(ClaimTypes.Name, username),
new Claim(JwtRegisteredClaimNames.Email, "john.doe@blinkingcaret.com"),
new Claim(ClaimTypes.Role, "Admin")
};
var token = new JwtSecurityToken(
issuer: "MyCore App",
audience: "Miotecher",
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(28),
signingCredentials: new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256)
);
string jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
return jwtToken;
}
public static string GenerateSHA256String(string inputString)
{
SHA256 sha256 = SHA256Managed.Create();
byte[] bytes = Encoding.UTF8.GetBytes(inputString);
byte[] hash = sha256.ComputeHash(bytes);
return GetStringFromHash(hash);
}
public static string GetStringFromHash(byte[] hash)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
result.Append(hash[i].ToString("X2"));
}
return result.ToString();
}
}
}

View File

@ -0,0 +1,141 @@
using MyCore.Framework.Business;
using MyCore.Interfaces.DTO;
using MyCore.Interfaces.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace MyCore.Service.Services
{
/// <summary>
/// Tokens service
/// </summary>
public class TokensService
{
private readonly ILogger<TokensService> _logger;
private readonly TokensSettings _tokenSettings;
private readonly ProfileLogic _profileLogic;
private readonly SigningCredentials _signingCredentials;
/// <summary>
/// Constructor
/// </summary>
/// <param name="logger">Logger</param>
/// <param name="tokenSettings">Tokens settings</param>
/// <param name="context">Database context</param>
/// <param name="profileLogic">Profile logic</param>
/// <param name="emailClient">Email client</param>
public TokensService(ILogger<TokensService> logger, IOptions<TokensSettings> tokenSettings, ProfileLogic profileLogic)
{
_logger = logger;
_tokenSettings = tokenSettings.Value;
_profileLogic = profileLogic;
var key = Encoding.UTF8.GetBytes(_tokenSettings.Secret);
_signingCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature);
}
/// <summary>
/// Authenticate
/// </summary>
/// <param name="email">Email</param>
/// <param name="password">Password</param>
/// <returns>Token DTO in case of success</returns>
public TokenDTO Authenticate(string email, string password)
{
try
{
var claims = new List<System.Security.Claims.Claim>();
var expiration = DateTime.UtcNow.AddMinutes(_tokenSettings.AccessTokenExpiration);
// Todo nothing good here..
var profile = _profileLogic.Authenticate(email, password);
claims.Add(new Claim(ClaimTypes.Email, email));
// TODO: add refresh token support
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor()
{
Subject = new ClaimsIdentity(claims),
Expires = expiration,
SigningCredentials = _signingCredentials
};
var token = tokenHandler.CreateToken(tokenDescriptor);
return new TokenDTO()
{
access_token = tokenHandler.WriteToken(token),
expires_in = _tokenSettings.AccessTokenExpiration * 60,
expiration = new DateTimeOffset(token.ValidTo),
token_type = "Bearer",
scope = Security.Scope
};
}
/*catch (UnauthorizedAccessException ex)
{
_logger?.LogError(ex, $"Authenticate error for user '{email}': unauthorized access");
throw;
}*/
catch (Exception ex)
{
_logger?.LogError(ex, $"Authenticate error for user '{email}': {ex.Message}");
throw;
}
}
public object GenerateToken(string username)
{
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("%G2YZ=\tgN7fC9M$FXDt#q*a&]Z")); // Put the secret in a file or something
var claims = new Claim[] {
new Claim(ClaimTypes.Name, username),
new Claim(JwtRegisteredClaimNames.Email, "john.doe@blinkingcaret.com"),
new Claim(ClaimTypes.Role, "Admin")
};
var token = new JwtSecurityToken(
issuer: "MyCore App",
audience: "Miotecher",
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(28),
signingCredentials: new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256)
);
string jwtToken = new JwtSecurityTokenHandler().WriteToken(token);
return jwtToken;
}
public static string GenerateSHA256String(string inputString)
{
SHA256 sha256 = SHA256Managed.Create();
byte[] bytes = Encoding.UTF8.GetBytes(inputString);
byte[] hash = sha256.ComputeHash(bytes);
return GetStringFromHash(hash);
}
public static string GetStringFromHash(byte[] hash)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
result.Append(hash[i].ToString("X2"));
}
return result.ToString();
}
}
}

View File

@ -4,21 +4,32 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using AspNetCore.Security.Jwt; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using MyCore.Models; using MyCore.Framework.Models;
using MyCore.Interfaces.Models;
using MyCore.Service;
using MyCore.Services; using MyCore.Services;
using MyCore.Services.MyControlPanel; using MyCore.Services.MyControlPanel;
using Swashbuckle.AspNetCore.Swagger; using NSwag;
using NSwag.Generation.AspNetCore;
using NSwag.Generation.Processors.Security;
using MyCore.Framework.Business;
using MyCore.Service.Services;
namespace MyCore namespace MyCore
{ {
public class Startup public class Startup
@ -36,10 +47,6 @@ namespace MyCore
/*YeelightService yeelighService = new YeelightService(); /*YeelightService yeelighService = new YeelightService();
yeelighService.GetDevices();*/ yeelighService.GetDevices();*/
MQTTService mQTTService = new MQTTService("192.168.31.140", "mqtt", "mqtt");
mQTTService.GetDevices();
} }
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
@ -47,20 +54,10 @@ namespace MyCore
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add the service (test purpose) //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddScoped<BookService>();
services.AddScoped<IoTDeviceService>();
services.AddScoped<UserDatabaseService>();
services.AddScoped<ProviderDatabaseService>();
services.AddScoped<DeviceDatabaseService>();
services.AddScoped<LocationDatabaseService>();
services.AddScoped<TokenService>();
services.AddScoped<ScreenDeviceDatabaseService>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Register the Swagger generator, defining 1 or more Swagger documents // Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c => /*services.AddSwaggerGen(c =>
{ {
c.SwaggerDoc("v1", new Info { Title = "MyCoreApi", Version = "v1" }); c.SwaggerDoc("v1", new Info { Title = "MyCoreApi", Version = "v1" });
@ -98,40 +95,167 @@ namespace MyCore
ClockSkew = TimeSpan.FromMinutes(5) //5 minute tolerance for the expiration date ClockSkew = TimeSpan.FromMinutes(5) //5 minute tolerance for the expiration date
}; };
});*/
// Swagger
services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
services.AddOpenApiDocument(config =>
{
ConfigureSwagger(config);
});
services.AddCors(o => o.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
// Authentication
var tokensConfiguration = Configuration.GetSection("Tokens");
var tokenSettings = tokensConfiguration.Get<TokensSettings>();
services.Configure<TokensSettings>(tokensConfiguration);
foreach (var policy in Security.PoliciesConfiguration)
services.AddAuthorization(options =>
{
options.AddPolicy(policy.Name, policyAdmin =>
{
foreach (var claim in policy.Claims)
policyAdmin.RequireClaim(Security.ClaimTypes.Permission, claim);
});
});
services
.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenSettings.Secret)),
ValidateIssuer = false,
ValidateAudience = false,
RequireExpirationTime = false,
ValidateLifetime = true
};
});
services.AddScoped<TokensService>();
services.AddScoped(typeof(ProfileLogic));
// Add the service (test purpose)
services.AddScoped<BookService>();
services.AddScoped<IoTDeviceService>();
services.AddScoped<UserDatabaseService>();
services.AddScoped<ProviderDatabaseService>();
services.AddScoped<DeviceDatabaseService>();
services.AddScoped<LocationDatabaseService>();
services.AddScoped<ScreenDeviceDatabaseService>();
services.AddScoped<MQTTService>(c => {
MQTTService mQTTService = new MQTTService("192.168.31.140", "mqtt", "mqtt");
mQTTService.GetDevices();
return mQTTService;
}); });
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
app.UseCors( /*app.UseCors(
options => options.WithOrigins("http://localhost:4200").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials() options => options.WithOrigins("http://localhost:4200").AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()
); );*/
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); //app.UseDeveloperExceptionPage();
} app.UseExceptionHandler(HandleError);
else
{
app.UseHsts();
} }
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), app.UseEndpoints(endpoints =>
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{ {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyCoreApi V1"); endpoints.MapControllers();
}); });
//app.UseHttpsRedirection(); app.UseOpenApi();
app.UseMvc(); app.UseSwaggerUi3();
}
private void ConfigureSwagger(AspNetCoreOpenApiDocumentGeneratorSettings config)
{
config.AddSecurity("bearer", Enumerable.Empty<string>(), new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.OAuth2,
Description = "MyCore Authentication",
Flow = OpenApiOAuth2Flow.Password,
Flows = new OpenApiOAuthFlows()
{
Password = new OpenApiOAuthFlow()
{
Scopes = new Dictionary<string, string>
{
{Security.Scope, "MyCore WebAPI"}
},
TokenUrl = "/api/authentication/Token",
AuthorizationUrl = "/authentication/Token",
}
}
});
config.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("bearer"));
config.PostProcess = document =>
{
document.Info.Title = "MyCore Service";
document.Info.Description = "API description";
document.Info.Version = "Version Pre-Alpha";
};
config.GenerateEnumMappingDescription = true;
}
private void HandleError(IApplicationBuilder error)
{
error.Run(async context =>
{
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
var exception = exceptionHandlerPathFeature?.Error as RequestException;
if (exception != null)
{
var json = exception.GetJson();
context.Response.ContentType = "application/json";
context.Response.StatusCode = exception.StatusCode;
await context.Response.WriteAsync(json);
}
});
} }
} }
} }

View File

@ -5,10 +5,17 @@
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Tokens": {
"Secret": "%G2YZ=\tgN7fC9M$FXDt#q*a&]Z",
"AccessTokenExpiration": 86400,
"RefreshTokenExpiration": 518400
},
"SecuritySettings": { "SecuritySettings": {
"Secret": "azertyuiopqsdfgh", "Secret": "azertyuiopqsdfgh",
"Issuer": "MyCore", "Issuer": "MyCore",