Compare commits

...

5 Commits

Author SHA1 Message Date
55562a9f00 feat: add default response type
Some checks failed
Build and Deploy Docker Container / build-and-deploy (push) Failing after 1m30s
.NET Test Pipeline / build-and-test (push) Failing after 1m7s
2024-12-23 06:29:29 +03:00
57b9819d13 feat: add maintenance ignore 2024-12-23 06:29:00 +03:00
78254ed23d fix: change same name 2024-12-23 06:28:28 +03:00
202d20bb25 build: add providers 2024-12-23 06:28:06 +03:00
3e05863aea refactor: clean code 2024-12-22 07:25:41 +03:00
8 changed files with 34 additions and 18 deletions

View File

@ -1,4 +1,4 @@
name: Build and Deploy Docker Container
name: Build and Deploy Docker Container
on:
push:
@ -52,6 +52,12 @@ jobs:
SECURITY_HASH_SIZE: ${{ secrets.SECURITY_HASH_SIZE }}
SECURITY_HASH_TOKEN: ${{ secrets.SECURITY_HASH_TOKEN }}
SECURITY_SALT_SIZE: ${{ secrets.SECURITY_SALT_SIZE }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
YANDEX_CLIENT_ID: ${{ secrets.YANDEX_CLIENT_ID }}
YANDEX_CLIENT_SECRET: ${{ secrets.YANDEX_CLIENT_SECRET }}
MAILRU_CLIENT_ID: ${{ secrets.MAILRU_CLIENT_ID }}
MAILRU_CLIENT_SECRET: ${{ secrets.MAILRU_CLIENT_SECRET }}
run: |
ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
ssh $SSH_USER@$SSH_HOST "
@ -78,6 +84,12 @@ jobs:
-e ACTUAL_SUB_PATH=api \
-e SWAGGER_SUB_PATH=swagger \
-e TZ=Europe/Moscow \
-e GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID \
-e GOOGLE_CLIENT_SECRET=GOOGLE_CLIENT_SECRET \
-e YANDEX_CLIENT_ID=YANDEX_CLIENT_ID \
-e YANDEX_CLIENT_SECRET=YANDEX_CLIENT_SECRET \
-e MAILRU_CLIENT_ID=MAILRU_CLIENT_ID \
-e MAILRU_CLIENT_SECRET=MAILRU_CLIENT_SECRET \
$DOCKER_IMAGE
"

View File

@ -302,19 +302,19 @@ public class SetupController(
[HttpPost("CreateAdmin")]
[TokenAuthentication]
[BadRequestResponse]
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user)
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest userRequest)
{
new PasswordPolicyService(GeneralConfig.PasswordPolicy).ValidatePasswordOrThrow(user.Password);
new PasswordPolicyService(GeneralConfig.PasswordPolicy).ValidatePasswordOrThrow(userRequest.Password);
if (!MailAddress.TryCreate(user.Email, out _))
if (!MailAddress.TryCreate(userRequest.Email, out _))
throw new ControllerArgumentException("The email address is incorrect.");
var (salt, hash) = passwordHashService.HashPassword(user.Password);
var (salt, hash) = passwordHashService.HashPassword(userRequest.Password);
var admin = new Admin
{
Username = user.Username,
Email = user.Email,
Username = userRequest.Username,
Email = userRequest.Email,
PasswordHash = hash,
Salt = salt
};

View File

@ -75,7 +75,7 @@ public class AuthController(IOptionsSnapshot<Admin> user, IOptionsSnapshot<Gener
if (userId != null)
{
userEntity.OAuthProviders ??= new Dictionary<OAuthProvider, OAuthUser>();
userEntity.OAuthProviders ??= [];
if (!userEntity.OAuthProviders.TryAdd(provider, oAuthUser))
{
@ -105,7 +105,7 @@ public class AuthController(IOptionsSnapshot<Admin> user, IOptionsSnapshot<Gener
TwoFactorAuthenticator = userEntity.TwoFactorAuthenticator,
SecondFactorToken = userEntity.Secret,
OAuthProviders = userEntity.OAuthProviders
}, provider);
});
title = "Успешный вход в аккаунт.";
message = "Вы успешно вошли в свою учетную запись. Добро пожаловать!";
@ -152,7 +152,7 @@ public class AuthController(IOptionsSnapshot<Admin> user, IOptionsSnapshot<Gener
[MaintenanceModeIgnore]
public ActionResult<List<AvailableOAuthProvidersResponse>> AvailableProviders() =>
Ok(oAuthService
.GetAvailableProviders(HttpContext, HttpContext.GetApiUrl(Url.Action("AuthorizeOAuth2")!))
.GetAvailableProviders(HttpContext.GetApiUrl(Url.Action("AuthorizeOAuth2")!))
.ConvertToDto());
/// <summary>

View File

@ -80,6 +80,7 @@ public class SecurityController(IOptionsSnapshot<GeneralConfig> generalConfig) :
/// The current password policy
/// </returns>
[HttpGet("PasswordPolicy")]
[MaintenanceModeIgnore]
public ActionResult<PasswordPolicy> PasswordPolicy() =>
Ok(generalConfig.Value.PasswordPolicy.ConvertToDto());
}

View File

@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
@ -58,7 +59,10 @@ public class Program
builder.Host.AddCustomSerilog();
AddDatabase(builder.Services, builder.Configuration, healthCheckBuilder);
builder.Services.AddControllers();
builder.Services.AddControllers(options =>
{
options.Filters.Add(new ProducesResponseTypeAttribute(StatusCodes.Status500InternalServerError));
});
builder.Services.AddSingleton<IMaintenanceModeNotConfigureService, MaintenanceModeNotConfigureService>();
builder.Services.AddSingleton<IMaintenanceModeService, MaintenanceModeService>();

View File

@ -84,7 +84,7 @@ To set up the `redirect URL` when registering and logging in using OAuth 2, use
"{schema}://{domain}{portString}{ACTUAL_SUB_PATH}/api/v1/Auth/OAuth2"
```
** Where:**
**Where:**
- `{schema}` is the protocol you are using (`http` or `https').
- `{domain}` is your domain (for example, `mydomain.com ` or IP address).

View File

@ -107,7 +107,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
authToken.Fingerprint);
}
public async Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptionsParameters cookieOptions, HttpContext context, User user, OAuthProvider provider, CancellationToken cancellation = default)
public async Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptionsParameters cookieOptions, HttpContext context, User user, CancellationToken cancellation = default)
{
var requestContext = new RequestContextInfo(context, cookieOptions);

View File

@ -108,9 +108,9 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
public Uri GetProviderRedirect(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUri, OAuthProvider provider)
{
var providerData = providers[provider];
var (clientId, _) = providers[provider];
var redirectUrl = $"?client_id={providerData.ClientId}" +
var redirectUrl = $"?client_id={clientId}" +
"&response_type=code" +
$"&redirect_uri={redirectUri}" +
$"&scope={ProviderData[provider].Scope}" +
@ -121,10 +121,9 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
return new Uri(ProviderData[provider].RedirectUrl + redirectUrl);
}
public (OAuthProvider Provider, Uri Redirect)[] GetAvailableProviders(HttpContext context, string redirectUri)
public (OAuthProvider Provider, Uri Redirect)[] GetAvailableProviders(string redirectUri)
{
return providers.Select(x => (x.Key, new Uri(redirectUri.TrimEnd('/') + "/?provider=" + (int)x.Key)))
.ToArray();
return [.. providers.Select(x => (x.Key, new Uri(redirectUri.TrimEnd('/') + "/?provider=" + (int)x.Key)))];
}
public async Task<(OAuthProvider provider, OAuthUser User)> LoginOAuth(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUrl, string code, string state, CancellationToken cancellation = default)