Release v1.0.0 #16
.envnuget.config
.gitea/workflows
.gitignoreApiDto
ApiDto.csproj
Backend.slnDockerfileCommon
Requests
Responses
Endpoint
Backend.httpISaveSettings.cs
README.mdCommon
Attributes
BadRequestResponseAttribute.csCacheMaxAgeAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csSwaggerDefaultAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
MapperDto
Services
Configuration
Core
BackgroundTasks
Middleware
CacheMaxAgeMiddleware.csCookieAuthorizationMiddleware.csCustomExceptionHandlerMiddleware.csJwtRevocationMiddleware.csMaintenanceModeMiddleware.cs
Startup
Model
SwaggerOptions
Validation
Controllers
BaseController.cs
Endpoint.csprojProgram.csConfiguration
V1
AuthController.csCampusController.csDisciplineController.csFacultyController.csGroupController.csImportController.csLectureHallController.csProfessorController.csScheduleController.cs
WeatherForecastController.csSync
WeatherForecast.cswwwroot/css/swagger
Security
Common
CookieNames.cs
DependencyInjection.csDomain
Caching
CookieOptionsParameters.csOAuth2
OAuthProvider.csOAuthUser.csRequestContextInfo.csTwoFactorAuthenticator.csUser.csInterfaces
Properties
Security.csprojServices
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus/Queries
GetCampusBasicInfoList
CampusBasicInfoDto.csCampusBasicInfoVm.csGetCampusBasicInfoListQuery.csGetCampusBasicInfoListQueryHandler.cs
GetCampusDetails
Discipline/Queries
GetDisciplineDetails
GetDisciplineList
Faculty/Queries/GetFacultyList
Group/Queries
GetGroupDetails
GetGroupList
LectureHall/Queries
GetLectureHallDetails
GetLectureHallList
Professor/Queries
GetProfessorDetails
GetProfessorDetailsBySearch
GetProfessorList
Schedule/Queries/GetScheduleList
Interfaces/DbContexts
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.cs20241027034820_RemoveUnusedRef.Designer.cs20241027034820_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.cs20241027032753_RemoveUnusedRef.Designer.cs20241027032753_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts/Schedule
CampusDbContext.csDisciplineDbContext.csFacultyDbContext.csGroupDbContext.csLectureHallDbContext.csLessonAssociationDbContext.csLessonDbContext.csProfessorDbContext.csSpecificWeekDbContext.csTypeOfOccupationDbContext.cs
DbInitializer.csDependencyInjection.csEntityTypeConfigurations
Mark.cs
Persistence.csprojUberDbContext.csMysql/Schedule
CampusConfiguration.csDisciplineConfiguration.csFacultyConfiguration.csGroupConfiguration.csLectureHallConfiguration.csLessonAssociationConfiguration.csLessonConfiguration.csProfessorConfiguration.csSpecificWeekConfiguration.csTypeOfOccupationConfiguration.cs
Postgresql/Schedule
CampusConfiguration.csDisciplineConfiguration.csFacultyConfiguration.csGroupConfiguration.csLectureHallConfiguration.csLessonAssociationConfiguration.csLessonConfiguration.csProfessorConfiguration.csSpecificWeekConfiguration.csTypeOfOccupationConfiguration.cs
Sqlite/Schedule
@ -15,7 +15,9 @@ using Mirea.Api.Security.Common.Domain;
|
|||||||
using Mirea.Api.Security.Services;
|
using Mirea.Api.Security.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using OAuthProvider = Mirea.Api.Security.Common.Domain.OAuthProvider;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Controllers.V1;
|
namespace Mirea.Api.Endpoint.Controllers.V1;
|
||||||
|
|
||||||
@ -30,13 +32,36 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of available OAuth providers with their respective redirect URIs.
|
/// Initiates the OAuth2 authorization process for the selected provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of available providers.</returns>
|
/// <remarks>
|
||||||
[HttpGet("GetAvailableProviders")]
|
/// This method generates a redirect URL for the selected provider and redirects the user to it.
|
||||||
public ActionResult<List<AvailableProvidersResponse>> GetUrls() =>
|
/// </remarks>
|
||||||
|
/// <param name="provider">The identifier of the OAuth provider to authorize with.</param>
|
||||||
|
/// <returns>A redirect to the OAuth provider's authorization URL.</returns>
|
||||||
|
/// <exception cref="ControllerArgumentException">Thrown if the specified provider is not valid.</exception>
|
||||||
|
[HttpGet("AuthorizeOAuth2")]
|
||||||
|
[MaintenanceModeIgnore]
|
||||||
|
public ActionResult AuthorizeOAuth2([FromQuery] int provider)
|
||||||
|
{
|
||||||
|
if (!Enum.IsDefined(typeof(OAuthProvider), provider))
|
||||||
|
throw new ControllerArgumentException("There is no selected provider");
|
||||||
|
|
||||||
|
return Redirect(oAuthService.GetProviderRedirect(HttpContext, GetCookieParams(), HttpContext.GetApiUrl(Url.Action("OAuth2")!), (OAuthProvider)provider).AbsoluteUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves a list of available OAuth providers with their corresponding authorization URLs.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This allows the client to fetch all possible OAuth options and the URLs required to initiate authorization.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns>A list of available providers and their redirect URLs.</returns>
|
||||||
|
[HttpGet("AvailableProviders")]
|
||||||
|
[MaintenanceModeIgnore]
|
||||||
|
public ActionResult<List<AvailableOAuthProvidersResponse>> AvailableProviders() =>
|
||||||
Ok(oAuthService
|
Ok(oAuthService
|
||||||
.GetAvailableProviders(HttpContext, GetCookieParams(), HttpContext.GetApiUrl(Url.Action("OAuth2")!))
|
.GetAvailableProviders(HttpContext, HttpContext.GetApiUrl(Url.Action("AuthorizeOAuth2")!))
|
||||||
.ConvertToDto());
|
.ConvertToDto());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -97,20 +97,26 @@ public class OAuthService(ILogger<OAuthService> logger, Dictionary<OAuthProvider
|
|||||||
return userInfo?.MapToInternalUser();
|
return userInfo?.MapToInternalUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public (OAuthProvider Provider, Uri Redirect)[] GetAvailableProviders(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUrl)
|
|
||||||
{
|
|
||||||
var redirectUri = "?client_id={0}" +
|
|
||||||
"&response_type=code" +
|
|
||||||
$"&redirect_uri={redirectUrl}" +
|
|
||||||
"&scope={1}" +
|
|
||||||
$"&state={new RequestContextInfo(context, cookieOptions).Fingerprint}_{{2}}";
|
|
||||||
|
|
||||||
return providers.Select(x => (x.Key, new Uri(ProviderData[x.Key].RedirectUrl.TrimEnd('/') +
|
public Uri GetProviderRedirect(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUri, OAuthProvider provider)
|
||||||
string.Format(redirectUri,
|
{
|
||||||
x.Value.ClientId,
|
var providerData = providers[provider];
|
||||||
ProviderData[x.Key].Scope,
|
|
||||||
Enum.GetName(x.Key))))
|
var redirectUrl = $"?client_id={providerData.ClientId}" +
|
||||||
).ToArray();
|
"&response_type=code" +
|
||||||
|
$"&redirect_uri={redirectUri}" +
|
||||||
|
$"&scope={ProviderData[provider].Scope}" +
|
||||||
|
$"&state={new RequestContextInfo(context, cookieOptions).Fingerprint}_{Enum.GetName(provider)}";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return new Uri(ProviderData[provider].RedirectUrl + redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public (OAuthProvider Provider, Uri Redirect)[] GetAvailableProviders(HttpContext context, string redirectUri)
|
||||||
|
{
|
||||||
|
return providers.Select(x => (x.Key, new Uri(redirectUri.TrimEnd('/') + "/?provider=" + (int)x.Key)))
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(OAuthProvider provider, OAuthUser User)> LoginOAuth(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUrl, string code, string state, CancellationToken cancellation = default)
|
public async Task<(OAuthProvider provider, OAuthUser User)> LoginOAuth(HttpContext context, CookieOptionsParameters cookieOptions, string redirectUrl, string code, string state, CancellationToken cancellation = default)
|
||||||
|
Reference in New Issue
Block a user