Exemple #1
0
        /// <summary>
        /// Constructor for teh class
        /// </summary>
        /// <param name="token">Authentication token used for non-anonymous access to the API</param>
        /// <param name="productName">
        /// Identification string for the product that will be interacting with the GitHub API
        /// </param>
        public GitHub(string token, string productName)
        {
            var creds = new InMemoryCredentialStore(new Credentials(token));

            _client = new GitHubClient(new ProductHeaderValue(productName), creds);
            //var rl = new Octokit.RateLimit();
        }
Exemple #2
0
        public async Task <long> OpenAsync(GitHubClientParameters parameters)
        {
            var inMemoryCredentialStore = new InMemoryCredentialStore(new Credentials(KnownGitHubs.Username, parameters.Password));

            var githubClient = new GitHubClient(new ProductHeaderValue("ImgBot"), inMemoryCredentialStore);

            var repo = await githubClient.Repository.Get(parameters.RepoOwner, parameters.RepoName);

            var branch = await githubClient.Repository.Branch.Get(parameters.RepoOwner, parameters.RepoName, KnownGitHubs.BranchName);

            var commit = await githubClient.Repository.Commit.Get(parameters.RepoOwner, parameters.RepoName, branch.Commit.Sha);

            if (branch == null)
            {
                return(0);
            }

            var pr = new NewPullRequest(KnownGitHubs.CommitMessageTitle, KnownGitHubs.BranchName, repo.DefaultBranch)
            {
                Body = PullRequestBody.Generate(commit.Commit.Message),
            };

            var result = await githubClient.PullRequest.Create(parameters.RepoOwner, parameters.RepoName, pr);

            return(result.Id);
        }
        private static GitHub CreateGitHubClient(string accessToken)
        {
            var credentialStore = new InMemoryCredentialStore(new Credentials(accessToken));
            var gitHubClient    = new GitHubClient(new ProductHeaderValue("info-scraper"), credentialStore);

            return(new GitHub(gitHubClient));
        }
        protected override Task ProcessRecordAsync()
        {
            if (OAuthToken == null)
            {
                throw new ArgumentNullException(nameof(OAuthToken));
            }
            if (OAuthTokenSecret == null)
            {
                throw new ArgumentNullException(nameof(OAuthTokenSecret));
            }
            if (ConsumerKey == null)
            {
                throw new ArgumentNullException(nameof(ConsumerKey));
            }
            if (ConsumerSecret == null)
            {
                throw new ArgumentNullException(nameof(ConsumerSecret));
            }
            var memoryCredentialStore = new InMemoryCredentialStore {
                ConsumerKey      = ConsumerKey,
                ConsumerSecret   = ConsumerSecret,
                OAuthToken       = OAuthToken,
                OAuthTokenSecret = OAuthTokenSecret
            };
            var authorizer = new SingleUserAuthorizer {
                CredentialStore = memoryCredentialStore
            };

            return(authorizer.AuthorizeAsync().ToObservable()
                   .HandleErrors(this).Select(_ => new TwitterContext(authorizer))
                   .WriteObject(this)
                   .ToTask());
        }
Exemple #5
0
        protected override string IsValidDynamicHelper(ref string fingerprintText, ref string message)
        {
            var    fingerprint = new Fingerprint(fingerprintText);
            string pat         = fingerprint.PersonalAccessToken;

            try
            {
                var credentials      = new Credentials(pat);
                var credentialsStore = new InMemoryCredentialStore(credentials);
                var client           = new GitHubClient(new ProductHeaderValue(Guid.NewGuid().ToString()), credentialsStore);

                User   user = client.User.Current().GetAwaiter().GetResult();
                string id   = user.Login;
                string name = user.Name;

                IReadOnlyList <Organization> orgs = client.Organization.GetAllForCurrent().GetAwaiter().GetResult();
                string orgNames = string.Join(", ", orgs.Select(o => o.Login));

                message = $"the compromised GitHub account '{id} ({name})' has access to the following orgs '{orgNames}'";
            }
            catch (AuthorizationException)
            {
                return(nameof(ValidationState.Unauthorized));
            }
            catch (Exception e)
            {
                message = $"An unexpected exception was caught attempting to validate PAT: {e.Message}";
                return(nameof(ValidationState.Unknown));
            }

            return(nameof(ValidationState.Authorized));
        }
        public static IGitHubClient GitHubClient(string token, string userAgent)
        {
            var productHeaderValue = new ProductHeaderValue(userAgent);
            var credentialStore    = new InMemoryCredentialStore(new Credentials(token));

            return(new GitHubClient(productHeaderValue, credentialStore));
        }
        public InMemoryCredentialStore Build()
        {
            var credentialStore = new InMemoryCredentialStore(CredentialList);

            new CredentialSeeder().Seed(RoleStore, credentialStore).Wait();
            return(credentialStore);
        }
