Exemplo n.º 1
0
        public static void DecodeAuthenticationToken()
        {
            // arrange
            var token         = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL3NhbmRib3gtYWNjb3VudHMub3BlbmJhbmsuc3RvbmUuY29tLmJyL2F1dGgvcmVhbG1zL3N0b25lX2JhbmsiLCJjbGllbnRJZCI6IjEyMzEyMzEyMyIsImV4cCI6MTU4ODk0OTE1MiwiaWF0IjoxNTg4OTQ4MjUyLCJuYmYiOjE1ODg5NDgyNTIsImp0aSI6IjE1ODg5NDgyNTIiLCJyZWFsbSI6InN0b25lX2JhbmsiLCJzdWIiOiIxMjMxMjMxMjMifQ.0rRZyf3f6nETHOfn-DBR2fa38qJ09fZsxt-bZcT7XuNEENXx8ji-IddNBCDqltCuR9t8Jwc_e0qSOH3r3OHGX3XsafftOvhiByZV_iL74IpljVKPDBAEMlEEMsO4irBO6POKEUW65bD3TMSt-sdlC11r28Vi-zdI0F3V8ERGlXzfdwxbVL1WzTaDi54WeGHuhoHOI_gNEJ4LJkVCracn1RtM8AgSmPT8yIHt-IovyXRDeogSgifzxSwskRThRGj4GncTG93xbAL1-_G9XZjp6VTCCr1Ujky_QTrkWyg59JVUPLnFCxNRwW1OXJyQqf2yF8F5mE7CSBy2prVCh-J50YHdjRbXeIm0h3MGKnkM0kRpuv4U-dmauyooi6qGE52oWgZeR0mqpiDK81_01zEim6xLu_WXQs1Sf1Dq13YUjymI24SjbugAFpMgaBsclpAfwpbcLeTqYlO8Xnyv_q6lCziBeRUUPRcMMf6d_epxZe-h781lGundLmDmYn_purXfOodTe9fey1GZw2Yfn1ce0E4kPP-joTZkhoolx34I-G2kvGnRMNbtX9r99U4XGUOSnfv1gnVRcfrOK3g-VBJJB_5NARWa0SdNu7VF4rPL-iubjq_WRUUUzxTOF_Ed6-2Py9nRiZUpzW--CPXkHochor_ArIt6xlfRLN10Ys0khEA";
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByFile", null);
            var services      = new ServiceCollection();

            services.AddStoneBankingJwt(configuration);
            var jwtSign = services.BuildServiceProvider().GetService <IStoneBankingJwt>();

            // act
            var decodedToken = jwtSign.DecodeToken(token);

            // assert
            var aud      = decodedToken["aud"].ToString();
            var clientId = decodedToken["clientId"].ToString();
            var exp      = int.Parse(decodedToken["exp"].ToString());
            var iat      = int.Parse(decodedToken["iat"].ToString());
            var nbf      = int.Parse(decodedToken["nbf"].ToString());
            var jti      = decodedToken["jti"].ToString();
            var realm    = decodedToken["realm"].ToString();
            var sub      = decodedToken["sub"].ToString();

            Assert.Equal(aud, "https://sandbox-accounts.openbank.stone.com.br/auth/realms/stone_bank");
            Assert.Equal(clientId, "123123123");
            Assert.Equal(exp, 1588949152);
            Assert.Equal(iat, 1588948252);
            Assert.Equal(nbf, 1588948252);
            Assert.Equal(jti, "1588948252");
            Assert.Equal(realm, "stone_bank");
            Assert.Equal(sub, "123123123");
        }
