Example #1
0
        public void GetJsonWebKey_DecodesValidJson()
        {
            var webKey = @"{'keys':[{'kid':'legacy-token-key','alg':'SHA256withRSA','value':'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk+7xH35bYBppsn54cBW+\nFlrveTe+3L4xl7ix13XK8eBcCmNOyBhNzhks6toDiRjrgw5QW76cFirVRFIVQkiZ\nsUwDyGOax3q8NOJyBFXiplIUScrx8aI0jkY/Yd6ixAc5yBSBfXThy4EF9T0xCyt4\nxWLYNXMRwe88Y+i+MEoLNXWRbhjJm76LN7rsdIxALbS0vJNWUDALWjtE6FeYX6uU\nL9msAzlCQkdnSvwMmr8Ij2O3IVMxHDJXOZinFqt9zVfXwO11o7ZmiskZnRz1/V0f\nvbUQAadkcDEUt1gk9cbrAhiipg8VWDMsC7VUXuekJZjme5f8oWTwpsgP6cTUzwSS\n6wIDAQAB\n-----END PUBLIC KEY-----','kty':'RSA','use':'sig','n':'AJPu8R9+W2AaabJ+eHAVvhZa73k3vty+MZe4sdd1yvHgXApjTsgYTc4ZLOraA4kY64MOUFu+nBYq1URSFUJImbFMA8hjmsd6vDTicgRV4qZSFEnK8fGiNI5GP2HeosQHOcgUgX104cuBBfU9MQsreMVi2DVzEcHvPGPovjBKCzV1kW4YyZu+ize67HSMQC20tLyTVlAwC1o7ROhXmF+rlC/ZrAM5QkJHZ0r8DJq/CI9jtyFTMRwyVzmYpxarfc1X18DtdaO2ZorJGZ0c9f1dH721EAGnZHAxFLdYJPXG6wIYoqYPFVgzLAu1VF7npCWY5nuX/KFk8KbID+nE1M8Ekus=','e':'AQAB'}]}";
            CloudFoundryTokenKeyResolver resolver = new CloudFoundryTokenKeyResolver(new CloudFoundryOptions());
            var webKeySet = resolver.GetJsonWebKeySet(webKey);

            Assert.NotNull(webKeySet);
            Assert.NotNull(webKeySet.Keys);
            Assert.Equal(1, webKeySet.Keys.Count);
        }
        public void GetJsonWebKeySet_Parses_JsonString()
        {
            // arrange
            var tkr = new CloudFoundryTokenKeyResolver(happyPathOptions);

            // act
            var expected = tkr.GetJsonWebKeySet(tokenKeysJsonString);

            // assert
            Assert.Contains(expected.Keys, key => key.Kid == "key-1");
            var tokenKey = expected.Keys.First();

            Assert.Equal("RS256", tokenKey.Alg);
            Assert.Equal("sig", tokenKey.Use);
            Assert.Equal("AQAB", tokenKey.E);
        }