Exemplo n.º 1
0
 /// <summary>
 /// Inspect the current context.
 /// </summary>
 /// <param name="phase">The current provider phase.</param>
 /// <param name="context">OAuth context</param>
 public void InspectContext(ProviderPhase phase, IOAuthContext context)
 {
     if (!_nonceStore.RecordNonceAndCheckIsUnique(context, context.Nonce))
     {
         throw Error.NonceHasAlreadyBeenUsed(context);
     }
 }
 public void InspectContext(ProviderPhase phase, IOAuthContext context)
 {
   if (!_consumerStore.IsConsumer(context))
   {
     throw Error.UnknownConsumerKey(context);
   }
 }
 public void InspectContext(ProviderPhase phase, IOAuthContext context)
 {
     if (!_consumerStore.IsConsumer(context))
     {
         throw Error.UnknownConsumerKey(context);
     }
 }
Exemplo n.º 4
0
 void ApplyInspectors(IOAuthContext context, ProviderPhase phase)
 {
     foreach (IContextInspector inspector in _inspectors)
     {
         inspector.InspectContext(phase, context);
     }
 }
    public void InspectContext(ProviderPhase phase, IOAuthContext context)
    {
      if (phase != ProviderPhase.CreateAccessToken) {
        return;
      }

      var authMode = context.XAuthMode;
      if (string.IsNullOrEmpty(authMode)) {
        throw Error.EmptyXAuthMode(context);
      }

      if (!_validateModeFunc(authMode)) {
        throw Error.InvalidXAuthMode(context);
      }

      var username = context.XAuthUsername;
      if (string.IsNullOrEmpty(username)) {
        throw Error.EmptyXAuthUsername(context);
      }

      var password = context.XAuthPassword;
      if (string.IsNullOrEmpty(password)) {
        throw Error.EmptyXAuthPassword(context);
      }

      if (!_authenticateFunc(username, password)) {
        throw Error.FailedXAuthAuthentication(context);
      }
    }
		public void InspectContext(ProviderPhase phase, IOAuthContext context)
		{
			if (!_nonceStore.RecordNonceAndCheckIsUnique(context, context.Nonce))
			{
				throw Error.NonceHasAlreadyBeenUsed(context);
			}
		}
Exemplo n.º 7
0
        protected virtual void InspectRequest(ProviderPhase phase, IOAuthContext context)
        {
            AssertContextDoesNotIncludeTokenSecret(context);

            AddStoredTokenSecretToContext(context, phase);

            ApplyInspectors(context, phase);
        }
    public virtual void InspectContext(ProviderPhase phase, IOAuthContext context)
    {
      SigningContext signingContext = CreateSignatureContextForConsumer(context);

      if (!_signer.ValidateSignature(context, signingContext))
      {
        throw Error.FailedToValidateSignature(context);
      }
    }
        public virtual void InspectContext(ProviderPhase phase, IOAuthContext context)
        {
            SigningContext signingContext = CreateSignatureContextForConsumer(context);

            if (!_signer.ValidateSignature(context, signingContext))
            {
                throw Error.FailedToValidateSignature(context);
            }
        }
        public void InspectContext(ProviderPhase phase, IOAuthContext context)
        {
            if (context.SignatureMethod == SignatureMethod.PlainText ||
                String.IsNullOrEmpty(context.BodyHash)) return;

            if (!context.BodyHash.EqualsInConstantTime(context.GenerateBodyHash()))
            {
                throw Error.FailedToValidateBodyHash(context);
            }
        }
Exemplo n.º 11
0
 public void InspectContext(ProviderPhase phase, IOAuthContext context)
 {
     if (phase == ProviderPhase.GrantRequestToken)
     {
         ValidateCallbackUrlIsPartOfRequest(context);
     }
     else if (phase == ProviderPhase.ExchangeRequestTokenForAccessToken)
     {
         ValidateVerifierMatchesStoredVerifier(context);
     }
 }
Exemplo n.º 12
0
		public void InspectContext(ProviderPhase phase, IOAuthContext context)
		{
			if (phase == ProviderPhase.GrantRequestToken)
			{
				ValidateCallbackUrlIsPartOfRequest(context);
			}
			else if (phase == ProviderPhase.ExchangeRequestTokenForAccessToken)
			{
				ValidateVerifierMatchesStoredVerifier(context);
			}
		}
