/// <inheritdoc />
 public ValidatedRegExExtractor(RegexClaimExtractionConfig.ExtractValueByRegexAsync func, Regex regex, string claim, ClaimLocation location)
 {
     _extract      = func;
     _regex        = regex;
     _claimName    = claim;
     ClaimLocation = location;
 }
 /// <inheritdoc />
 internal ValidJsonPathClaimExtractionConfig(string path, JsonPathClaimExtractionConfig.ExtractValueByJsonPathAsync jsonPathExtraction, string claimName, ClaimLocation location)
 {
     _path         = path;
     _extract      = jsonPathExtraction;
     _claimName    = claimName;
     ClaimLocation = location;
 }
Example #3
0
 /// <inheritdoc />
 internal ValidKeyValueClaimExtractionConfig(KeyValueClaimExtractionConfig.KeyValueExtractionAsync func, string key, ClaimLocation location, string claimName)
 {
     _extract      = func;
     _keyName      = key;
     ClaimLocation = location;
     _claimName    = claimName;
 }
Example #4
0
 /// <inheritdoc />
 internal ValidRegexClaimExtractionConfig(RegexClaimExtractionConfig.ExtractValueByRegexAsync func, Regex regex, string claim, ClaimLocation location)
 {
     _extract      = func;
     _regex        = regex;
     _claimName    = claim;
     ClaimLocation = location;
 }
        private static string GetContent(ClaimLocation location, ExtractionType extType, HttpRequest req, RouteValueDictionary routeValues, string requestBodyString = "")
        {
            switch (location)
            {
            case ClaimLocation.Body:
            {
                if (!string.IsNullOrEmpty(requestBodyString))
                {
                    return(requestBodyString);
                }
                var bodyMemStream = new MemoryStream();
                if (req.Body.CanSeek)
                {
                    req.Body.Position = 0;
                }
                req.Body.CopyTo(bodyMemStream);
                var stringBody = System.Text.Encoding.UTF8.GetString(bodyMemStream.ToArray());
                return(stringBody);
            }

            case ClaimLocation.Headers:
            {
                return(extType == ExtractionType.KeyValue ? JsonConvert.SerializeObject(HeaderDictToKvp(req.Headers, req.Headers)) : string.Empty);
            }

            case ClaimLocation.Uri:
            {
                if (extType == ExtractionType.KeyValue)
                {
                    return(routeValues == null ? "" : JsonConvert.SerializeObject(RouteValueDictionaryToKvp(routeValues)));
                }
                if (extType == ExtractionType.RegEx)
                {
                    return(req.Path);
                }
                break;
            }

            case ClaimLocation.QueryParameters:
            {
                switch (extType)
                {
                case ExtractionType.KeyValue:
                    return(JsonConvert.SerializeObject(QueryCollectionToKvp(req.Query)));

                case ExtractionType.RegEx:
                    return(req.QueryString.ToString());
                }
                break;
            }

            default:
                return(string.Empty);
            }
            return(string.Empty);
        }
 /// <summary>
 /// creates a new <see cref="RegexClaimExtractionConfig"/>
 /// </summary>
 /// <param name="claimName">name of claim</param>
 /// <param name="location"><see cref="ClaimLocation"/> location of the claim</param>
 public RegexClaimExtractionConfig(string claimName, ClaimLocation location) : base(claimName)
 {
     if (!(location == ClaimLocation.Uri || location == ClaimLocation.Body))
     {
         throw new InvalidEnumArgumentException(
                   $"{nameof(location)} must either be {nameof(ClaimLocation.Uri)} or {nameof(ClaimLocation.Body)}");
     }
     ClaimName      = claimName;
     Location       = location;
     ExtractionType = ExtractionType.RegEx;
 }
 /// <summary>
 /// creates a new <see cref="KeyValueClaimExtractionConfig"/>
 /// </summary>
 /// <param name="claimName">name of the claim</param>
 /// <param name="location"><see cref="ClaimLocation"/> location of the claim</param>
 public KeyValueClaimExtractionConfig(string claimName, ClaimLocation location) : base(claimName)
 {
     ClaimName      = claimName;
     Location       = location;
     ExtractionType = ExtractionType.KeyValue;
 }
 /// <inheritdoc />
 public ValidTypeClaimExtractionConfig(TypeClaimExtractionConfig <T> .ExtractClaimForTypeAsync func, string claim, ClaimLocation location)
 {
     _typeExtraction = func;
     _claimName      = claim;
     ClaimLocation   = location;
 }