示例#1
0
        static void Main(string[] args)
        {
            var tempoClient = new WorklogService(new Uri(""));

            tempoClient.SetBasicAuthentication("", "");

            var searchResult = tempoClient.Issue.GetAsync("21127").Result;
            var myselfAsync  = tempoClient.User.GetMyselfAsync().Result;
            var worklog      = new Worklog()
            {
                Author = new Author()
                {
                    Name = myselfAsync.Name,
                    Self = myselfAsync.Self.ToString()
                },
                Issue = new Issue()
                {
                    Key = "18652"
                },
                DateStarted       = DateTime.Now.ToString("o"),
                Comment           = "Tested toggl2tempo",
                TimeSpentSeconds  = 2600,
                WorklogAttributes = new List <WorklogAttribute>()
                {
                    new WorklogAttribute()
                    {
                        Key = "_Activity_", Value = "Other"
                    }
                }
            };

            var result = tempoClient.Tempo.CreateAsync(worklog).Result;
        }
        public IWorklogService GetWorkLogServiceFromCookie(Uri jiraHostUri)
        {
            var worklogService = new WorklogService(jiraHostUri);
            var jiraClaim      = _httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == JiraAuthCookie);
            var jiraCookies    = JsonConvert.DeserializeObject <IEnumerable <JiraCookie> >(jiraClaim.Value);

            foreach (var jiraCookie in jiraCookies)
            {
                var cookie = new Cookie(jiraCookie.Name, jiraCookie.Value);
                worklogService.Behaviour.CookieContainer.Add(worklogService.JiraBaseUri, cookie);
            }

            return(worklogService);
        }
        public LoginResult Login([FromBody] JiraAuthModel model)
        {
            var worklogService = new WorklogService(new Uri(_configuration.GetSection("Jira")["Host"]));

            try
            {
                worklogService.Session.StartAsync(model.User, model.Password).Wait();
            }
            catch
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            // TODO [as] Rework
            var jiraClaim = _cookieAuthentication.GetClaimWithJiraSession(worklogService);

            Authenticate(model.User, jiraClaim);
            return(new LoginResult {
                Username = model.User
            });
        }