public bool Check(bool throwException = true)
 {
     try
     {
         if (string.IsNullOrEmpty(Authority))
         {
             throw new ArgumentNullException("Authority");
         }
         if (string.IsNullOrEmpty(ClientId))
         {
             throw new ArgumentNullException("ClientId");
         }
         if (SigningMethod == SigningMethod.None && string.IsNullOrEmpty(ClientSecret))
         {
             throw new ArgumentNullException("ClientSecret");
         }
         if (SigningMethod == SigningMethod.X509EnterpriseSecurityKey && string.IsNullOrEmpty(CertificateThumbprint))
         {
             throw new ArgumentNullException("CertificateThumprint");
         }
         if (SigningMethod == SigningMethod.RsaSecurityKey && !RSAKeyGenerator.KeyExists())
         {
             throw new ArgumentNullException("No RSA key found");
         }
         if (string.IsNullOrEmpty(RedirectUri))
         {
             throw new ArgumentNullException("RedirectUri");
         }
         // Not true if all we want to do is call for a refresh token..
         //if (string.IsNullOrEmpty(Scope))
         //{
         //    throw new ArgumentNullException("Scope");
         //}
         //if (!Scope.Contains("openid"))
         //{
         //    throw new ArgumentException("Scope must include openid", nameof(Scope));
         //}
     }
     catch
     {
         if (throwException)
         {
             throw;
         }
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Runs a quick check to see it the options are correctly setup. Note that this is only a shallow check and the
        ///     options can still be invalid.
        /// </summary>
        /// <param name="throwException">Specifies if the check should throw an exception if the check fails or just return false.</param>
        /// <returns></returns>
        public bool Check(bool throwException = true)
        {
            try
            {
                if (string.IsNullOrEmpty(Authority))
                {
                    throw new NullReferenceException("Authority");
                }

                if (string.IsNullOrEmpty(ClientId))
                {
                    throw new NullReferenceException("ClientId");
                }

                if (SigningMethod == SigningMethod.None && string.IsNullOrEmpty(ClientSecret))
                {
                    throw new NullReferenceException("ClientSecret");
                }

                if (SigningMethod == SigningMethod.X509EnterpriseSecurityKey &&
                    string.IsNullOrEmpty(CertificateThumbprint))
                {
                    throw new NullReferenceException("CertificateThumprint");
                }

                if (SigningMethod == SigningMethod.RsaSecurityKey && !RSAKeyGenerator.KeyExists(ClientId))
                {
                    throw new NullReferenceException("No RSA key found");
                }

                if (string.IsNullOrEmpty(RedirectUri))
                {
                    throw new NullReferenceException("RedirectUri");
                }
            }
            catch
            {
                if (throwException)
                {
                    throw;
                }
                return(false);
            }

            return(true);
        }