4using System.Threading.Tasks;
26 private readonly
string petitionId;
27 private readonly Dictionary<string, object> properties;
28 private readonly Dictionary<string, object>[] attachments;
41 this.petitionId = PetitionId;
59 public string Id => this.
id.Id;
64 public string Key => this.petitionId;
79 public DateTime
Created => this.
id.Created;
84 public DateTime?
Updated => this.id.Updated == DateTime.MinValue ? (DateTime?)
null : this.
id.Updated;
89 public DateTime
From => this.
id.From;
94 public DateTime
To => this.
id.To;
109 public Dictionary<string, object>
Properties => this.properties;
114 public Dictionary<string, object>[]
Attachments => this.attachments;
134 if (
string.IsNullOrEmpty(s))
137 int i = s.IndexOf(
'@');
153 return string.IsNullOrEmpty(s) ? this.id.Id : s;
167 StringBuilder sb =
null;
173 return sb?.ToString() ??
"N/A";
176 return FullName?.ToString() ??
"N/A";
180 if (
string.IsNullOrEmpty(s))
183 if (
string.IsNullOrEmpty(s))
186 int i = s.IndexOf(
'@');
190 string LocalPart = s[..i];
192 if (Guid.TryParse(LocalPart, out
_) && !(
this.id is
null))
195 if (!
string.IsNullOrEmpty(EMail))
199 if (!
string.IsNullOrEmpty(PhoneNr))
203 string Domain = s[(i + 1)..];
220 StringBuilder sb =
null;
231 return sb.ToString();
243 return sb?.ToString() ??
"N/A";
261 private void Append(ref StringBuilder sb,
string Name,
string Delimiter)
263 if (this.properties.TryGetValue(Name, out
object Obj))
294 if (!(this.attachments is
null))
296 foreach (Dictionary<string, object>
Attachment in this.attachments)
298 if (
Attachment.TryGetValue(
"ContentType", out
object Obj) &&
299 Obj is
string ContentType &&
300 ContentType.StartsWith(
"image/") &&
301 Attachment.TryGetValue(
"BackEndUrl", out Obj) &&
302 Obj is
string BackEndUrl)
320 if (this.attachments is
null)
326 foreach (Dictionary<string, object>
Attachment in this.attachments)
328 if (
Attachment.TryGetValue(
"Url", out
object Obj) &&
330 string.Compare(s, Url,
true) == 0 &&
348 return Task.FromResult(
new RequestOrigin(this.
Jid,
null,
null,
null,
this));
356 public object this[
string Key]
360 if (this.properties.TryGetValue(
Key, out
object Obj))
372 public Task<IEnumerable<KeyValuePair<string, object>>>
CreateClaims(
bool Encrypted)
374 int IssuedAt = (int)Math.Round(DateTime.UtcNow.Subtract(
JSON.
UnixEpoch).TotalSeconds);
375 int Expires = IssuedAt + 3600;
376 DateTime Now = DateTime.Now;
378 if (this.From > Now ||
380 this.State != Networking.XMPP.Contracts.IdentityState.Approved)
382 return Task.FromResult<IEnumerable<KeyValuePair<string, object>>>(
null);
385 List<KeyValuePair<string, object>> Claims =
new List<KeyValuePair<string, object>>()
391 new KeyValuePair<string, object>(
JwtClaims.
Name,
this.UserName),
407 FullName = Networking.XMPP.Contracts.LegalIdentity.JoinNames(FirstName, MiddleNames, LastNames);
409 Networking.XMPP.Contracts.LegalIdentity.SeparateNames(FullName, out FirstName, out MiddleNames, out LastNames);
418 string BMonth =
null;
421 foreach (KeyValuePair<string, object> P
in this.properties)
455 BDay = P.Value?.ToString();
459 BMonth = P.Value?.ToString();
463 BYear = P.Value?.ToString();
467 AddClaim(Claims,
"age_above", P.Value);
471 AddClaim(Claims,
"org_name", P.Value);
475 AddClaim(Claims,
"org_nr", P.Value);
479 AddClaim(Claims,
"org_dept", P.Value);
483 AddClaim(Claims,
"org_role", P.Value);
487 AddClaim(Claims,
"org_addr", P.Value);
491 AddClaim(Claims,
"org_addr2", P.Value);
495 AddClaim(Claims,
"org_zip", P.Value);
499 AddClaim(Claims,
"org_area", P.Value);
503 AddClaim(Claims,
"org_city", P.Value);
507 AddClaim(Claims,
"org_region", P.Value);
511 AddClaim(Claims,
"org_country", P.Value);
516 if (!
string.IsNullOrEmpty(BDay) &&
517 !
string.IsNullOrEmpty(BMonth) &&
518 !
string.IsNullOrEmpty(BYear) &&
519 int.
TryParse(BDay, out
int BDayNr) &&
520 int.
TryParse(BMonth, out
int BMonthNr) &&
521 int.
TryParse(BYear, out
int BYearNr) &&
522 BMonthNr >= 1 && BMonthNr <= 12 &&
523 BYearNr >= 1900 && BYearNr <= 2100 &&
524 BDayNr >= 1 && BDayNr <= DateTime.DaysInMonth(BYearNr, BMonthNr))
530 return Task.FromResult<IEnumerable<KeyValuePair<string, object>>>(Claims);
533 private static void AddClaim(List<KeyValuePair<string, object>> Claims,
string Key,
object Value)
535 if (!(Value is
null))
537 if (Value is
string s && s ==
"N/A")
540 Claims.Add(
new KeyValuePair<string, object>(
Key, Value));
552 params KeyValuePair<string, object>[] AdditionalClaims)
554 IEnumerable<KeyValuePair<string, object>> Claims = await this.
CreateClaims(Encrypted);
556 return Factory.
Create(Claims);
565 StringBuilder Xml =
new StringBuilder();
567 return Xml.ToString();
576 Xml.Append(
"<quickLoginUser xmlns='");
578 Xml.Append(
"' key='");
582 this.
id.Serialize(Xml,
true,
true,
true,
true,
true,
true,
true);
584 if (!(this.properties is
null))
586 Xml.Append(
"<properties>");
588 Xml.Append(
"</properties>");
591 if (!(this.attachments is
null))
593 Xml.Append(
"<attachments>");
595 foreach (Dictionary<string, object>
Attachment in this.attachments)
597 Xml.Append(
"<attachment>");
599 Xml.Append(
"</attachment>");
602 Xml.Append(
"</attachments>");
605 Xml.Append(
"</quickLoginUser>");
621 Reason =
new ArgumentNullException(nameof(Xml)).Message;
627 Reason =
"Not a quick-login user element.";
632 if (
string.IsNullOrEmpty(PetitionId))
634 Reason =
"Missing or empty key.";
642 foreach (XmlNode N
in Xml.ChildNodes)
644 if (!(N is XmlElement E))
652 Id = Networking.XMPP.Contracts.LegalIdentity.Parse(E);
666 foreach (XmlNode N2
in E.ChildNodes)
668 if (N2 is XmlElement E2 && E2.LocalName ==
"attachment")
677 Reason =
"Missing legal identity.";
683 Properties ??
new Dictionary<string, object>(),
689 private static Dictionary<string, object> ParseTags(XmlElement E)
691 Dictionary<string, object> Tags =
new Dictionary<string, object>();
693 foreach (XmlNode N2
in E.ChildNodes)
695 if (N2 is XmlElement E2 && E2.LocalName ==
"tag")
702 TagValueParsed = TagValue;
704 Tags[TagName] = TagValueParsed;
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 Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
static string Encode(string s)
Encodes a string for use in XML.
This class handles incoming events from the XMPP network. The default behaviour is to log incoming ev...
static bool TryParse(string Value, string Type, out object ParsedValue)
Tries to parse a simple value.
Event sink sending events to a destination over the XMPP network.
static void AppendTags(StringBuilder Xml, params KeyValuePair< string, object >[] Tags)
Appends a collection of tags to an XML string.
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.
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
override string ToString()
A chunked list is a linked list of chunks of objects of type T .
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.
static IEnumerable< KeyValuePair< string, object > > JoinClaims(IEnumerable< KeyValuePair< string, object > > Claims1, params KeyValuePair< string, object >[] Claims2)
Joins two sets of claims into one.
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.
Web resource that allows calling applications to enable Quick-Login using legal identities.
const string NamespaceTagSignature
https://tagroot.io/schema/Signature
DateTime? Updated
When ID was updated
Dictionary< string, object > Properties
Properties encoded into the ID
static bool TryParse(XmlElement Xml, out QuickLoginUser User, out string Reason)
Tries to parse a Quick-Login user from XML.
string Key
Key used during login
string FriendlyName
Friendly name of the user, for display purposes.
string ClientPubKey
Client public key
Networking.XMPP.Contracts.IdentityState State
Legal ID state.
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.
void ExportXml(StringBuilder Xml)
Exports the Quick-Login user to XML.
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 ExportXml()
Exports the Quick-Login user to XML.
string ClientKeyName
Algorithm used by client
bool HasClientPublicKey
If ID has a client public key
LegalIdentity LegalId
Legal ID used to identify with the system.
async Task< string > CreateToken(JwtFactory Factory, bool Encrypted, params KeyValuePair< string, object >[] AdditionalClaims)
Creates a JWT Token referencing the user object.
string UserName
User Name.
string Id
Identifier of ID
string FederatedUserName
Full Federated User Name.
string FullAddress
Full address of person
Tokens available in request.
Interfaces for legal identities.
Basic interface for a users with a Legal Identity.
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.
Reason
Reason a token is not valid.