refactor: add DatabaseContext.GetToken method
This commit is contained in:
parent
be34c4c77e
commit
2682cabfb0
6 changed files with 51 additions and 35 deletions
|
@ -79,6 +79,17 @@ public static class AuthUtils
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryParseToken(string? input, out byte[] rawToken)
|
||||
{
|
||||
rawToken = [];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input)) return false;
|
||||
if (input.StartsWith("bearer ", StringComparison.InvariantCultureIgnoreCase))
|
||||
input = input["bearer ".Length..];
|
||||
|
||||
return TryFromBase64String(input, out rawToken);
|
||||
}
|
||||
|
||||
public static string RandomToken(int bytes = 48) =>
|
||||
Convert.ToBase64String(RandomNumberGenerator.GetBytes(bytes)).Trim('=');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue