public static async Task <BoolValue <AuthResult> > GetAccessTokenAsync(AuthConfig config, string cacheKey) { var accessToken = new TokenInfo(new RandomString(), TokenRole.AccessToken, DateTime.Now.Add(AccessTokenLongevity), null); var refreshToken = new TokenInfo(new RandomString(), TokenRole.RefreshToken, null, null); if (!config.IsRequestingUserId) { return(await config.CacheAsync(new AuthResult(null, null, accessToken, refreshToken), cacheKey)); } var idToken = new TokenInfo(simulatedJwtToken(), TokenRole.IdToken, DateTime.Now.Add(IdTokenLongevity), onValidateSimulatedIdToken); return(await config.CacheAsync(new AuthResult(null, null, accessToken, refreshToken, idToken), cacheKey)); }
public static async Task <BoolValue <AuthResult> > TryGetSimulatedRenewedAccessTokenAsync(string refreshToken, AuthConfig config, string cacheKey) { var canBeRefreshed = await config.TryGetFromRefreshTokenAsync(refreshToken); if (!canBeRefreshed) { return(BoolValue <AuthResult> .Fail($"Invalid refresh token")); } var accessToken = new TokenInfo(new RandomString(), TokenRole.AccessToken, DateTime.Now.Add(AccessTokenLongevity), null); return(await config.CacheAsync(new AuthResult(null, null, accessToken), cacheKey)); }