(content)!;
+ if (!string.IsNullOrEmpty((string)obj["Url"]))
+ {
+ url = (string)obj["Url"];
+ }
+ }
+ else
+ {
+ // create template appsettings.json file
+ using (StreamWriter writer = File.CreateText(file))
+ {
+ writer.WriteLine("{ \"Url\": \"\" }");
+ }
}
}
+ return url;
}
- private static void LoadClientAssemblies(HttpClient http)
+ private static void LoadClientAssemblies(HttpClient http, string apiurl)
{
try
{
@@ -227,7 +231,7 @@ public static class MauiProgram
}
catch (Exception ex)
{
- Debug.WriteLine($"Oqtane Error: Loading Client Assemblies {ex}");
+ Debug.WriteLine($"Error Loading Client Assemblies From {apiurl} - {ex}");
}
}
diff --git a/Oqtane.Server/Infrastructure/Middleware/JwtMiddleware.cs b/Oqtane.Server/Infrastructure/Middleware/JwtMiddleware.cs
index f0e65998..7b8696fa 100644
--- a/Oqtane.Server/Infrastructure/Middleware/JwtMiddleware.cs
+++ b/Oqtane.Server/Infrastructure/Middleware/JwtMiddleware.cs
@@ -37,20 +37,46 @@ namespace Oqtane.Infrastructure
var identity = jwtManager.ValidateToken(token, secret, sitesettings.GetValue("JwtOptions:Issuer", ""), sitesettings.GetValue("JwtOptions:Audience", ""));
if (identity != null && identity.Claims.Any())
{
- // create user identity using jwt claims (note the difference in claimtype names)
- var user = new User
+ var idclaim = "nameid";
+ var nameclaim = "unique_name";
+ var legacynameclaim = "name"; // this was a breaking change in System.IdentityModel.Tokens.Jwt in .NET 7
+
+ // get jwt claims for userid and username
+ var userid = identity.Claims.FirstOrDefault(item => item.Type == idclaim)?.Value;
+ if (userid != null)
{
- UserId = int.Parse(identity.Claims.FirstOrDefault(item => item.Type == "nameid")?.Value),
- Username = identity.Claims.FirstOrDefault(item => item.Type == "name")?.Value
- };
- // jwt already contains the roles - we are reloading to ensure most accurate permissions
- var _userRoles = context.RequestServices.GetService(typeof(IUserRoleRepository)) as IUserRoleRepository;
+ if (!int.TryParse(userid, out _))
+ {
+ userid = null;
+ }
+ }
+ var username = identity.Claims.FirstOrDefault(item => item.Type == nameclaim)?.Value;
+ if (username == null)
+ {
+ // fallback for legacy clients
+ username = identity.Claims.FirstOrDefault(item => item.Type == legacynameclaim)?.Value;
+ }
- // set claims identity
- var claimsidentity = UserSecurity.CreateClaimsIdentity(alias, user, _userRoles.GetUserRoles(user.UserId, alias.SiteId).ToList());
- context.User = new ClaimsPrincipal(claimsidentity);
+ if (userid != null && username != null)
+ {
+ // create user identity
+ var user = new User
+ {
+ UserId = int.Parse(userid),
+ Username = username
+ };
- logger.Log(alias.SiteId, LogLevel.Information, "TokenValidation", Enums.LogFunction.Security, "Token Validated For User {Username}", user.Username);
+ // set claims identity (note jwt already contains the roles - we are reloading to ensure most accurate permissions)
+ var _userRoles = context.RequestServices.GetService(typeof(IUserRoleRepository)) as IUserRoleRepository;
+ var claimsidentity = UserSecurity.CreateClaimsIdentity(alias, user, _userRoles.GetUserRoles(user.UserId, alias.SiteId).ToList());
+ context.User = new ClaimsPrincipal(claimsidentity);
+
+ logger.Log(alias.SiteId, LogLevel.Information, "TokenValidation", Enums.LogFunction.Security, "Token Validated For UserId {UserId} And Username {Username}", user.UserId, user.Username);
+ }
+ else
+ {
+ logger.Log(alias.SiteId, LogLevel.Error, "TokenValidation", Enums.LogFunction.Security, "Token Validated But Could Not Locate UserId Or Username In Claims {Claims}", identity.Claims.ToString());
+ }
}
else
{
diff --git a/Oqtane.Server/Infrastructure/UpgradeManager.cs b/Oqtane.Server/Infrastructure/UpgradeManager.cs
index c4d5e91f..3af4b4b7 100644
--- a/Oqtane.Server/Infrastructure/UpgradeManager.cs
+++ b/Oqtane.Server/Infrastructure/UpgradeManager.cs
@@ -231,7 +231,7 @@ namespace Oqtane.Infrastructure
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
- Content = "The page you requested does not exist.
"
+ Content = "The page you requested does not exist or you do not have sufficient rights to view it.
"
}
}
});
diff --git a/Oqtane.Server/Managers/UserManager.cs b/Oqtane.Server/Managers/UserManager.cs
index 92677c78..e7d99d51 100644
--- a/Oqtane.Server/Managers/UserManager.cs
+++ b/Oqtane.Server/Managers/UserManager.cs
@@ -130,14 +130,14 @@ namespace Oqtane.Managers
if (!user.EmailConfirmed)
{
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
- string url = alias.Protocol + "://" + alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
+ string url = alias.Protocol + alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
string body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
var notification = new Notification(user.SiteId, User, "User Account Verification", body);
_notifications.AddNotification(notification);
}
else
{
- string url = alias.Protocol + "://" + alias.Name;
+ string url = alias.Protocol + alias.Name;
string body = "Dear " + user.DisplayName + ",\n\nA User Account Has Been Successfully Created For You. Please Use The Following Link To Access The Site:\n\n" + url + "\n\nThank You!";
var notification = new Notification(user.SiteId, User, "User Account Notification", body);
_notifications.AddNotification(notification);
@@ -299,7 +299,7 @@ namespace Oqtane.Managers
var alias = _tenantManager.GetAlias();
user = _users.GetUser(user.Username);
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
- string url = alias.Protocol + "://" + alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
+ string url = alias.Protocol + alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
string body = "Dear " + user.DisplayName + ",\n\nYou attempted multiple times unsuccessfully to log in to your account and it is now locked out. Please wait a few minutes and then try again... or use the link below to reset your password:\n\n" + url +
"\n\nPlease note that the link is only valid for 24 hours so if you are unable to take action within that time period, you should initiate another password reset on the site." +
"\n\nThank You!";
@@ -348,7 +348,7 @@ namespace Oqtane.Managers
var alias = _tenantManager.GetAlias();
user = _users.GetUser(user.Username);
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
- string url = alias.Protocol + "://" + alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
+ string url = alias.Protocol + alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
string body = "Dear " + user.DisplayName + ",\n\nYou recently requested to reset your password. Please use the link below to complete the process:\n\n" + url +
"\n\nPlease note that the link is only valid for 24 hours so if you are unable to take action within that time period, you should initiate another password reset on the site." +
"\n\nIf you did not request to reset your password you can safely ignore this message." +
diff --git a/Oqtane.Server/Repository/SiteRepository.cs b/Oqtane.Server/Repository/SiteRepository.cs
index e75738ae..72e07bc7 100644
--- a/Oqtane.Server/Repository/SiteRepository.cs
+++ b/Oqtane.Server/Repository/SiteRepository.cs
@@ -640,7 +640,7 @@ namespace Oqtane.Repository
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
- Content = "The page you requested does not exist.
"
+ Content = "The page you requested does not exist or you do not have sufficient rights to view it.
"
}
}
});