Exemple #8
0
        public GitHubPullRequestProvider(ProgramArgs programArgs)
        {
            _programArgs = programArgs;
            DiscoverToken();
            var gitHubCredentials = new InMemoryCredentialStore(new Credentials(_programArgs.GitHubToken));

            _gitHubClient = new GitHubClient(new ProductHeaderValue("PullRequestReleaseNotes"), gitHubCredentials);
        }
Exemple #9
0
        public int CountPullRequests()
        {
            var creds        = new InMemoryCredentialStore(new Credentials(token));
            var client       = new GitHubClient(new ProductHeaderValue(product_name), creds);
            var pullrequests = client.PullRequest.GetAllForRepository(owner, repo).Result;

            return(pullrequests.Count());
        }
 /// <summary>
 /// Setup our GitHubClient in the constructor to be used
 /// </summary>
 /// <param name="_configuration">Configuration key/values from appsettings</param>
 public ProtectorLogic(IConfiguration _configuration)
 {
     Configuration = _configuration;
     UserName      = Configuration["OrgOwner"];
     Organization  = Configuration["Organization"];
     credentials   = new InMemoryCredentialStore(new Credentials(Configuration["Token"]));
     client        = new GitHubClient(new ProductHeaderValue(UserName), credentials);
 }
Exemple #11
0
        public void InitClient()
        {
            var inMemoryCredentials = new InMemoryCredentialStore(new Credentials(textBoxToken.Text.Trim()));

            _client = new GitHubClient(new ProductHeaderValue("GithubTool.ConsoleTest"), inMemoryCredentials);

            buttonUpload.Enabled = true;
        }
        private static void RegisterGithubClients(IKernel kernel)
        {
            var productHeaderValue = new ProductHeaderValue("CreateMask");
            var credentialStore    = new InMemoryCredentialStore(new Credentials("create-mask-error-reporter", "createmask2018"));
            var githubClient       = new GitHubClient(productHeaderValue, credentialStore);

            kernel.Bind <IReleasesClient>().ToConstant(githubClient.Repository.Release);
            kernel.Bind <IIssuesClient>().ToConstant(githubClient.Issue);
        }
Exemple #13
0
        public int CountPullRequests()
        {
            var creds        = new InMemoryCredentialStore(new Credentials(AppSettings.Value.GitHubSettings.Token));
            var client       = new GitHubClient(new ProductHeaderValue(AppSettings.Value.GitHubSettings.ProductName), creds);
            var pullrequests = client.PullRequest.GetAllForRepository(
                AppSettings.Value.GitHubSettings.Owner, AppSettings.Value.GitHubSettings.Repo).Result;

            return(pullrequests.Count());
        }
Exemple #14
0
        private GitHubClient GetGitHubClientWithApiKey([NotNull] string apiKey)
        {
            var version            = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var productInformation = new Octokit.ProductHeaderValue("DHGMS-Gitstronomy", version);
            var credentials        = new Credentials(apiKey);
            var credentialStore    = new InMemoryCredentialStore(credentials);

            return(new Octokit.GitHubClient(productInformation, credentialStore));
        }
