Ejemplo n.º 1
0
        public static void AddStoneBankingJwt(this IServiceCollection services, IConfigurationRoot configurationRoot)
        {
            if (services == null)
            {
                throw new ArgumentNullException("ServiceCollection cannot be null");
            }

            if (configurationRoot == null)
            {
                throw new ArgumentNullException("ConfigurationRoot cannot be null. Try add 'services.AddSingleton(Configuration);' before 'services.AddStoneBankingJwt();'");
            }

            var section = configurationRoot.GetSection("StoneBankingJwt");

            if (!section.Exists())
            {
                throw new ArgumentException("ConfigurationRoot must have a section with name StoneBankingJwt.");
            }

            var stoneBankingSettings = new StoneBankingSettings();

            configurationRoot.GetSection("StoneBankingJwt").Bind(stoneBankingSettings);

            AddStoneBankingJwt(services, stoneBankingSettings);
        }
Ejemplo n.º 2
0
        public static void LoadConfig_WithObject()
        {
            // arrange
            var services             = new ServiceCollection();
            var stoneBankingSettings = new StoneBankingSettings
            {
                ClientId   = "1231234",
                PrivateKey = "-----BEGIN RSA PRIVATE KEY-----\nMIIJKAIBAAKCAgEAr49YBXfHZkPxXAQ+uHWcHNMLt2PY0t1G5TvAV6+BQBvv64BA\nSjVe0uBHw8LOeQ1Gu5aQDyxUm5PDzORrkK+y9YaK+2X24XkRVuR9v4ZD5eQXKLan\nNm/6EGPmeHfsmhI3ecgjePs+M7kEkcVcloO6EPEZdhf32NLV+tY6D4FKD3sJ+RhV\n7CmKoBi6Befwlmpo64kStdzlaq2s3jMNvxWMH4rjuYglC3LKNsTzbKBqyS+aqFOf\nE5MRCCyAlusN/vQ6cD3/AHzTbVpNgohk6T0cp/7iZSAhD3T6/HmXEALrenNoMZrz\nQES5Qbf2XgozQvh0j/UONYVWA6cfkY7+gttewcENe1h+Rm+5inWCc7aEKAlldJrZ\nsI5jH90yewoFtcgvsKl18OQC//H/Hix1g8x5dNaje9H9WtKYwtPtu9xzUeO0sFtF\nra1qknGKvCXP+H1t4mX9VnmUMx+2iTZfss4VrJvEaw/mNbJx1w0sjQioJpsik8Pq\nV4B//ZVK8xMcY4P/H8ly5eTHJB91NBcZZi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Fra1qknGKvCXP+H1t4mX9VnmUMx+2iTZfss4V\nrJvEaw/mNbJx1w0sjQioJpsik8PqV4B//ZVK8xMcY4P/H8ly5eTHJB91NBcZZiy8\nnUGMbybV8SJH4FmqnFfIIMJODQao6XhbkQ0IFkqWmWR4gyLaIKQ2QIKW/uzB5ClL\nTLq6Pkc0pkP9zhmrBKw5ejJRzyIRAksodp/lXsyBMOhw2cAK30SjYeAWKH0BmTfV\nd2GzlXHVfGLqk5wWZl3lzoUCAwEAAQ==\n-----END PUBLIC KEY-----\n",
            };

            // act
            services.AddStoneBankingJwt(stoneBankingSettings);
            var provider = services.BuildServiceProvider();

            var settings = provider.GetService <StoneBankingSettings>();
            var jwtSign  = provider.GetService <IStoneBankingJwt>();

            // assert
            Assert.Equal(settings.ClientId, "1231234");
            Assert.Equal(settings.ConsentExpiresInSeconds, 300);
            Assert.Equal(settings.AuthenticationExpiresInSeconds, 900);
            Assert.Equal(settings.Environment, StoneBankingEnvironment.Sandbox);
            Assert.Null(settings.ConsentDefaultRedirectUrl);
            Assert.Equal(settings.PublicKey, stoneBankingSettings.PublicKey);
            Assert.Equal(settings.PrivateKey, stoneBankingSettings.PrivateKey);

            var jwtSignObj = ((StoneBankingJwt)jwtSign);

            Assert.Equal(jwtSignObj.PublicKey, stoneBankingSettings.PublicKey);
            Assert.Equal(jwtSignObj.PrivateKey, stoneBankingSettings.PrivateKey);
        }
        public StoneBankingJwt(StoneBankingSettings stoneBankingSettings)
        {
            this.StoneBankingSettings = stoneBankingSettings;
            this.AssemblyVersion      = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            this.AccountsApiUrl       = StoneBankingSettingsStatic.GetAccountsApi(this.StoneBankingSettings.Environment);

            this.ValidateRequiredSettings();
            this.ReadPublicKey();
            this.ReadPrivateKey();
        }
Ejemplo n.º 4
0
        public static void AddStoneBankingJwt(this IServiceCollection services, StoneBankingSettings stoneBankingSettings)
        {
            if (services == null)
            {
                throw new ArgumentNullException("ServiceCollection cannot be null");
            }

            if (stoneBankingSettings == null)
            {
                throw new ArgumentNullException("StoneBankingSettings cannot be null.");
            }

            services.AddSingleton(provider => stoneBankingSettings);
            services.AddSingleton <IStoneBankingJwt, StoneBankingJwt>();
        }
Ejemplo n.º 5
0
        public static void AddStoneBankingJwt(this IServiceCollection services, Action <StoneBankingSettings> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException("ServiceCollection cannot be null");
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException("SetupAction cannot be null.");
            }

            var stoneBankingSettings = new StoneBankingSettings();

            setupAction(stoneBankingSettings);

            AddStoneBankingJwt(services, stoneBankingSettings);
        }