3using System.Threading.Tasks;
42 AgentResource.Factory = Factory;
65 List<IAgentResource> Resources =
new List<IAgentResource>();
76 await Resource.Register(WebServer,
this);
84 this.resources = Resources.ToArray();
101 if (!(this.resources is
null))
104 await Resource.Unregister(WebServer);
139 : this(
Code, string.Empty)
150 this.ErrorMessage = Message;
162 this.ErrorMessage = ex.Message;
178 this.ErrorMessage =
null;
236 string UserName,
string Password,
string EMail,
string PhoneNr,
string Language,
258 EMailVerified =
null,
260 PhoneNrVerified =
null,
262 CanRelayMessages =
false,
263 Created = DateTime.UtcNow
282 new Uri(
"https://" + OnboardingDomainName +
"/ID/SendVerificationMessage.ws"),
283 new Dictionary<string, object>()
286 {
"Language", Language }
288 new KeyValuePair<string, string>(
"Accept",
"application/json"));
293 if (!(OnboardingResponse.
Decoded is Dictionary<string, object> Response))
296 if (!Response.TryGetValue(
"Status", out
object Obj) ||
297 !(Obj is
bool Status) ||
300 if (Response.TryGetValue(
"Message", out Obj) && Obj is
string Message)
309 new Uri(
"https://" + OnboardingDomainName +
"/ID/SendVerificationMessage.ws"),
310 new Dictionary<string, object>()
313 {
"Language", Language }
315 new KeyValuePair<string, string>(
"Accept",
"application/json"));
320 if (!(OnboardingResponse.
Decoded is Dictionary<string, object> Response2))
323 if (!Response2.TryGetValue(
"Status", out Obj) ||
324 !(Obj is
bool Status2) ||
327 if (Response2.TryGetValue(
"Message", out Obj) && Obj is
string Message)
333 int IssuedAt = (int)Math.Round(DateTime.UtcNow.Subtract(
JSON.
UnixEpoch).TotalSeconds);
334 int Expires = IssuedAt + (int)Seconds;
338 else if (Seconds > 3600)
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
Helps with common JSON-related tasks.
static readonly DateTime UnixEpoch
Unix Date and Time epoch, starting at 1970-01-01T00:00:00Z
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static HttpServer HttpServer
HTTP Server
static LoginAuditor LoginAuditor
Current Login Auditor. Should be used by modules accepting user logins, to protect the system from un...
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
Represents an HTTP request.
string RemoteEndPoint
Remote end-point.
string Host
Host reference. (Value of Host header, without the port number)
Implements an HTTP server.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that have a named field equal to a given value.
Static class managing persistent counters.
static Task< long > IncrementCounter(CaseInsensitiveString Key)
Increments a counter.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object Instantiate(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
Static class containing predefined JWT claim names.
const string Issuer
Issuer of the JWT
const string IssueTime
Time at which the JWT was issued; can be used to determine age of the JWT
const string JwtId
Unique identifier; can be used to prevent the JWT from being replayed (allows a token to be used only...
const string Subject
Subject of the JWT (the user)
const string ExpirationTime
Time after which the JWT expires
A factory that can create and validate JWT tokens.
string Create(params KeyValuePair< string, object >[] Claims)
Creates a new JWT token.
Class that monitors login events, and help applications determine malicious intent....
Contains information about a broker account.
CaseInsensitiveString UserName
User Name of account
Account()
Contains information about a broker account.
static async Task AccountCreated(Account Account, ApiKey ApiKeyObject, string Domain, string RemoteEndPoint)
Notifies operators of a new account being created.
Legal (digital identities, smart contracts) service component.
static Task< string > GetOnboardingNeuronDomainName()
Gets the domain name of the Nnboarding Neuron.
Result from the CreateAccount method.
int Expires
When token expires.
CreateAccountResult(int Code, string Message)
Result from the CreateAccount method.
CreateAccountResult(DataStorage.Account Account, string Token, int IssuedAt, int Expires)
Result from the CreateAccount method.
CreateAccountResult(int Code)
Result from the CreateAccount method.
string Token
Agent API token for the created account.
DataStorage.Account Account
Account if created.
int IssuedAt
When token was issued.
string ErrorMessage
Error message, if code=-1, or specification of error, if applicable.
int Code
Codes have the following meanings:
CreateAccountResult(Exception ex)
Result from the CreateAccount method.
Task Start()
Starts the module.
Task Stop()
Stops the module.
LoginAuditor Auditor
Login auditor
AgentApi()
Agent API Module.
static async Task< ApiKey > GetAgentApiApiKey()
Gets API Key for the Agent API.
AgentApi(JwtFactory Factory, LoginAuditor Auditor)
Agent API Module.
async Task< ApiKey > GetApiKey(string ApiKey)
Gets an API Key
async Task Start(HttpServer WebServer)
Starts the module using a specific web server.
static async Task< CreateAccountResult > CreateAccount(string UserName, string Password, string EMail, string PhoneNr, string Language, int Seconds, HttpRequest Request)
Creates an account for use with the Agent API.
async Task Stop(HttpServer WebServer)
Stops the module using a specific web server.
Abstract base class for agent resources
static JwtFactory Factory
JWT Factory
Interface for late-bound modules loaded at runtime.
Interface for agent resources.