Shady nagy/net6 (#614)
* udated to .net6 * used the .net6 version RC2 * added editconfig. * App core new Scoped Namespaces style. * BlazorAdmin new Scoped Namespaces style. * Blazor Shared new Scoped Namespaces style. * Infra new Scoped Namespaces style. * public api new Scoped Namespaces style. * web new Scoped Namespaces style. * FunctionalTests new Scoped Namespaces style. * Integrational tests new Scoped Namespaces style. * unit tests new Scoped Namespaces style. * update github action. * update github action. * change the global.
This commit is contained in:
@@ -1,50 +1,49 @@
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.Web.Api
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.Web.Api;
|
||||
|
||||
public class ApiTokenHelper
|
||||
{
|
||||
public class ApiTokenHelper
|
||||
public static string GetAdminUserToken()
|
||||
{
|
||||
public static string GetAdminUserToken()
|
||||
{
|
||||
string userName = "admin@microsoft.com";
|
||||
string[] roles = { "Administrators" };
|
||||
string userName = "admin@microsoft.com";
|
||||
string[] roles = { "Administrators" };
|
||||
|
||||
return CreateToken(userName, roles);
|
||||
return CreateToken(userName, roles);
|
||||
}
|
||||
|
||||
public static string GetNormalUserToken()
|
||||
{
|
||||
string userName = "demouser@microsoft.com";
|
||||
string[] roles = { };
|
||||
|
||||
return CreateToken(userName, roles);
|
||||
}
|
||||
|
||||
private static string CreateToken(string userName, string[] roles)
|
||||
{
|
||||
var claims = new List<Claim> { new Claim(ClaimTypes.Name, userName) };
|
||||
|
||||
foreach (var role in roles)
|
||||
{
|
||||
claims.Add(new Claim(ClaimTypes.Role, role));
|
||||
}
|
||||
|
||||
public static string GetNormalUserToken()
|
||||
var key = Encoding.ASCII.GetBytes(AuthorizationConstants.JWT_SECRET_KEY);
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
string userName = "demouser@microsoft.com";
|
||||
string[] roles = { };
|
||||
|
||||
return CreateToken(userName, roles);
|
||||
}
|
||||
|
||||
private static string CreateToken(string userName, string[] roles)
|
||||
{
|
||||
var claims = new List<Claim> { new Claim(ClaimTypes.Name, userName) };
|
||||
|
||||
foreach (var role in roles)
|
||||
{
|
||||
claims.Add(new Claim(ClaimTypes.Role, role));
|
||||
}
|
||||
|
||||
var key = Encoding.ASCII.GetBytes(AuthorizationConstants.JWT_SECRET_KEY);
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims.ToArray()),
|
||||
Expires = DateTime.UtcNow.AddHours(1),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
Subject = new ClaimsIdentity(claims.ToArray()),
|
||||
Expires = DateTime.UtcNow.AddHours(1),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user