public async Task Login(string code) { var ret = await BitbucketClient.GetAuthorizationCode( Secrets.ClientId, Secrets.ClientSecret, code); var client = BitbucketClient.WithBearerAuthentication(ret.AccessToken); var user = await client.Users.GetCurrent(); var account = await _accountsService.Get(Domain, user.Username); if (account == null) { account = new Account { Username = user.Username, AvatarUrl = user.Links.Avatar.Href, RefreshToken = ret.RefreshToken, Token = ret.AccessToken }; await _accountsService.Save(account); } else { account.RefreshToken = ret.RefreshToken; account.Token = ret.AccessToken; account.AvatarUrl = user.Links.Avatar.Href; await _accountsService.Save(account); } ActivateUser(account, client); }