Exemplo n.º 2
0
        public static void CreateAuthenticationToken()
        {
            // arrange
            var now_timestamp = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByFile", null);
            var services      = new ServiceCollection();

            services.AddStoneBankingJwt(configuration);
            var jwtSign = services.BuildServiceProvider().GetService <IStoneBankingJwt>();

            // act
            var token        = jwtSign.CreateAuthenticationToken();
            var decodedToken = jwtSign.DecodeToken(token);

            // assert
            var aud      = decodedToken["aud"].ToString();
            var clientId = decodedToken["clientId"].ToString();
            var exp      = int.Parse(decodedToken["exp"].ToString());
            var iat      = int.Parse(decodedToken["iat"].ToString());
            var nbf      = int.Parse(decodedToken["nbf"].ToString());
            var jti      = int.Parse(decodedToken["jti"].ToString());
            var realm    = decodedToken["realm"].ToString();
            var sub      = decodedToken["sub"].ToString();

            Assert.Equal(aud, "https://sandbox-accounts.openbank.stone.com.br/auth/realms/stone_bank");
            Assert.Equal(clientId, "123123123");
            Assert.True(exp >= now_timestamp + 900 && exp <= now_timestamp + 100 + 900);
            Assert.True(iat >= now_timestamp && iat <= now_timestamp + 100);
            Assert.True(nbf >= now_timestamp && nbf <= now_timestamp + 100);
            Assert.True(jti >= now_timestamp && nbf <= now_timestamp + 100);
            Assert.Equal(realm, "stone_bank");
            Assert.Equal(sub, "123123123");
        }
Exemplo n.º 3
0
        public static void LoadConfig_AppSettingsWithRsaString()
        {
            // arrange
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByString", null);
            var services      = new ServiceCollection();
            var 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/H8ly5eTHJB91NBcZZiy8nUGMbybV8SJH4FmqnFfIIMJODQao\n6XhbkQ0IFkqWmWR4gyLaIKQ2QIKW/uzB5ClLTLq6Pkc0pkP9zhmrBKw5ejJRzyIR\nAksodp/lXsyBMOhw2cAK30SjYeAWKH0BmTfVd2GzlXHVfGLqk5wWZl3lzoUCAwEA\nAQKCAgA2woV4HyZpNaQhSYmuy7CIJSQwbcqB61djxUF3mFy+fHhX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K30SjYeAWKH0BmTfV\nd2GzlXHVfGLqk5wWZl3lzoUCAwEAAQ==\n-----END PUBLIC KEY-----\n";

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

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

            // assert
            Assert.Equal(settings.ClientId, "321321321");
            Assert.Equal(settings.ConsentExpiresInSeconds, 600);
            Assert.Equal(settings.AuthenticationExpiresInSeconds, 1800);
            Assert.Equal(settings.Environment, StoneBankingEnvironment.Production);
            Assert.Equal(settings.ConsentDefaultRedirectUrl, "https://mysite.com/stonebanking/success2");
            Assert.Equal(settings.PublicKey, publicKey);
            Assert.Equal(settings.PrivateKey, privateKey);

            var jwtSignObj = ((StoneBankingJwt)jwtSign);

            Assert.Equal(jwtSignObj.PublicKey, publicKey);
            Assert.Equal(jwtSignObj.PrivateKey, privateKey);
        }