Exemple #15
0
        public GithubPoller(IEnumerable <Project> projects, string user,
                            string password)
        {
            var creds      = new Credentials(user, password);
            var credsStore = new InMemoryCredentialStore(creds);

            this.github = new GitHubClient(new ProductHeaderValue("BuildSharp"),
                                           credsStore);
            this.projects = projects;
        }
 public LinqToTwitterPoller(IConfiguration config, ILogger <LinqToTwitterPoller> logger)
 {
     _logger      = logger;
     _credentials = new InMemoryCredentialStore
     {
         ConsumerKey    = config["TWITTER_API_KEY"],
         ConsumerSecret = config["TWITTER_API_SECRET"]
     };
     _trackFilter = config["TWITTER_FILTER"];
 }
        public override async Task Connect(string personalAccessToken)
        {
            var credentials      = new Credentials(this.AccountOrOrganization, personalAccessToken);
            var credentialsStore = new InMemoryCredentialStore(credentials);

            await Task.Run(() =>
            {
                this.gitHubClient = new GitHubClient(new ProductHeaderValue(this.AccountOrOrganization), credentialsStore);
            });
        }
        public static async Task <GroupShareClient> AuthenticateClient(string token, string user, string password, Uri baseAddress,
                                                                       IEnumerable <string> scopes)
        {
            var credentials = new Credentials(token, user, password);

            var inMemoryCredentials = new InMemoryCredentialStore(credentials);

            var groupShareClient = new GroupShareClient(inMemoryCredentials, baseAddress);

            return(groupShareClient);
        }
        public void BasicSignIn()
        {
            var config = Configuration.GetConfiguration;

            var credentials   = new Credentials(config.Username, config.Password, AuthenticationType.Basic);
            var inMemoryStore = new InMemoryCredentialStore(credentials);
            var gitlabClient  = new GitLabClient(new ProductHeaderValue(config.Username), inMemoryStore, config.Url);

            var user = gitlabClient.User.Current;

            Assert.AreNotEqual(user.Username, string.Empty);
        }
Exemple #20
0
        public GitHubDeployRequestCreator(Options _opts)
        {
            this.opts = _opts;

            var creds = new InMemoryCredentialStore(
                new Credentials(opts.GitToken));

            client = new GitHubClient(
                new ProductHeaderValue("Depreq"), creds, opts.GitRepoUri);
            var apiConn = new ApiConnection(client.Connection);

            aClient = new AssigneesClient(apiConn);
        }
        /// <summary>
        /// Creates a new instance of the GroupShare API v1 client that has the authorization token configured
        /// </summary>
        /// <param name="user">Provides the user for which to obtain the token.</param>
        /// <param name="password">Provides the password for the specified user.</param>
        /// <param name="baseAddress">The address to point this client to.</param>
        /// <param name="scopes">The token scope(s).</param>
        /// <returns></returns>

        public static async Task <string> GetRequestToken(string user, string password, Uri baseAddress,
                                                          IEnumerable <string> scopes)
        {
            var credentials = new Credentials(user, password);

            var inMemoryCredentials = new InMemoryCredentialStore(credentials);

            var tokenGroupShareClient = new GroupShareClient(inMemoryCredentials, baseAddress);

            var authorization = await tokenGroupShareClient.Authenticate.Post(scopes);

            return(authorization.Token);
        }
Exemple #22
0
        public async Task <bool> IsArchived(GitHubClientParameters parameters)
        {
            var inMemoryCredentialStore = new InMemoryCredentialStore(
                new Credentials(KnownGitHubs.Username, parameters.Password));

            var githubClient = new GitHubClient(
                new ProductHeaderValue("ImgBot"), inMemoryCredentialStore);

            var repo = await githubClient.Repository.Get(
                parameters.RepoOwner, parameters.RepoName);

            return(repo.Archived);
        }
