Class TestApiKeyBuilder
- Namespace
- XBullet.EasyTesting.Authentication
- Assembly
- XBullet.EasyTesting.dll
Fluently creates an API-key-shaped test principal.
public sealed class TestApiKeyBuilder
- Inheritance
-
TestApiKeyBuilder
- Inherited Members
Remarks
This builder creates simulated claims and never stores or validates an API-key secret. It is mutable and not thread-safe; each call to Build() returns a snapshot.
Constructors
TestApiKeyBuilder(string)
Creates an API-key test builder targeting the supplied application scheme.
public TestApiKeyBuilder(string authenticationScheme = "IntegrationTest")
Parameters
authenticationSchemestringThe non-empty simulated scheme targeted by the resulting user. When omitted, the default XBullet test-authentication scheme is used.
Fields
KeyIdClaim
Claim containing the non-secret identifier of the represented API key.
public const string KeyIdClaim = "api_key_id"
Field Value
Methods
Build()
Creates the API-key-shaped test user.
public TestUser Build()
Returns
- TestUser
A new user containing snapshots of the configured key identifier, client name, roles, and custom claims. Later builder changes do not modify the returned user.
WithClaim(string, string)
Adds a custom claim associated with the API key.
public TestApiKeyBuilder WithClaim(string type, string value)
Parameters
typestringThe non-empty claim-type identifier.
valuestringThe non-null claim value; an empty value is accepted.
Returns
- TestApiKeyBuilder
This builder so additional identity values can be configured.
WithClientName(string)
Sets the client name exposed through Name.
public TestApiKeyBuilder WithClientName(string clientName)
Parameters
clientNamestringThe non-empty client-name claim value.
Returns
- TestApiKeyBuilder
This builder so additional identity values can be configured.
WithKeyId(string)
Sets the non-secret API-key identifier included in the claims principal.
public TestApiKeyBuilder WithKeyId(string keyId)
Parameters
keyIdstringThe non-empty identifier used for the KeyIdClaim and name-identifier claims. It is metadata, not an API-key secret.
Returns
- TestApiKeyBuilder
This builder so additional identity values can be configured.
WithRole(string)
Adds a role recognized by ASP.NET Core role authorization.
public TestApiKeyBuilder WithRole(string role)
Parameters
rolestringThe non-empty role value to append. Duplicate roles are retained.
Returns
- TestApiKeyBuilder
This builder so additional identity values can be configured.
WithRoles(params string[])
Adds roles recognized by ASP.NET Core role authorization.
public TestApiKeyBuilder WithRoles(params string[] roles)
Parameters
rolesstring[]The non-null role array appended in order. Every element must be non-empty; duplicates are retained. The builder copies the values and does not own the array.
Returns
- TestApiKeyBuilder
This builder so additional identity values can be configured.