Exemplo n.º 4
0
        public static void LoadConfig_AppSettingsWithRsaFile()
        {
            // arrange
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByFile", null);
            var services      = new ServiceCollection();

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

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

            // assert
            Assert.Equal(settings.ClientId, "123123123");
            Assert.Equal(settings.ConsentExpiresInSeconds, 300);
            Assert.Equal(settings.AuthenticationExpiresInSeconds, 900);
            Assert.Equal(settings.Environment, StoneBankingEnvironment.Sandbox);
            Assert.Equal(settings.ConsentDefaultRedirectUrl, "https://mysite.com/stonebanking/success");
            Assert.Equal(settings.PublicKey, "rsa-publickey-file.pub");
            Assert.Equal(settings.PrivateKey, "rsa-privatekey-file.pem");

            var jwtSignObj = ((StoneBankingJwt)jwtSign);

            Assert.Equal(jwtSignObj.PublicKey, "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA+V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1i6PA4pDmWjJ\nM+T+8yHeZpaGttsQKSVAMlSGjGr/mSO2bw3CFUzeSdYf+mKuE6aHLUtLhu0cuEGo\nigGD0wKCAQEApzt1EfEvW1UaWedE2QR6gqHglEG/1DpKQjNQm0cwjgS7Di/uBi8/\nhRizS/p8c0ophfptJV/Vvx3nUa6yS+awnPr9EIfmAtJisjPCT5NszsxaLMuk5ca2\nItJ2aGUrmS0w8hoprgM5ZC/1SeIyK/EHPS+uEgHaP6bE3AA7tP2wWXs9J6JokvKL\ni5Gv45XfephwWEKPIIS61l8nQVgiTD/vTGZ4ErAfMo2k2d/7e3lgzlFhiQOBG7iL\nxxUXUAXFijHxbGyEAsonMFKImt2IndtES5QOiX/He0z1O87S77hHUNimvxWJ89ok\ng3hopFPqz04aN21Lh1T/Ebj/+IcT9yqyWQKCAQAhldW1y3fPqDVD9O6VNV0vuW3C\nwW6LNN+/neqqKMJV8pr2L2OTK/DM4sH5rRPNH0o1gjv+tHFrH8Lbz+6Y6QMxOpjC\nhcIh5RV56ILd+EN7midEsYGrOBXnU1s/0HcP+F3cXDUi0pSHptCt+GkST1x51hGD\nN7BXx20UbtIVgg+ceqUvz+hn7EadB1x1OudlzyXkYUSYjj26CJltQenZyXHXFMRQ\n6YaCo2w6fc29ogw1h96E9klirwkEbG7tQ6bmpLrMDR42uhLDgKFE6ZyW/M+TmG8d\nFD3iSt4jXSc6VQPa0SFbbcBjscHYisKi9CrmpxdQ8edLF89t3KsL+yH1eTSK\n-----END RSA PRIVATE KEY-----\n");
        }
Exemplo n.º 5
0
        public static void CreateConsentUrl_WithMetadata()
        {
            // arrange
            var now_timestamp = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByFile", null);
            var services      = new ServiceCollection();

            services.AddStoneBankingJwt(configuration);
            var jwtSign = services.BuildServiceProvider().GetService <IStoneBankingJwt>();

            // act
            var metadata = new Dictionary <string, string>
            {
                { "user_id", "user_123" },
                { "other_data", "123123" }
            };
            var url          = jwtSign.CreateConsentUrl(metadata);
            var query        = ParseQueryString(url.Split("?").LastOrDefault());
            var decodedToken = jwtSign.DecodeToken(query["jwt"]);

            // assert
            Assert.Equal(query.Count, 3);
            Assert.Equal(query["type"], "consent");
            Assert.Equal(query["client_id"], "123123123");
            Assert.NotNull(query["jwt"]);
            Assert.Equal(url.Split("?").FirstOrDefault(), "https://sandbox-accounts.openbank.stone.com.br/#/consent");

            var aud             = decodedToken["aud"].ToString();
            var clientId        = decodedToken["client_id"].ToString();
            var iss             = decodedToken["iss"].ToString();
            var exp             = int.Parse(decodedToken["exp"].ToString());
            var iat             = int.Parse(decodedToken["iat"].ToString());
            var nbf             = int.Parse(decodedToken["nbf"].ToString());
            var jti             = int.Parse(decodedToken["jti"].ToString());
            var redirect_uri    = decodedToken["redirect_uri"].ToString();
            var sessionMetadata = (Dictionary <string, object>)decodedToken["session_metadata"];

            Assert.Equal(aud, "*****@*****.**");
            Assert.Equal(clientId, "123123123");
            Assert.Equal(iss, "123123123");
            Assert.True(exp >= now_timestamp + 300 && exp <= now_timestamp + 100 + 300);
            Assert.True(iat >= now_timestamp && iat <= now_timestamp + 100);
            Assert.True(nbf >= now_timestamp && nbf <= now_timestamp + 100);
            Assert.True(jti >= now_timestamp && nbf <= now_timestamp + 100);
            Assert.Equal(redirect_uri, "https://mysite.com/stonebanking/success");
            Assert.Equal(sessionMetadata["user_id"], "user_123");
            Assert.Equal(sessionMetadata["other_data"], "123123");
            Assert.Equal(sessionMetadata.Count, 2);
        }
