Skip to content

Commit 0644e1d

Browse files
committedJan 15, 2024
tidied up internal comments
1 parent a6d081e commit 0644e1d

File tree

2 files changed

+33
-83
lines changed

2 files changed

+33
-83
lines changed
 

‎WebApp/Classes/FunnySongz.cs

+24-25
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,44 @@ public static FunnySong[] GenerateFunnySongsFromJSON(string givenJson)
2323
foreach (var nn in result)
2424
{
2525
nn.RndVal = xRnd.Next(result.Count);
26-
//nn.ImportedOn = $"{DateTime.Now}-{xRnd.Next(result.Count)}"; //.ToString();
2726
nn.ImportedOn = $"{DateTime.Now}-{nn.RndVal}";
2827
}
2928
return result.ToArray();
3029
}
3130

3231
public static FunnySong[] GetFunnySongByID(int givenID)
3332
{
34-
var kludge = new List<FunnySong>();
33+
var kludge = new List<FunnySong>(); // super kludgy to return an array instead of an object - wouldn't ACTUALLY do it that way in a serious app...
3534
var result = GenerateFunnySongsFromJSON(FunnySongsSON).FirstOrDefault(f => f.Id == givenID);
3635
kludge.Add(result);
37-
return kludge.ToArray(); // result;
36+
return kludge.ToArray();
3837
}
3938
}
4039

4140
public class FunnySong
4241
{
43-
public int Id { get; set; } //1
44-
public string Title { get; set; } //Ave maria
45-
public string SubTitle { get; set; } //
46-
public string Composer { get; set; } //Bach
47-
public string ComposerPickerID { get; set; } //
48-
public string Lyricist { get; set; } //liturgy
49-
public string Arranger { get; set; } //
50-
public string Publisher { get; set; } //
51-
public string CopyrightNumber { get; set; } //
42+
public int Id { get; set; } //1
43+
public string Title { get; set; } //Ave maria
44+
public string SubTitle { get; set; } //
45+
public string Composer { get; set; } //Bach
46+
public string ComposerPickerID { get; set; } //
47+
public string Lyricist { get; set; } //liturgy
48+
public string Arranger { get; set; } //
49+
public string Publisher { get; set; } //
50+
public string CopyrightNumber { get; set; } //
5251
public string UserPermissionIfNotFGS { get; set; } //none
53-
public string PricePerCopy { get; set; } //3.14
54-
public string PricePerCopyAsOf { get; set; } //2012-04-23T182543.511Z
55-
public string Style { get; set; } //Gothic
56-
public string Instrumentation { get; set; } //Organ
57-
public string Level { get; set; } //Advanced
58-
public string ModifiedBy { get; set; } //Arthur Dent
59-
public string ModifiedByUserId { get; set; } //314
60-
public string ModifiedOn { get; set; } //2012-04-22T062501.511Z
61-
public string CreatedBy { get; set; } //Slarty Bartfast
62-
public string CreatedById { get; set; } //42
63-
public string CreatedOn { get; set; } //2012-04-23T132302.513Z
64-
public string ImportedOn { get; set; }
65-
public int RndVal { get; set; }
52+
public string PricePerCopy { get; set; } //3.14
53+
public string PricePerCopyAsOf { get; set; } //2012-04-23T182543.511Z
54+
public string Style { get; set; } //Gothic
55+
public string Instrumentation { get; set; } //Organ
56+
public string Level { get; set; } //Advanced
57+
public string ModifiedBy { get; set; } //Arthur Dent
58+
public string ModifiedByUserId { get; set; } //314
59+
public string ModifiedOn { get; set; } //2012-04-22T062501.511Z
60+
public string CreatedBy { get; set; } //Slarty Bartfast
61+
public string CreatedById { get; set; } //42
62+
public string CreatedOn { get; set; } //2012-04-23T132302.513Z
63+
public string ImportedOn { get; set; }
64+
public int RndVal { get; set; }
6665
}
6766
}

‎WebApp/Classes/JWT.cs

+9-58
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,6 @@ DateTime givenTokenExpires
3737
, givenClientSite
3838
, givenTokenClaimName
3939
, givenTokenExpires);
40-
41-
//var thisSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(givenAPISecret));
42-
//var thisCredentials = new SigningCredentials(thisSecurityKey, SecurityAlgorithms.HmacSha256);
43-
////var issuer = AppConfig.Setting.JWTapiSite;
44-
////var audience = AppConfig.Setting.JWTclientSite;
45-
////DateTime givenTokenExpires = DateTime.UtcNow.AddMinutes(AppConfig.Setting.JWTMinutesToLive);
46-
47-
////Create a List of Claims, Keep claims name short
48-
//var permClaims = new List<Claim>();
49-
////chr observation: I'm presuming that a GUID adds a bunch of randomness to the token - thus the signature won't betray the validating secret...
50-
//permClaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()));
51-
//permClaims.Add(new Claim("valid", "1"));
52-
////permClaims.Add(new Claim("userid", "1")); // redacted to keep api minimal
53-
//permClaims.Add(new Claim("name", givenUserID)); // our link to a user table somewhere
54-
55-
////Create Security Token object by giving required parameters
56-
//var token = new JwtSecurityToken(
57-
// givenIssuerSite,
58-
// givenClientSite,
59-
// permClaims,
60-
// expires: givenTokenExpires,
61-
// signingCredentials: thisCredentials);
62-
//var jwt_token = new JwtSecurityTokenHandler().WriteToken(token);
63-
//return new { data = jwt_token };
6440
}
6541
}
6642
return null;
@@ -76,9 +52,6 @@ DateTime givenTokenExpires
7652
{
7753
var thisSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(givenAPISecret));
7854
var thisCredentials = new SigningCredentials(thisSecurityKey, SecurityAlgorithms.HmacSha256);
79-
//var issuer = AppConfig.Setting.JWTapiSite;
80-
//var audience = AppConfig.Setting.JWTclientSite;
81-
//DateTime givenTokenExpires = DateTime.UtcNow.AddMinutes(AppConfig.Setting.JWTMinutesToLive);
8255

