Skip to content

Commit

Permalink
Merge pull request #707 from mixcore/features/auth-add-client-credential
Browse files Browse the repository at this point in the history
Update OAuth
  • Loading branch information
nhathoang989 authored Nov 18, 2023
2 parents c801f4c + 81b5dc3 commit 817b97e
Show file tree
Hide file tree
Showing 54 changed files with 2,346 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Mixcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mix.log.lib", "platform\mix
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mix.log", "modules\mix.log\mix.log.csproj", "{F37BBDB4-EB48-42E4-8CB1-D459F5EF3C3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mix.oauth", "platform\mix.oauth\mix.oauth.csproj", "{C59DE2E9-2CF8-4BA0-A91C-4986AC060525}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -259,6 +261,10 @@ Global
{F37BBDB4-EB48-42E4-8CB1-D459F5EF3C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F37BBDB4-EB48-42E4-8CB1-D459F5EF3C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F37BBDB4-EB48-42E4-8CB1-D459F5EF3C3F}.Release|Any CPU.Build.0 = Release|Any CPU
{C59DE2E9-2CF8-4BA0-A91C-4986AC060525}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C59DE2E9-2CF8-4BA0-A91C-4986AC060525}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C59DE2E9-2CF8-4BA0-A91C-4986AC060525}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C59DE2E9-2CF8-4BA0-A91C-4986AC060525}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -318,6 +324,7 @@ Global
{B4C40E02-E06A-4359-BDC5-349E103366AD} = {5B29B975-B0AC-46B3-8398-4C8A22EAE355}
{BC6B8583-4F0F-45AD-BF71-1D998AA65869} = {84C68A6F-ECE0-467E-91C0-AE63AC4FC4C7}
{F37BBDB4-EB48-42E4-8CB1-D459F5EF3C3F} = {B4C40E02-E06A-4359-BDC5-349E103366AD}
{C59DE2E9-2CF8-4BA0-A91C-4986AC060525} = {0027B7D2-664D-4872-AE99-BA2A2BCA6B2E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0143C230-7F40-44B2-8BA3-EF5B92D55848}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@
using System.Web;
using Mix.Identity.Models.ManageViewModels;
using Mix.Lib.Interfaces;
using Mix.OAuth.OauthRequest;
using Mix.Identity.Services;
using Mix.Identity.Interfaces;

namespace Mix.Account.Controllers
{
[Route("api/v2/rest/mix-account/user")]
public class MixUserController : MixTenantApiControllerBase
public class MixAccountController : MixTenantApiControllerBase
{
private readonly TenantUserManager _userManager;
private readonly SignInManager<MixUser> _signInManager;
private readonly RoleManager<MixRole> _roleManager;
private readonly MixIdentityService _idService;
private readonly IAuthorizeResultService _authResultService;
private readonly IMixEdmService _edmService;
private readonly EntityRepository<MixCmsAccountContext, MixUser, Guid> _repository;
private readonly MixRepoDbRepository _repoDbRepository;
Expand All @@ -41,7 +45,7 @@ public class MixUserController : MixTenantApiControllerBase
private readonly EntityRepository<MixCmsAccountContext, RefreshTokens, Guid> _refreshTokenRepo;
private readonly AuthConfigService _authConfigService;

public MixUserController(
public MixAccountController(
TenantUserManager userManager,
SignInManager<MixUser> signInManager,
RoleManager<MixRole> roleManager,
Expand All @@ -58,7 +62,8 @@ public MixUserController(
IQueueService<MessageQueueModel> queueService,
AuthConfigService authConfigService,
IMixEdmService edmService,
IMixTenantService mixTenantService)
IMixTenantService mixTenantService,
IAuthorizeResultService authResultService)
: base(httpContextAccessor, configuration, mixService,
translator, mixIdentityService, queueService, mixTenantService)
{
Expand All @@ -76,6 +81,7 @@ public MixUserController(
_repoDbRepository = repoDbRepository;
_authConfigService = authConfigService;
_edmService = edmService;
_authResultService = authResultService;
}

#region Overrides
Expand Down Expand Up @@ -143,6 +149,22 @@ await _edmService.SendMailWithEdmTemplate("Welcome", "Welcome", ReflectionHelper
}
}

[HttpPost("connect/token")]
public JsonResult Token([FromBody] TokenRequest tokenRequest)
{
var result = _authResultService.GenerateToken(tokenRequest);

if (result.HasError)
return Json(new
{
error = result.Error,
error_description = result.ErrorDescription
});

return Json(result);
}


[AllowAnonymous]
[HttpGet("resend-confirm-email/{id}")]
public async Task<ActionResult> ResendConfirmEmail(string id)
Expand Down
1 change: 1 addition & 0 deletions src/modules/mix.account/mix.account.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<ItemGroup>
<ProjectReference Include="..\..\platform\mix.identity\mix.identity.csproj" />
<ProjectReference Include="..\..\platform\mix.library\mix.library.csproj" />
<ProjectReference Include="..\..\platform\mix.oauth\mix.oauth.csproj" />
<ProjectReference Include="..\mix.grpc\mix.grpc.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class MixAppConfigFilePaths
public const string Authentication = "mixcontent/shared/appconfigs/authentication";
public const string AppConfigs = "mixcontent/appconfigs";
public const string Shared = "mixcontent/shared";
public const string IdentityRSAKey = "mixcontent/shared/appconfigs/identity_rsa_key";
public const string Database = "mixcontent/shared/appconfigs/database";
public const string Culture = "mixcontent/shared/appconfigs/culture";
public const string ConnectionString = "mixcontent/shared/appconfigs/connection_string";
Expand Down
20 changes: 20 additions & 0 deletions src/platform/mix.identity/Interfaces/IAuthorizeResultService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2022 Mohammed Ahmed Hussien babiker Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
*/

using Microsoft.AspNetCore.Http;
using Mix.OAuth.OauthRequest;
using Mix.OAuth.OauthResponse;

namespace Mix.Identity.Interfaces
{
public interface IAuthorizeResultService
{
AuthorizeResponse AuthorizeRequest(IHttpContextAccessor httpContextAccessor, AuthorizationRequest authorizationRequest);
TokenResponse GenerateToken(TokenRequest tokenRequest);
}
}
12 changes: 12 additions & 0 deletions src/platform/mix.identity/Models/JwtSecurityKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mix.Identity.Models
{
internal class JwtSecurityKey
{
}
}
Loading

0 comments on commit 817b97e

Please sign in to comment.