Exemplo n.º 6
0
        public static void DecodeConsentToken()
        {
            // arrange
            var token         = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiY29uc2VudCIsImF1ZCI6ImFjY291bnRzLWh1YmlkQG9wZW5iYW5rLnN0b25lLmNvbS5iciIsImNsaWVudF9pZCI6IjEyMzEyMzEyMyIsImlzcyI6IjEyMzEyMzEyMyIsImV4cCI6MTU4ODk1NTIzMywiaWF0IjoxNTg4OTU0OTMzLCJuYmYiOjE1ODg5NTQ5MzMsImp0aSI6IjE1ODg5NTQ5MzMiLCJyZWRpcmVjdF91cmkiOiJodHRwczovL215c2l0ZS5jb20vc3RvbmViYW5raW5nL3N1Y2Nlc3MiLCJzZXNzaW9uX21ldGFkYXRhIjp7InVzZXJfaWQiOiJ1c2VyXzEyMyIsIm90aGVyX2RhdGEiOiIxMjMxMjMifX0.2lAGMIGD3yOuIoAY7k-Fs3X2JAYb0VgyCkxgUPaJk6m7xJH0AH0NZODpVNnK-tUoI_CS17y_fAgrNRgFQ-lHmK3UptFupvmlRs-TBjdDyIsWos5aZFCYio4bizkTE2rZbOqwk5_ou6-nsdhxKJy8-yEeOuHA9yImzknqcSaLhLBI7r6wJ_O8RLd4s3KpE7vsbiAOoojF3JTZzzKpbRmz2iGro1-hVmCb36m_I9X_qc2H3G8SEEdMttBqT9i7BfChLt7hGD1D7l5TZtc5UxajgM6lCXCinUepKxN9Q0BKgchdyEyygZyKBf4-awnF-ez34YX2dBMINmFQ_6cewEAGFEi6S2tj8coap4Jz9Orv1NMmrXVMvYqNRKfCPsXAFU8FolPAvGjrc3uoxFrBT9D1HvV8qVYzAFWjp-dio8LNsOdeGxPIua6cTY82P3U2A6WMiXvbjsCNRQEsMEQUmN-bLaGRFdpxTUT9b0gc0fOpzgHXzgP1qsnPwNqzNfMl-I0wpKIyzEzxQopbA-EsrPrnl_RPASMsN760jIiCcTz-zNdtFDTd2Jm4GwuErpyvhjVoFfxhzirH3zKghTiI7AWT7pPF-EnWNUfZvMtQgUo2l-aLVtxMg1Bcyuf3Hmwmij9_N1vdl4789pDRri3bFw0nFTHVwr_IHY2aAXtvFeirySI";
            var configuration = ConfigurationHelpers.LoadConfigurations("RsaByFile", null);
            var services      = new ServiceCollection();

            services.AddStoneBankingJwt(configuration);
            var jwtSign = services.BuildServiceProvider().GetService <IStoneBankingJwt>();

            // act
            var decodedToken = jwtSign.DecodeToken(token);

            // assert
            var aud             = decodedToken["aud"].ToString();
            var clientId        = decodedToken["client_id"].ToString();
            var iss             = decodedToken["iss"].ToString();
            var exp             = int.Parse(decodedToken["exp"].ToString());
            var iat             = int.Parse(decodedToken["iat"].ToString());
            var nbf             = int.Parse(decodedToken["nbf"].ToString());
            var jti             = int.Parse(decodedToken["jti"].ToString());
            var redirect_uri    = decodedToken["redirect_uri"].ToString();
            var sessionMetadata = (Dictionary <string, object>)decodedToken["session_metadata"];

            Assert.Equal(aud, "*****@*****.**");
            Assert.Equal(clientId, "123123123");
            Assert.Equal(iss, "123123123");
            Assert.Equal(exp, 1588955233);
            Assert.Equal(iat, 1588954933);
            Assert.Equal(nbf, 1588954933);
            Assert.Equal(jti, 1588954933);
            Assert.Equal(redirect_uri, "https://mysite.com/stonebanking/success");
            Assert.Equal(sessionMetadata["user_id"], "user_123");
            Assert.Equal(sessionMetadata["other_data"], "123123");
            Assert.Equal(sessionMetadata.Count, 2);
        }