* Implement support for access tokens

A bit more work and testing is needed

* Make ValidUntil computed, fix netf, among others

* netf fixes as always

* Allow AWH to forcefully refresh session

* Unify access token lifetime
This commit is contained in:
Łukasz Domeradzki
2023-10-19 13:38:39 +02:00
committed by GitHub
parent 4106c5f41a
commit d571cd9580
7 changed files with 244 additions and 118 deletions

View File

@@ -24,6 +24,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Linq;
using System.Net;
@@ -48,6 +49,8 @@ public static class Utilities {
// normally we'd just use words like "steam" and "farm", but the library we're currently using is a bit iffy about banned words, so we need to also add combinations such as "steamfarm"
private static readonly ImmutableHashSet<string> ForbiddenPasswordPhrases = ImmutableHashSet.Create(StringComparer.InvariantCultureIgnoreCase, "archisteamfarm", "archi", "steam", "farm", "archisteam", "archifarm", "steamfarm", "asf", "asffarm", "password");
private static readonly JwtSecurityTokenHandler JwtSecurityTokenHandler = new();
[PublicAPI]
public static string GetArgsAsText(string[] args, byte argsToSkip, string delimiter) {
ArgumentNullException.ThrowIfNull(args);
@@ -187,6 +190,21 @@ public static class Utilities {
return (text.Length % 2 == 0) && text.All(Uri.IsHexDigit);
}
[PublicAPI]
public static JwtSecurityToken? ReadJwtToken(string token) {
if (string.IsNullOrEmpty(token)) {
throw new ArgumentNullException(nameof(token));
}
try {
return JwtSecurityTokenHandler.ReadJwtToken(token);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return null;
}
}
[PublicAPI]
public static IList<INode> SelectNodes(this IDocument document, string xpath) {
ArgumentNullException.ThrowIfNull(document);