Add Program Manager menu item and implement JWT token generation for SSO login

This commit is contained in:
2025-12-06 16:24:11 +03:30
parent 87ff7976fb
commit 323a46a623
4 changed files with 74 additions and 4 deletions

View File

@@ -7,6 +7,10 @@ using Company.Domain.WorkshopAccountAgg;
using CompanyManagment.App.Contracts.Workshop;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using WorkFlow.Application.Contracts.AdminWorkFlow;
namespace ServiceHost.Areas.AdminNew.Pages
@@ -121,5 +125,51 @@ namespace ServiceHost.Areas.AdminNew.Pages
data = checkerCount,
});
}
public IActionResult OnGetProgramManager()
{
try
{
// دریافت اطلاعات کاربر فعلی
var currentAccountId = _authHelper.CurrentAccountId();
var accountInfo = _authHelper.CurrentAccountInfo();
// تعریف Secret Key برای JWT (باید در appsettings.json تعریف شود)
var secretKey = _configuration["JwtSettings:SecretKey"] ?? ">3£>^1UBG@yw)QdhRC3$£:;r8~?qpp^oKK4D3a~8L2>enF;lkgh";
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey));
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
// ایجاد Claims
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, currentAccountId.ToString()),
new Claim(ClaimTypes.Name, accountInfo.Fullname ?? ""),
new Claim(ClaimTypes.Email, accountInfo.Username ?? ""),
new Claim("AccountId", currentAccountId.ToString()),
new Claim("RoleId", accountInfo.RoleId.ToString())
};
// ایجاد JWT Token
var token = new JwtSecurityToken(
issuer: _configuration["JwtSettings:Issuer"] ?? "GozareshgirApp",
audience: _configuration["JwtSettings:Audience"] ?? "GozareshgirUsers",
claims: claims,
expires: DateTime.UtcNow.AddMinutes(int.Parse(_configuration["JwtSettings:ExpirationMinutes"] ?? "30")),
signingCredentials: credentials
);
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
var domain = _configuration["GozareshgirProgramManager:Domain"] ?? "http://localhost:5000";
// Redirect به SSO-Login با Token
// var ssoUrl = $"https://pm{domain}/sso-login?token={Uri.EscapeDataString(tokenString)}";
var ssoUrl = $"https://localhost:7032/api/Auth/sso-login?token={Uri.EscapeDataString(tokenString)}";
return Redirect(ssoUrl);
}
catch (Exception ex)
{
// در صورت خطا، برگشت به صفحه اصلی
return RedirectToPage("/Index");
}
}
}
}

View File

@@ -629,6 +629,15 @@
</div>
</a>
</li>
<li>
<a asp-area="AdminNew" asp-page="/Index" asp-page-handler="ProgramManager" class="waves-effect btnCustom">
<div class="menuTitle">
<i class="md md-home"></i>
<span> پروگرام منیجر </span>
</div>
</a>
</li>
<li class="has_sub" permission="307">
<a class="waves-effect MainMenuItem">

View File

@@ -48,7 +48,13 @@
//, "09116067106", "09114221321"
]
},
"SepehrGateWayTerminalId": 99213700
"SepehrGateWayTerminalId": 99213700,
"JwtSettings": {
"SecretKey": ">3£>^1UBG@yw)QdhRC3$£:;r8~?qpp^oKK4D3a~8L2>enF;lkgh",
"Issuer": "GozareshgirApp",
"Audience": "GozareshgirUsers",
"ExpirationMinutes": 30
}
}

View File

@@ -7,7 +7,7 @@
}
},
"ConnectionStrings": {
//"MesbahDb": "Data Source=.\\MSSQLSERVER2019;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=mesbah_db;Password=sa142857$@;"
//"MesbahDb": "Data Source=.\\MSSQLSERVER2019;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=mesbah_db;Password=sa142857$@;"
"MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;",
//dad-mehr
@@ -36,6 +36,11 @@
"IsTestMode": false,
"TestNumbers": []
},
"SepehrGateWayTerminalId": 99213700
"SepehrGateWayTerminalId": 99213700,
"JwtSettings": {
"SecretKey": ">3£>^1UBG@yw)QdhRC3$£:;r8~?qpp^oKK4D3a~8L2>enF;lkgh",
"Issuer": "GozareshgirApp",
"Audience": "GozareshgirUsers",
"ExpirationMinutes": 30
}
}