2using System.Collections.Generic;
4using System.Threading.Tasks;
21 private readonly
string petitionId;
22 private readonly Dictionary<string, object> properties;
23 private readonly Dictionary<string, object>[] attachments;
36 this.petitionId = PetitionId;
49 public string Id => this.
id.Id;
54 public string Key => this.petitionId;
69 public DateTime
Created => this.
id.Created;
74 public DateTime?
Updated => this.id.Updated == DateTime.MinValue ? (DateTime?)
null : this.
id.Updated;
79 public DateTime
From => this.
id.From;
84 public DateTime
To => this.
id.To;
99 public Dictionary<string, object>
Properties => this.properties;
104 public Dictionary<string, object>[]
Attachments => this.attachments;
123 if (this.properties.ContainsKey(
"FIRST") && this.properties.ContainsKey(
"LAST"))
125 StringBuilder sb =
null;
127 this.Append(ref sb,
"FIRST",
" ");
128 this.Append(ref sb,
"MIDDLE",
" ");
129 this.Append(ref sb,
"LAST",
" ");
131 return sb?.ToString() ??
"N/A";
136 if (
string.IsNullOrEmpty(s))
139 if (
string.IsNullOrEmpty(s))
142 int i = s.IndexOf(
'@');
146 string LocalPart = s.Substring(0, i);
148 if (Guid.TryParse(LocalPart, out _) && !(
this.id is
null))
150 string EMail = this.
id[
"EMAIL"];
151 if (!
string.IsNullOrEmpty(EMail))
154 string PhoneNr = this.
id[
"PHONE"];
155 if (!
string.IsNullOrEmpty(PhoneNr))
159 string Domain = s.Substring(i + 1);
176 StringBuilder sb =
null;
178 this.Append(ref sb,
"ADDR",
", ");
179 this.Append(ref sb,
"ADDR2",
", ");
180 this.Append(ref sb,
"AREA",
", ");
181 this.Append(ref sb,
"ZIP",
", ");
182 this.Append(ref sb,
"CITY",
", ");
183 this.Append(ref sb,
"REGION",
", ");
184 this.Append(ref sb,
"COUNTRY",
", ");
187 return sb.ToString();
189 this.Append(ref sb,
"ORGNAME",
", ");
190 this.Append(ref sb,
"ORGDEPT",
", ");
191 this.Append(ref sb,
"ORGADDR",
", ");
192 this.Append(ref sb,
"ORGADDR2",
", ");
193 this.Append(ref sb,
"ORGAREA",
", ");
194 this.Append(ref sb,
"ORGZIP",
", ");
195 this.Append(ref sb,
"ORGCITY",
", ");
196 this.Append(ref sb,
"ORGREGION",
", ");
197 this.Append(ref sb,
"ORGCOUNTRY",
", ");
199 return sb?.ToString() ??
"N/A";
210 if (this.properties.TryGetValue(
"JID", out
object Obj) && Obj is
string s)
217 private void Append(ref StringBuilder sb,
string Name,
string Delimiter)
219 if (this.properties.TryGetValue(Name, out
object Obj))
250 if (!(this.attachments is
null))
252 foreach (Dictionary<string, object>
Attachment in this.attachments)
254 if (
Attachment.TryGetValue(
"ContentType", out
object Obj) &&
255 Obj is
string ContentType &&
256 ContentType.StartsWith(
"image/") &&
257 Attachment.TryGetValue(
"BackEndUrl", out Obj) &&
258 Obj is
string BackEndUrl)
276 if (this.attachments is
null)
282 foreach (Dictionary<string, object>
Attachment in this.attachments)
284 if (
Attachment.TryGetValue(
"Url", out
object Obj) &&
286 string.Compare(s, Url,
true) == 0 &&
312 public object this[
string Key]
316 if (this.properties.TryGetValue(
Key, out
object Obj))
328 public Task<IEnumerable<KeyValuePair<string, object>>>
CreateClaims(
bool Encrypted)
330 int IssuedAt = (int)Math.Round(DateTime.UtcNow.Subtract(
JSON.
UnixEpoch).TotalSeconds);
331 int Expires = IssuedAt + 3600;
332 DateTime Now = DateTime.Now;
334 if (this.From > Now || this.To < Now || this.State !=
IdentityState.Approved)
335 return Task.FromResult<IEnumerable<KeyValuePair<string, object>>>(
null);
337 List<KeyValuePair<string, object>> Claims =
new List<KeyValuePair<string, object>>()
343 new KeyValuePair<string, object>(
JwtClaims.
Name,
this.UserName),
363 string BDay =
this[
"BDAY"]?.ToString() ??
string.Empty;
364 string BMonth =
this[
"BMONTH"]?.ToString() ??
string.Empty;
365 string BYear =
this[
"BYEAR"]?.ToString() ??
string.Empty;
367 if (
int.TryParse(BDay, out
int BDayNr) &&
int.TryParse(BMonth, out
int BMonthNr) &&
int.TryParse(BYear, out
int BYearNr) &&
368 BMonthNr >= 1 && BMonthNr <= 12 && BYearNr >= 1900 && BYearNr <= 2100 && BDayNr >= 1 && BDayNr <= DateTime.DaysInMonth(BYearNr, BMonthNr))
376 return Task.FromResult<IEnumerable<KeyValuePair<string, object>>>(Claims);
379 private static void AddClaim(List<KeyValuePair<string, object>> Claims,
string Key,
object Value)
381 if (!(Value is
null))
383 if (Value is
string s && s ==
"N/A")
386 Claims.Add(
new KeyValuePair<string, object>(
Key, Value));
Helps with common JSON-related tasks.
static readonly DateTime UnixEpoch
Unix Date and Time epoch, starting at 1970-01-01T00:00:00Z
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static bool IsDomain(string DomainOrHost, bool IncludeAlternativeDomains)
If a domain or host name represents the gateway.
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
Contains a reference to an attachment assigned to a legal object.
Represents a digital signature on a contract.
Represents a server signature on a contract.
Static class containing predefined JWT claim names.
const string Issuer
Issuer of the JWT
const string GivenName
Given name(s) or first name(s)
const string EMailVerified
True if the e-mail address has been verified; otherwise false
const string WebSite
Web page or blog URL
const string IssueTime
Time at which the JWT was issued; can be used to determine age of the JWT
const string Name
Full name
const string JwtId
Unique identifier; can be used to prevent the JWT from being replayed (allows a token to be used only...
const string Picture
Profile picture URL
const string EMail
Preferred e-mail address
const string BirthDate
Birthday
const string SubjectIdentifier
Subject Identifier
const string Nationalities
String array representing the End-User's nationalities.
const string PhoneNumber
Preferred telephone number
const string Gender
Gender
const string MiddleName
Middle name(s)
const string Subject
Subject of the JWT (the user)
const string PhoneNumberVerified
True if the phone number has been verified; otherwise false
const string ExpirationTime
Time after which the JWT expires
const string Address
Preferred postal address
const string FamilyName
Surname(s) or last name(s)
A factory that can create and validate JWT tokens.
string Create(params KeyValuePair< string, object >[] Claims)
Creates a new JWT token.
Corresponds to a privilege in the system.
Corresponds to a user in the system.
static void AppendValue(ref StringBuilder Output, object Value, string Delimiter)
Appends a value to a StringBuilder.
DateTime? Updated
When ID was updated
Dictionary< string, object > Properties
Properties encoded into the ID
string Key
Key used during login
string ClientPubKey
Client public key
string PasswordHash
Empty string (object does not use passwords.)
bool IsUserAttachment(string Url, out string AttachmentId)
Checks if an URL corresponds to an attachment in the legal identity of the user.
Task< IEnumerable< KeyValuePair< string, object > > > CreateClaims(bool Encrypted)
Creates a set of claims identifying the user.
Dictionary< string, object >[] Attachments
Attachments associated with ID.
string PasswordHashType
Empty string (object does not use passwords.)
QuickLoginUser(LegalIdentity ID, string PetitionId, Dictionary< string, object > Properties, Dictionary< string, object >[] Attachments)
Quick-Login user object.
Task< RequestOrigin > GetOrigin()
Origin of request.
string AvatarUrl
URL to avatar.
DateTime Created
When ID was created
string Provider
Provider of ID
DateTime To
To when ID is valid
DateTime From
From when ID is valid
bool HasPrivilege(string Privilege)
If user has a privilege.
string ClientKeyName
Algorithm used by client
async Task< string > CreateToken(JwtFactory Factory, bool Encrypted)
Creates a JWT Token referencing the user object.
bool HasClientPublicKey
If ID has a client public key
IdentityState State
Legal ID state.
LegalIdentity LegalId
Legal ID used to identify with the system.
string Id
Identifier of ID
string FullAddress
Full address of person
Tokens available in request.
A User that can participate in distributed operations, where the user is identified using a JWT token...
Interface for requestors that can act as an origin for distributed requests.
IdentityState
Lists recognized legal identity states.