Ejemplo n.º 1
0
        public static async Task <string> GetAccessToken(IConfiguration configuration, Group group,
                                                         HttpClient httpClient,
                                                         IArangoDatabase database)
        {
            if (!group.DevOpsExpirationTime.HasValue)
            {
                return(null);
            }
            if ((group.DevOpsExpirationTime.Value - DateTime.UtcNow).Seconds > 0)
            {
                return(group.DevOpsToken);
            }

            var token = await RefreshToken(configuration, group.DevOpsRefreshToken, httpClient);

            group.DevOpsRefreshToken   = token.RefreshToken;
            group.DevOpsToken          = token.AccessToken;
            group.DevOpsExpirationTime = DateTime.UtcNow.AddSeconds(3000);
            await database.UpdateByIdAsync <Group>(group.Id, group);

            return(token.AccessToken);
        }