Login finished
This commit is contained in:
2
BetterIServ.Backend/.gitignore
vendored
Normal file
2
BetterIServ.Backend/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
bin
|
||||
obj
|
||||
21
BetterIServ.Backend/BetterIServ.Backend.csproj
Normal file
21
BetterIServ.Backend/BetterIServ.Backend.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
42
BetterIServ.Backend/Controllers/HelperController.cs
Normal file
42
BetterIServ.Backend/Controllers/HelperController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BetterIServ.Backend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class HelperController : Controller {
|
||||
|
||||
[HttpPost("/login")]
|
||||
public async Task<ActionResult<string>> Login([FromForm] string email, [FromForm] string password) {
|
||||
try {
|
||||
using var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = false }) { Timeout = TimeSpan.FromSeconds(5) };
|
||||
|
||||
var split = email.Split("@");
|
||||
var username = split[0];
|
||||
var domain = split[1];
|
||||
|
||||
var form = new FormUrlEncodedContent(new[] {
|
||||
new KeyValuePair<string, string>("_username", username),
|
||||
new KeyValuePair<string, string>("_password", password)
|
||||
});
|
||||
|
||||
var request = new HttpRequestMessage {
|
||||
RequestUri = new Uri($"https://{domain}/iserv/auth/login"),
|
||||
Method = HttpMethod.Post,
|
||||
Content = form
|
||||
};
|
||||
|
||||
var response = await client.SendAsync(request);
|
||||
var header = response.Headers.GetValues("Set-Cookie").First();
|
||||
var part = header.Split(";")[0];
|
||||
|
||||
if (!part.Contains("IServAuthSession")) throw new Exception();
|
||||
|
||||
return Ok(part.Replace("IServAuthSession=", ""));
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
20
BetterIServ.Backend/Dockerfile
Normal file
20
BetterIServ.Backend/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["BetterIServ.Backend/BetterIServ.Backend.csproj", "BetterIServ.Backend/"]
|
||||
RUN dotnet restore "BetterIServ.Backend/BetterIServ.Backend.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/BetterIServ.Backend"
|
||||
RUN dotnet build "BetterIServ.Backend.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "BetterIServ.Backend.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "BetterIServ.Backend.dll"]
|
||||
29
BetterIServ.Backend/Program.cs
Normal file
29
BetterIServ.Backend/Program.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseCors(options => {
|
||||
options.WithOrigins("http://localhost:8100");
|
||||
options.AllowCredentials();
|
||||
});
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
41
BetterIServ.Backend/Properties/launchSettings.json
Normal file
41
BetterIServ.Backend/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:49668",
|
||||
"sslPort": 44383
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5273",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7147;http://localhost:5273",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
BetterIServ.Backend/appsettings.Development.json
Normal file
8
BetterIServ.Backend/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
BetterIServ.Backend/appsettings.json
Normal file
9
BetterIServ.Backend/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user