コード例 #1
0
        public Task <IBitbucketClient> AuthentificateAsync(string verifier)
        {
            if (_oauthToken == null)
            {
                throw new BitbucketException("No token request was made. Call RequestTokenAsync first.");
            }
            var taskCompletionSource = new TaskCompletionSource <IBitbucketClient>();
            var client = new RestClient(AUTHENTIFICATION_URL);

            client.Authenticator = OAuth1Authenticator.ForAccessToken(
                _key, _secretKey, _oauthToken, _oauthTokenSecret, verifier
                );
            var request = new RestRequest("oauth/access_token", Method.POST);

            client.ExecuteAsync(request, response =>
            {
                var queryString            = HttpUtility.ParseQueryString(response.Content);
                _oauthTokenForAccess       = queryString["oauth_token"];
                _oauthTokenSecretForAccess = queryString["oauth_token_secret"];
                if ((string.IsNullOrWhiteSpace(_oauthTokenForAccess) == true) ||
                    (string.IsNullOrWhiteSpace(_oauthTokenSecretForAccess) == true))
                {
                    var exception = new BitbucketException("Access tokens were not received");
                    taskCompletionSource.SetException(exception);
                }
                var authentificator = OAuth1Authenticator.ForProtectedResource(
                    _key, _secretKey,
                    _oauthTokenForAccess, _oauthTokenSecretForAccess);
                System.Diagnostics.Debug.WriteLine(_oauthTokenForAccess + "\n" + _oauthTokenSecretForAccess);
                var bitbucketClient = new BitbucketClient(authentificator);
                taskCompletionSource.SetResult(bitbucketClient);
            });
            return(taskCompletionSource.Task);
        }
コード例 #2
0
        public IBitbucketClient AuthentificateWithLogin(string username, string password)
        {
            var authentificator = new HttpBasicAuthenticator(username, password);
            var bitbucketClient = new BitbucketClient(authentificator);

            return(bitbucketClient);
        }
コード例 #3
0
        public IBitbucketClient AuthentificateWithAccessToken(string token, string secretToken)
        {
            var authentificator = OAuth1Authenticator.ForProtectedResource(
                _key, _secretKey,
                _oauthTokenForAccess, _oauthTokenSecretForAccess);
            var bitbucketClient = new BitbucketClient(authentificator);

            return(bitbucketClient);
        }