Exemple #1
0
        public void CreateEncodedJwtToken_FromString_ShouldNotFail()
        {
            // Arrange
            var privateKeySource = new StringPrivateKeySource(File.ReadAllText("envvar.pem"));
            var options          = new GitHubJwtFactoryOptions
            {
                AppIntegrationId  = 6837,
                ExpirationSeconds = 600 // 10 minutes maximum
            };
            var factory = new GitHubJwtFactory(privateKeySource, options);

            // Act
            var token = factory.CreateEncodedJwtToken();

            // Assert
            Assert.IsNotNull(token);
            Console.WriteLine(token);
        }
Exemple #2
0
        private static IGitHubClient ConstructGitHubClientWithPrivateKey(IConfiguration configuration, string privateKey)
        {
            var privateKeySource = new StringPrivateKeySource(
                privateKey);

            var tokenFactory = new GitHubJwtFactory(
                privateKeySource,
                new GitHubJwtFactoryOptions()
            {
                AppIntegrationId = int.Parse(
                    configuration["GitHub:PullDog:AppIdentifier"],
                    CultureInfo.InvariantCulture),
                ExpirationSeconds = 60 * 5
            });

            var token = tokenFactory.CreateEncodedJwtToken();

            return(new GitHubClient(new ProductHeaderValue("pull-dog"))
            {
                Credentials = new Credentials(
                    token,
                    AuthenticationType.Bearer)
            });
        }