3using System.Threading.Tasks;
15 : base(
"/ValidateLegalId")
19 public override bool HandlesSubPaths =>
false;
20 public override bool UserSessions =>
true;
34 if (Content.
HasError || !(Content.
Decoded is Dictionary<string, object> RequestObj) ||
35 !RequestObj.TryGetValue(
"LegalId", out
object Obj) || !(Obj is
string LegalId) ||
36 !RequestObj.TryGetValue(
"Purpose", out Obj) || !(Obj is
string Purpose) ||
37 !RequestObj.TryGetValue(
"Password", out Obj) || !(Obj is
string Password) ||
38 !RequestObj.TryGetValue(
"TabID", out Obj) || !(Obj is
string TabID))
44 if (LegalId.IndexOf(
'@') < 0)
56 Dictionary<string, object> ResponseObj;
61 ResponseObj = await this.Encode(Identity);
65 string PetitionId = Guid.NewGuid().ToString();
67 Purpose = Purpose.Trim();
68 if (
string.IsNullOrEmpty(Purpose))
69 Purpose =
"Validating Legal Identity through web interface at " +
Gateway.
Domain;
75 {
"PetitionId", e.PetitionId },
76 {
"PetitionResponse", e.Response },
77 {
"Identity", await this.Encode(e.RequestedIdentity) },
78 {
"Declined", e.RequestedIdentity is
null && !(e.Message is
null) },
79 {
"Timeout", e.Message is
null }
81 }, TimeSpan.FromMinutes(5)))
83 await Response.
SendResponse(
new ForbiddenException(Request,
"Unable to sign petition. Either password is incorrect, or no legal identity assigned to broker."));
87 ResponseObj =
new Dictionary<string, object>()
91 {
"PetitionId", PetitionId },
92 {
"Message",
"The information has been petitioned from the owner. If the owner accepts to share the information, it will be displayed here when it arrives." }
96 await Response.
Return(ResponseObj);
99 private async Task<Dictionary<string, object>> Encode(
LegalIdentity Identity)
101 if (Identity is
null)
106 Dictionary<string, object> Properties =
new Dictionary<string, object>();
107 Dictionary<string, object> ResponseObj =
new Dictionary<string, object>()
109 {
"Id", Identity.Id },
110 {
"IdUri", Identity.IdUriString },
111 {
"Petition",
false },
112 {
"ClientKeyName", Identity.ClientKeyName },
113 {
"ClientPubKey", Identity.HasClientPublicKey ? Convert.ToBase64String(Identity.
ClientPubKey) :
null },
114 {
"ClientSignature", Identity.HasClientSignature ? Convert.ToBase64String(Identity.
ClientSignature) :
null },
115 {
"Created", Identity.Created },
116 {
"From", Identity.From },
117 {
"To", Identity.To },
118 {
"HasClientPublicKey", Identity.HasClientPublicKey },
119 {
"HasClientSignature", Identity.HasClientSignature },
120 {
"Provider", Identity.Provider },
121 {
"ServerSignature", Convert.ToBase64String(Identity.
ServerSignature) },
122 {
"State", Identity.
State.ToString() },
123 {
"Updated", Identity.Updated },
124 {
"ValidationStatus", Status.ToString() },
125 {
"ValidationStatusTags", e.Tags },
126 {
"Properties", Properties }
134 List<Dictionary<string, object>> Attachments =
new List<Dictionary<string, object>>();
138 Attachments.Add(
new Dictionary<string, object>()
140 {
"Id", Attachment.Id },
141 {
"ContentType", Attachment.ContentType },
142 {
"FileName", Attachment.FileName },
143 {
"Url", Attachment.Url },
145 {
"Timestamp", Attachment.Timestamp },
149 ResponseObj[
"Attachments"] = Attachments.ToArray();
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
static Task< bool > PetitionLegalIdentity(string LegalId, string PetitionId, string Purpose, EventHandlerAsync< LegalIdentityPetitionResponseEventArgs > Callback, TimeSpan Timeout, HttpRequest Request)
Petitions information about a legal identity from its owner.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
bool HasData
If the request has data.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Return(Exception ex)
Returns an error to the client.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Contains a reference to an attachment assigned to a legal object.
byte[] Signature
Binary signature of the attachment, generated by an approved legal identity of the account-holder....
Task< LegalIdentity > GetLegalIdentityAsync(string LegalIdentityId)
Gets legal identity registered with the account.
Task< IdentityValidationEventArgs > ValidateAsync(LegalIdentity Identity)
Validates a legal identity.
Event arguments for identity validation responses
IdentityStatus Status
Validation status of legal identity.
IdentityState State
Current state of identity
byte[] ClientSignature
Client signature
byte[] ClientPubKey
Client Public key
byte[] ServerSignature
Server signature
Attachment[] Attachments
Attachments assigned to the legal identity.
Property[] Properties
Properties detailing the legal identity.
string Name
Name of property
string Value
Property value
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.
IdentityStatus
Validation Status of legal identity