Esempio n. 1
0
 /// <summary>VerifyJwtBearerTokenFlowAssertion</summary>
 /// <param name="jwtAssertion">string</param>
 /// <param name="iss">client_id</param>
 /// <param name="aud">Token2 EndPointのuri</param>
 /// <param name="scopes">scopes</param>
 /// <param name="jobj">JObject</param>
 /// <param name="jwkPublicKey">RS256用のJWK公開鍵</param>
 /// <returns>検証結果</returns>
 public static bool VerifyJwtBearerTokenFlowAssertionJWK(string jwtAssertion,
                                                         out string iss, out string aud, out string scopes, out JObject jobj, string jwkPublicKey)
 {
     return(JwtAssertion.VerifyJwtBearerTokenFlowAssertion(
                jwtAssertion, out iss, out aud, out scopes, out jobj,
                RsaPublicKeyConverter.JwkToParam(jwkPublicKey)));
 }
Esempio n. 2
0
        /// <summary>Create</summary>
        /// <param name="iss">client_id</param>
        /// <param name="aud">Token2 EndPointのuri</param>
        /// <param name="forExp">DateTimeOffset</param>
        /// <param name="scopes">scopes</param>
        /// <param name="jwkPrivateKey">RS256用のJWK秘密鍵</param>
        /// <returns>JwtAssertion</returns>
        public static string Create(
            string iss, string aud, TimeSpan forExp, string scopes, string jwkPrivateKey)
        {
            JObject temp = JsonConvert.DeserializeObject <JObject>(jwkPrivateKey);

            if (temp.ContainsKey("kty"))
            {
                if (((string)temp["kty"]).ToUpper() == "RSA")
                {
                    RsaPrivateKeyConverter rpkc = new RsaPrivateKeyConverter(JWS_RSA.RS._256);
                    return(JwtAssertion.CreateByRsa(iss, aud, forExp, scopes,
                                                    rpkc.JwkToParam(jwkPrivateKey)));
                }
#if NET45 || NET46
#else
                else if (((string)temp["kty"]).ToUpper() == "EC")
                {
                    EccPrivateKeyConverter epkc = new EccPrivateKeyConverter(JWS_ECDSA.ES._256);
                    return(JwtAssertion.CreateByECDsa(iss, aud, forExp, scopes,
                                                      epkc.JwkToParam(jwkPrivateKey)));
                }
#endif
            }

            return("");
        }
Esempio n. 3
0
        /// <summary>Verify</summary>
        /// <param name="jwtAssertion">string</param>
        /// <param name="iss">client_id</param>
        /// <param name="aud">Token2 EndPointのuri</param>
        /// <param name="scopes">scopes</param>
        /// <param name="jobj">JObject</param>
        /// <param name="jwkPublicKey">RS256用のJWK公開鍵</param>
        /// <returns>検証結果</returns>
        public static bool Verify(string jwtAssertion,
                                  out string iss, out string aud, out string scopes, out JObject jobj, string jwkPublicKey)
        {
            iss    = "";
            aud    = "";
            scopes = "";
            jobj   = null;

            JObject temp = JsonConvert.DeserializeObject <JObject>(jwkPublicKey);

            if (temp.ContainsKey("kty"))
            {
                if (((string)temp["kty"]).ToUpper() == "RSA")
                {
                    RsaPublicKeyConverter rpkc = new RsaPublicKeyConverter();
                    return(JwtAssertion.VerifyByRsa(jwtAssertion,
                                                    out iss, out aud, out scopes, out jobj,
                                                    rpkc.JwkToParam(jwkPublicKey)));
                }
#if NET45 || NET46
#else
                else if (((string)temp["kty"]).ToUpper() == "EC")
                {
                    EccPublicKeyConverter epkc = new EccPublicKeyConverter();
                    return(JwtAssertion.VerifyByECDsa(jwtAssertion,
                                                      out iss, out aud, out scopes, out jobj,
                                                      epkc.JwkToParam(jwkPublicKey)));
                }
#endif
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>Create</summary>
        /// <param name="iss">client_id</param>
        /// <param name="aud">Token2 EndPointのuri</param>
        /// <param name="forExp">DateTimeOffset</param>
        /// <param name="scopes">scopes</param>
        /// <param name="jwkPrivateKey">RS256用のJWK秘密鍵</param>
        /// <returns>JwtAssertion</returns>
        public static string Create(
            string iss, string aud, TimeSpan forExp, string scopes, string jwkPrivateKey)
        {
            RsaPrivateKeyConverter rpkc = new RsaPrivateKeyConverter(JWS_RSA.RS._256);

            return(JwtAssertion.Create(iss, aud, forExp, scopes,
                                       rpkc.JwkToParam(jwkPrivateKey)));
        }
Esempio n. 5
0
        /// <summary>Verify</summary>
        /// <param name="jwtAssertion">string</param>
        /// <param name="iss">client_id</param>
        /// <param name="aud">Token2 EndPointのuri</param>
        /// <param name="scopes">scopes</param>
        /// <param name="jobj">JObject</param>
        /// <param name="jwkPublicKey">RS256用のJWK公開鍵</param>
        /// <returns>検証結果</returns>
        public static bool Verify(string jwtAssertion,
                                  out string iss, out string aud, out string scopes, out JObject jobj, string jwkPublicKey)
        {
            RsaPublicKeyConverter rpkc = new RsaPublicKeyConverter();

            return(JwtAssertion.Verify(jwtAssertion,
                                       out iss, out aud, out scopes, out jobj,
                                       rpkc.JwkToParam(jwkPublicKey)));
        }
Esempio n. 6
0
 /// <summary>CreateJwtBearerTokenFlowAssertionJWK</summary>
 /// <param name="iss">client_id</param>
 /// <param name="aud">Token2 EndPointのuri</param>
 /// <param name="forExp">DateTimeOffset</param>
 /// <param name="scopes">scopes</param>
 /// <param name="jwkPrivateKey">RS256用のJWK秘密鍵</param>
 /// <returns>JwtAssertion</returns>
 public static string CreateJwtBearerTokenFlowAssertionJWK(
     string iss, string aud, TimeSpan forExp, string scopes, string jwkPrivateKey)
 {
     return(JwtAssertion.CreateJwtBearerTokenFlowAssertion(iss, aud, forExp, scopes,
                                                           PrivateKeyConverter.JwkToRsaParam(jwkPrivateKey)));
 }