AccessKey Class
Definition
- Namespace
- Codebelt.SharedKernel.Security
- Assemblies
- Codebelt.SharedKernel.dll
Represents an AccessKey object that can be used for API key-based authentication and similar.
public record AccessKey : ValueObject, IEquatable<ValueObject>, IEquatable<AccessKey>
- Inheritance
-
objectAccessKey
- Implements
- Inherited Members
-
ValueObject.Equals(object)ValueObject.<Clone>$()ValueObject.EqualityContract
- Extension Methods
Examples
The following example issues a one-year AccessKey from a Secret and a TimeToLive, then reports the resulting secret material and the validity window so an issuer can confirm what was handed to the caller. Use AccessKey.Issue whenever you need both the secret and the bounded validity period on the same value object.
using System;
using Codebelt.SharedKernel;
using Codebelt.SharedKernel.Security;
namespace KeyIssuanceSample;
public static class KeyIssuer
{
public static (string Secret, DateTime ValidFrom, DateTime Expires) IssueYearlyKey(string hexSecret)
{
var secret = new Secret(hexSecret);
var key = AccessKey.Issue(secret, TimeToLive.FromYears(1));
// All three values are observable on the issued AccessKey and can flow into the caller response.
return (key.Secret, key.ValidFrom, key.Expires);
}
}
Remarks
Constructors
| Name | Description |
|---|---|
| AccessKey(Secret, Action<AccessKeyOptions>) | Initializes a new instance of the AccessKey class. |
Properties
| Name | Description |
|---|---|
| DesiredTolerance | Gets the desired tolerance for potential clock skew variations. |
| Expires | Gets the expiry date and time of the access key expressed as Coordinated Universal Time (UTC). |
| Secret | Gets the secret of the access key. |
| ValidFrom | Gets the date and time,expressed as Coordinated Universal Time (UTC), from which the access key is valid. |
Methods
| Name | Description |
|---|---|
| Issue(Secret, TimeToLive) | Issues a new instance of AccessKey with an optional |