Exemplo n.º 13
0
        void AddStoredTokenSecretToContext(IOAuthContext context, ProviderPhase phase)
        {
            if (phase == ProviderPhase.ExchangeRequestTokenForAccessToken)
            {
                string secret = _tokenStore.GetRequestTokenSecret(context);
                context.TokenSecret = secret;
            }

            else if (phase == ProviderPhase.AccessProtectedResourceRequest || phase == ProviderPhase.RenewAccessToken)
            {
                string secret = _tokenStore.GetAccessTokenSecret(context);

                context.TokenSecret = secret;
            }
        }
		public void InspectContext(ProviderPhase phase, IOAuthContext context)
		{
			if (context.SignatureMethod == SignatureMethod.PlainText ||
			    String.IsNullOrEmpty(context.BodyHash)) return;

			if (!string.IsNullOrEmpty(context.BodyHash)
			    && context.FormEncodedParameters.Count > 0)
			{
				throw Error.EncounteredUnexpectedBodyHashInFormEncodedRequest(context);
			}

			if (!context.BodyHash.EqualsInConstantTime(context.GenerateBodyHash()))
			{
				throw Error.FailedToValidateBodyHash(context);
			}
		}
        public void InspectContext(ProviderPhase phase, IOAuthContext context)
        {
            if (context.SignatureMethod == SignatureMethod.PlainText ||
                String.IsNullOrEmpty(context.BodyHash))
            {
                return;
            }

            if (!string.IsNullOrEmpty(context.BodyHash) &&
                context.FormEncodedParameters.Count > 0)
            {
                throw Error.EncounteredUnexpectedBodyHashInFormEncodedRequest(context);
            }

            if (!context.BodyHash.EqualsInConstantTime(context.GenerateBodyHash()))
            {
                throw Error.FailedToValidateBodyHash(context);
            }
        }
        public void InspectContext(ProviderPhase phase, IOAuthContext context)
        {
            DateTime timestamp = DateTimeUtility.FromEpoch(Convert.ToInt32(context.Timestamp));
            DateTime now       = _nowFunc();

            if (now.Subtract(_maxBeforeNow) > timestamp)
            {
                throw new OAuthException(context, OAuthProblems.TimestampRefused,
                                         string.Format(
                                             "The timestamp is to old, it must be at most {0} seconds before the servers current date and time",
                                             _maxBeforeNow.TotalSeconds));
            }
            if (now.Add(_maxAfterNow) < timestamp)
            {
                throw new OAuthException(context, OAuthProblems.TimestampRefused,
                                         string.Format(
                                             "The timestamp is to far in the future, if must be at most {0} seconds after the server current date and time",
                                             _maxAfterNow.TotalSeconds));
            }
        }
    public void InspectContext(ProviderPhase phase, IOAuthContext context)
    {
      DateTime timestamp = DateTimeUtility.FromEpoch(Convert.ToInt32(context.Timestamp));
      DateTime now = _nowFunc();

      if (now.Subtract(_maxBeforeNow) > timestamp)
      {
        throw new OAuthException(context, OAuthProblems.TimestampRefused,
                                 string.Format(
                                   "The timestamp is to old, it must be at most {0} seconds before the servers current date and time",
                                   _maxBeforeNow.TotalSeconds));
      }
      if (now.Add(_maxAfterNow) < timestamp)
      {
        throw new OAuthException(context, OAuthProblems.TimestampRefused,
                                 string.Format(
                                   "The timestamp is to far in the future, if must be at most {0} seconds after the server current date and time",
                                   _maxAfterNow.TotalSeconds));
      }
    }
Exemplo n.º 18
0
        public void InspectContext(ProviderPhase phase, IOAuthContext context)
        {
            if (phase != ProviderPhase.CreateAccessToken)
            {
                return;
            }

            var authMode = context.XAuthMode;

            if (string.IsNullOrEmpty(authMode))
            {
                throw Error.EmptyXAuthMode(context);
            }

            if (!_validateModeFunc(authMode))
            {
                throw Error.InvalidXAuthMode(context);
            }

            var username = context.XAuthUsername;

            if (string.IsNullOrEmpty(username))
            {
                throw Error.EmptyXAuthUsername(context);
            }

            var password = context.XAuthPassword;

            if (string.IsNullOrEmpty(password))
            {
                throw Error.EmptyXAuthPassword(context);
            }

            if (!_authenticateFunc(username, password))
            {
                throw Error.FailedXAuthAuthentication(context);
            }
        }
Exemplo n.º 19
0
		void AddStoredTokenSecretToContext(IOAuthContext context, ProviderPhase phase)
		{
			if (phase == ProviderPhase.ExchangeRequestTokenForAccessToken)
			{
				string secret = _tokenStore.GetRequestTokenSecret(context);
				context.TokenSecret = secret;
			}

			else if (phase == ProviderPhase.AccessProtectedResourceRequest || phase == ProviderPhase.RenewAccessToken)
			{
				string secret = _tokenStore.GetAccessTokenSecret(context);

				context.TokenSecret = secret;
			}
		}
Exemplo n.º 20
0
		void ApplyInspectors(IOAuthContext context, ProviderPhase phase)
		{
			foreach (IContextInspector inspector in _inspectors)
			{
				inspector.InspectContext(phase, context);
			}
		}
Exemplo n.º 21
0
		protected virtual void InspectRequest(ProviderPhase phase, IOAuthContext context)
		{
			AssertContextDoesNotIncludeTokenSecret(context);

			AddStoredTokenSecretToContext(context, phase);

			ApplyInspectors(context, phase);
		}