Exemple #23
0
        public static GitHubClient Build()
        {
            var credentialStore = new InMemoryCredentialStore(Helper.Credentials);
            var httpClient      = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault);

            var connection = new Connection(
                new ProductHeaderValue("ReleaseNotesCompiler"),
                GitHubClient.GitHubApiUrl,
                credentialStore,
                httpClient,
                new SimpleJsonSerializer());

            return(new GitHubClient(connection));
        }
        static LinqToTwitterService()
        {
            var store = new InMemoryCredentialStore()
            {
                ConsumerKey    = "8SBo35KV2hEXeOQaW6ZDaw",
                ConsumerSecret = "fhNwwxui5hd8yeJJb6ZGrsKyxHEPk3d2dk1dLnFo2hM",
            };

            _appAuth = new ApplicationOnlyAuthorizer()
            {
                CredentialStore = store
            };
            _appAuth.AuthorizeAsync();
        }
        async public Task <IGitHubClientWrapper> ConnectAsync(string organization, string personalAccessToken)
        {
            var credentials      = new Credentials(personalAccessToken);
            var credentialsStore = new InMemoryCredentialStore(credentials);
            GitHubClientWrapper gitHubClientWrapper;

            gitHubClientWrapper = await Task.Run(() =>
            {
                var gitHubClient = new GitHubClient(new ProductHeaderValue(organization), credentialsStore);
                return(new GitHubClientWrapper(gitHubClient));
            });

            return(gitHubClientWrapper);
        }
Exemple #26
0
        private static IGitHubClient CreateGitHubClient(IReadOnlyList <string> args)
        {
            var information = new ProductHeaderValue("github-contributions");

            if (args.Count <= 1)
            {
                return(new GitHubClient(information));
            }

            var credentials = new Credentials(args[1]);

            var store = new InMemoryCredentialStore(credentials);

            return(new GitHubClient(information, store));
        }
Exemple #27
0
        static LinqToTwitterService()
        {
            MessageBoxService = Container.GetSharedInstance <IMessageBoxService>();
            var store = new InMemoryCredentialStore()
            {
                ConsumerKey    = "8SBo35KV2hEXeOQaW6ZDaw",
                ConsumerSecret = "fhNwwxui5hd8yeJJb6ZGrsKyxHEPk3d2dk1dLnFo2hM",
            };

            _pinAuth = new ApplicationOnlyAuthorizer()
            {
                CredentialStore = store
            };
            _pinAuth.AuthorizeAsync();
        }
Exemple #28
0
        public static GitHubClient Build()
        {
            var credentialStore = new InMemoryCredentialStore(GitHubHelper.Credentials);

            var httpClient = new HttpClientAdapter(null);

            var connection = new Connection(
                new ProductHeaderValue("ReleaseStats"),
                GitHubClient.GitHubApiUrl,
                credentialStore,
                httpClient,
                new SimpleJsonSerializer());

            return(new GitHubClient(connection));
        }
Exemple #29
0
        public static async Task OpenAsync(PullRequestParameters parameters)
        {
            var inMemoryCredentialStore = new InMemoryCredentialStore(new Credentials(KnownGitHubs.Username, parameters.Password));

            var githubClient = new GitHubClient(new ProductHeaderValue("ImgBot"), inMemoryCredentialStore);

            var repo = await githubClient.Repository.Get(parameters.RepoOwner, parameters.RepoName);

            var pr = new NewPullRequest(KnownGitHubs.CommitMessageTitle, KnownGitHubs.BranchName, repo.DefaultBranch)
            {
                Body = "Beep boop. Optimizing your images is my life. https://imgbot.net/ for more information."
            };

            await githubClient.PullRequest.Create(parameters.RepoOwner, parameters.RepoName, pr);
        }
        private static IGitHubClient GitHubClientFactory(IUnityContainer container)
        {
            Options            options            = container.Resolve <Options>();
            ProductHeaderValue productHeaderValue = GetProductHeaderValue();

            if (!String.IsNullOrWhiteSpace(options.Token))
            {
                Credentials      credentials     = new Credentials(options.Token);
                ICredentialStore credentialStore = new InMemoryCredentialStore(credentials);

                return(new GitHubClient(productHeaderValue, credentialStore));
            }

            return(new GitHubClient(productHeaderValue));
        }