fix: use url-unsafe base 64 for auth tokens
.net throws an error when decoding url-safe base 64 luckily we never decode it *except* for tokens, so those can keep using url-unsafe base 64. they're never used in URLs after all
This commit is contained in:
		
							parent
							
								
									9d33093339
								
							
						
					
					
						commit
						49b2902d6d
					
				
					 2 changed files with 5 additions and 4 deletions
				
			
		|  | @ -358,7 +358,7 @@ public class AuthService( | |||
| 
 | ||||
|     private static (string, byte[]) GenerateToken() | ||||
|     { | ||||
|         string token = AuthUtils.RandomToken(); | ||||
|         string token = AuthUtils.RandomUrlUnsafeToken(); | ||||
|         byte[] hash = SHA512.HashData(Convert.FromBase64String(token)); | ||||
| 
 | ||||
|         return (token, hash); | ||||
|  |  | |||
|  | @ -130,10 +130,11 @@ public static class AuthUtils | |||
|         return TryFromBase64String(input, out rawToken); | ||||
|     } | ||||
| 
 | ||||
|     public static string RandomUrlUnsafeToken(int bytes = 48) => | ||||
|         Convert.ToBase64String(RandomNumberGenerator.GetBytes(bytes)).Trim('='); | ||||
| 
 | ||||
|     public static string RandomToken(int bytes = 48) => | ||||
|         Convert | ||||
|             .ToBase64String(RandomNumberGenerator.GetBytes(bytes)) | ||||
|             .Trim('=') | ||||
|         RandomUrlUnsafeToken() | ||||
|             // Make the token URL-safe | ||||
|             .Replace('+', '-') | ||||
|             .Replace('/', '_'); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue