4using System.Threading.Tasks;
19 private readonly
Account account;
38 public string UserName => this.account.UserName;
52 string s = this.account.FullName;
53 return string.IsNullOrEmpty(s) ? this.UserName : s;
74 return this.account.HasPrivilege(
Privilege);
90 public async Task<IEnumerable<KeyValuePair<string, object>>>
CreateClaims(
bool Encrypted)
92 if (!this.account.Enabled)
95 int IssuedAt = (int)Math.Round(DateTime.UtcNow.Subtract(
JSON.
UnixEpoch).TotalSeconds);
96 int Expires = IssuedAt + 3600;
98 List<KeyValuePair<string, object>> Claims =
new List<KeyValuePair<string, object>>()
109 if (!
string.IsNullOrWhiteSpace(this.account.EMail))
110 Claims.Add(
new KeyValuePair<string, object>(
JwtClaims.
EMail,
this.account.EMail));
112 if (!
string.IsNullOrWhiteSpace(this.account.PhoneNr))
115 if (this.account.CanRelayMessages)
118 if ((this.account.RoleIds?.Length ?? 0) > 0)
120 StringBuilder sb =
null;
122 foreach (
string RoleId
in this.account.RoleIds)
125 Claims.Add(
new KeyValuePair<string, object>(
JwtClaims.
Roles, sb?.ToString()));
129 foreach (
Role Role in await this.account.LoadRoles())
155 params KeyValuePair<string, object>[] AdditionalClaims)
157 IEnumerable<KeyValuePair<string, object>> Claims = await this.
CreateClaims(Encrypted);
162 return Factory.
Create(Claims);
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 runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
Implements a simple SMTP Server, as defined in:
const string SmtpRelayPrivilegeID
SmtpRelay
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 EMail
Preferred e-mail address
const string PhoneNumber
Preferred telephone number
const string Subject
Subject of the JWT (the user)
const string Entitlements
Entitlements
const string ExpirationTime
Time after which the JWT expires
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.
Contains a reference to a privilege
Corresponds to a role in the system.
PrivilegePattern[] Privileges
Privileges
Corresponds to a user in the system.
static void AppendValue(ref StringBuilder Output, object Value, string Delimiter)
Appends a value to a StringBuilder.
Contains information about a broker account.
Account Account
Account object.
string UserName
User Name.
AccountUser(Account Account)
Account user object.
string FriendlyName
Friendly name of the user, for display purposes.
string PasswordHashType
Type of password hash. The empty stream means a clear-text password.
Task< RequestOrigin > GetOrigin()
Origin of request.
string FederatedUserName
Full Federated User Name.
async Task< IEnumerable< KeyValuePair< string, object > > > CreateClaims(bool Encrypted)
Creates a set of claims identifying the user.
async Task< string > CreateToken(JwtFactory Factory, bool Encrypted, params KeyValuePair< string, object >[] AdditionalClaims)
Creates a JWT Token referencing the user object.
bool HasPrivilege(string Privilege)
If the user has a given privilege.
string PasswordHash
Password Hash
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.