private async Task Initialize() { using IServiceScope scope = services.CreateScope(); ITokenDataContext ctx = scope.GetRequiredService <ITokenDataContext>(); List <UserToken> storedTokens = await ctx.GlowTokenCache.ToListAsync(); foreach (UserToken token in storedTokens) { tokens[token.UserId] = new ActiveUser(token.UserId, "", "", token.AccessToken); } initialized = true; }
public async Task Set(string userId, ActiveUser user) { using IServiceScope scope = services.CreateScope(); ITokenDataContext ctx = scope.GetRequiredService <ITokenDataContext>(); UserToken existingToken = await ctx.GlowTokenCache.SingleOrDefaultAsync(v => v.UserId == userId); if (existingToken == null) { ctx.GlowTokenCache.Add(new UserToken { UserId = userId, AccessToken = user.AccessToken }); } else { existingToken.AccessToken = user.AccessToken; } await ctx.SaveChangesAsync(); tokens[userId] = user; }