Example #1
0
        /// <summary>
        /// Create a new <see cref="Consumer"/> with a callback URL and a X509 certificate.
        /// </summary>
        /// <param name="name">The name of the <see cref="Consumer"/> to create.</param>
        /// <param name="callback">The callback URL of the <see cref="Consumer"/>.</param>
        /// <param name="certificate">The X509 certificate for the user.</param>
        /// <returns>The created <see cref="Consumer"/>.</returns>
        /// <exception cref="ArgumentException">Thrown if a parameter is not valid.</exception>
        /// <exception cref="Glipho.OAuth.OAuthException">Thrown if an error occurs while executing the requested command.</exception>
        public Consumer Create(string name, Uri callback, X509Certificate2 certificate)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name does not have a value.", "name");
            }

            var secret = GenerateConsumerSecret(ConsumerSecretLength);
            var dataConsumer = new Database.Consumer
            {
                Callback = callback,
                Certificate = certificate,
                Name = name,
                Secret = secret,
                VerificationCodeFormat = (int)VerificationFormat,
                VerificationCodeLength = VerificationCodeLength,
            };
            var createdConsumer = this.consumers.Create(dataConsumer);
            return Consumer.FromDataConsumer(createdConsumer);
        }
Example #2
0
        /// <summary>
        /// Determines whether the specified <see cref="Consumer"/> is equal to the current <see cref="Consumer"/>.
        /// </summary>
        /// <param name="consumer">The <see cref="Consumer"/> to compare with the current <see cref="Consumer"/>.</param>
        /// <returns>
        /// true if the specified <see cref="Consumer"/> is equal to the current <see cref="Consumer"/>; otherwise false.
        /// </returns>
        public bool Equals(Consumer consumer)
        {
            if (consumer == null)
            {
                return false;
            }

            return this.Name == consumer.Name
                && this.Callback == consumer.Callback
                && this.Id == consumer.Id
                && this.Secret == consumer.Secret
                && this.VerificationCodeFormat == consumer.VerificationCodeFormat
                && this.VerificationCodeLength == consumer.VerificationCodeLength
                && (this.Certificate != null && consumer.Certificate != null && this.Certificate.Equals(consumer.Certificate));
        }