Esempio n. 1
0
        private void AddClaim(ReadOnlySpan <byte> utf8Name, JwtProperty value)
        {
            if (_jsonPayload == null)
            {
                _jsonPayload = new JwtObject();
            }

            JwtObject jwtObject;

            if (_jsonPayload.TryGetValue(utf8Name, out JwtProperty property) && property.Type == JwtTokenType.Object && !(property.Value is null))
            {
                jwtObject = (JwtObject)property.Value;
            }
            else
            {
                jwtObject = new JwtObject();
                _jsonPayload.Add(new JwtProperty(utf8Name, jwtObject));
            }

            jwtObject.Add(value);
        }
Esempio n. 2
0
        private JwtDescriptorBuilder AddClaim(ReadOnlySpan <byte> utf8Name, JwtArray value)
        {
            if (_jsonPayload == null)
            {
                _jsonPayload = new JwtObject();
            }

            if (_jsonPayload.TryGetValue(utf8Name, out var property))
            {
                if (property.Type != JwtTokenType.Array)
                {
                    ThrowHelper.ThrowJwtDescriptorException_ClaimMustBeOfType(utf8Name, JwtTokenType.Array);
                }

                ((JwtArray)property.Value !).Merge(value);
            }
            else
            {
                property = new JwtProperty(utf8Name, value);
                _jsonPayload.Add(property);
            }

            return(this);
        }
Esempio n. 3
0
 /// <summary>
 /// Adds a claim.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public void AddClaim(string name, JwtProperty value)
 => AddClaim(Utf8.GetBytes(name), value);
Esempio n. 4
0
 public void AddEvent(JwtProperty @event)
 {
     AddClaim(SetClaims.EventsUtf8, @event);
 }