Пример #1
0
        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);
        }
Пример #2
0
        public async Task RefreshToken()
        {
            try
            {
                if (Account == null)
                {
                    return;
                }

                var ret = await BitbucketClient.GetRefreshToken(
                    Secrets.ClientId, Secrets.ClientSecret, Account.RefreshToken);

                if (ret == null)
                {
                    return;
                }

                Account.RefreshToken = ret.RefreshToken;
                Account.Token        = ret.AccessToken;
                _accountsService.Save(Account).ToBackground();

                Client = BitbucketClient.WithBearerAuthentication(Account.Token);
            }
            catch
            {
                // Do nothing....
            }
        }
Пример #3
0
        public async Task <BitbucketClient> LoginAccount(Account account)
        {
            //Create the client
            var client = BitbucketClient.WithBearerAuthentication(account.Token);
            var user   = await client.Users.GetCurrent();

            account.Username  = user.Username;
            account.AvatarUrl = user.Links.Avatar.Href.Replace("/avatar/32", "/avatar/64");
            await _accountsService.Save(account);

            return(client);
        }