private static void TestApiV1() { var sharpBucket = new SharpBucketV1(); // Decide on which authentication you wish to use //ReadTestDataBasic(); //sharpBucket.BasicAuthentication(email, password); ReadTestDataOauth(); // Two legged OAuth, just supply the consumerKey and the consumerSecretKey and you are done sharpBucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey); // Three legged OAuth. We can supply our own callback url to which bitbucket will send our pin // If we use "oob" as the callback url we will get the bitbuckets url address which will have our pin //var authenticator = sharpBucket.OAuth3LeggedAuthentication(consumerKey, consumerSecretKey, "oob"); //var uri = authenticator.StartAuthentication(); //Process.Start(uri); //var pin = Console.ReadLine(); // we can now do the final step by using the pin to get our access tokens //authenticator.AuthenticateWithPin(pin); // of if you saved the tokens you can simply use those // var authenticator = sharpBucket.OAuth3LeggedAuthentication(consumerKey, consumerSecretKey, "oauthtoken", "oauthtokensecret"); TestUserEndPoint(sharpBucket); TestIssuesEndPoint(sharpBucket); TestRepositoriesEndPoint(sharpBucket); TestUsersEndPoint(sharpBucket); TestPrivilegesEndPoint(sharpBucket); }
public static SharpBucketV1 GetV1ClientAuthenticatedWithOAuth() { //get the environment variable from OS registry key for the current user var consumerKey = Environment.GetEnvironmentVariable(SbConsumerKey); var consumerSecretKey = Environment.GetEnvironmentVariable(SbConsumerSecretKey); var sharpbucket = new SharpBucketV1(); sharpbucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey); return(sharpbucket); }
public override Task <bool> ReportPackageSourceAudit() { if (!AuditOptions.ContainsKey("BitBucketReportAccount") || !AuditOptions.ContainsKey("BitBucketReportName") || !AuditOptions.ContainsKey("BitBucketKey")) { throw new ArgumentException("The BitBucketReportAccount, BitBucketReportName, and BitBucketReportKey audit options must be present."); } string key = (string)AuditOptions["BitBucketKey"]; string[] k = key.Split('|'); if (k.Count() != 2) { throw new ArgumentException("The BitBucketReportKey audit option must have the format consumer_key|secret."); } string consumer = k[0], secret = k[1]; string account = (string)AuditOptions["BitBucketReportAccount"]; string repository = (string)AuditOptions["BitBucketReportName"]; if (AuditOptions.ContainsKey("BitBucketReportTitle")) { IssueTitle = (string)AuditOptions["BitBucketReportTitle"]; } else { IssueTitle = string.Format("[DevAudit] {0} audit on {1} {2}", Source.PackageManagerLabel, DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString()); } SharpBucketV1 sharp_bucket = new SharpBucketV1(); sharp_bucket.OAuth2LeggedAuthentication(consumer, secret); RepositoriesEndPoint repository_endpoint = sharp_bucket.RepositoriesEndPoint(account, repository); IssuesResource r; try { r = repository_endpoint.IssuesResource(); } catch (Exception e) { AuditEnvironment.Error(e, "Could not get issues resource for repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } BuildPackageSourceAuditReport(); Issue issue = new Issue() { title = IssueTitle, content = IssueText.ToString(), status = "new", priority = "major", kind = "bug" }; try { Issue i = r.PostIssue(issue); if (i == null) { AuditEnvironment.Error("Could not post issue to repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } else { AuditEnvironment.Success("Created issue {0} at {1}.", i.title, i.resource_uri); } } catch (Exception e) { AuditEnvironment.Error(e, "Could not post issue to repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } return(Task.FromResult(true)); }