8356
//Create a List of Claims, Keep claims name short
8457
var permClaims = new List<Claim>();
@@ -97,29 +70,8 @@ DateTime givenTokenExpires
9770
signingCredentials: thisCredentials);
9871
var jwt_token = new JwtSecurityTokenHandler().WriteToken(token);
9972
return new { data = jwt_token };
100-
101-
//var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(givenSecret));
102-
//var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
103-
104-
////Create a List of Claims, Keep claims name short - minimalistic
105-
//var permClaims = new List<Claim>();
106-
//permClaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()));
107-
//permClaims.Add(new Claim("valid", "1"));
108-
//permClaims.Add(new Claim("name", givenTokenClaimName)); // the key to the user db - unique
109-
110-
////Create Security Token object by giving required parameters
111-
//var token = new JwtSecurityToken(givenIssuerSite,
112-
// givenClientSite,
113-
// permClaims,
114-
// expires: tokenexpires,
115-
// signingCredentials: credentials);
116-
//var jwt_token = new JwtSecurityTokenHandler().WriteToken(token);
117-
//return jwt_token; // new { data = jwt_token };
11873
}
119-
//}
120-
//public class JWTvalidator //: DelegatingHandler
121-
//{
122-
74+
12375
public static bool TryRetrieveToken(HttpRequestMessage givenRequest, out string token)
12476
{
12577
token = null;
@@ -133,7 +85,7 @@ public static bool TryRetrieveToken(HttpRequestMessage givenRequest, out string
13385
// next two lines are a kludge because the client is sending JSON instead of encoded string...
13486
var badhead = "{\"data\":\"";
13587
if (token.Substring(0,badhead.Length) == badhead ) { token = token.Substring(badhead.Length); token = token.Substring(0, token.Length - 2); }
136-
return true; // I was here - going to test out my JSON - then move onto bigger issues in the Claims try/catch...
88+
return true;
13789
}
13890

13991
public bool ValidateToken(HttpRequestMessage givenRequest, List<MockUzer> givenUsers, string givenSecret)
@@ -145,8 +97,6 @@ public bool ValidateToken(HttpRequestMessage givenRequest, List<MockUzer> givenU
14597
true,
14698
true);
14799
return ValidateHeaderToken(givenRequest, givenUsers, theseParams);
148-
149-
//return false;
150100
}
151101

152102
public bool ValidateHeaderToken(HttpRequestMessage givenRequest, List<MockUzer> givenUsers, TokenValidationParameters givenTokenValidationParameters)
@@ -196,10 +146,10 @@ bool givenIssuerSigningKey
196146
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(givenSecret));
197147
TokenValidationParameters validationParameters = new TokenValidationParameters()
198148
{
199-
ValidAudience = givenAudience, //"http://localhost:50191",
200-
ValidIssuer = givenIssuer, //"http://localhost:50191",
201-
ValidateLifetime = givenLifetime, // true,
202-
ValidateIssuerSigningKey = givenIssuerSigningKey, // true,
149+
ValidAudience = givenAudience,
150+
ValidIssuer = givenIssuer,
151+
ValidateLifetime = givenLifetime,
152+
ValidateIssuerSigningKey = givenIssuerSigningKey,
203153
LifetimeValidator = this.LifetimeValidator,
204154
IssuerSigningKey = securityKey
205155
};
@@ -223,19 +173,20 @@ public bool LifetimeValidator(DateTime? notBefore, DateTime? expires, SecurityTo
223173
return false;
224174
}
225175

226-
227176
public static string HashPassword(string password, string salt)
228177
{
229178
using (SHA1Managed sha1 = new SHA1Managed())
230179
{
231180
return Convert.ToBase64String(sha1.ComputeHash(Encoding.UTF8.GetBytes(salt + password)));
232181
}
233182
}
234-
// cargo cult coding: https://stackoverflow.com/questions/31908529/randomnumbergenerator-proper-usage
183+
184+
// thanks for the reminder of how to use this: https://stackoverflow.com/questions/31908529/randomnumbergenerator-proper-usage
235185
public static string GenRandomSeed()
236186
{
237187
return Convert.ToBase64String(GenerateSaltNewInstance(42));
238188
}
189+
239190
private static byte[] GenerateSaltNewInstance(int size)
240191
{
241192
using (var generator = RandomNumberGenerator.Create())

0 commit comments

Comments
 (0)