Table of Contents

Class TestUserStore

Namespace
Fdyay.IdentityServer.Test
Assembly
Fdyay.IdentityServer.Core.dll

An in-memory ITestUserStore. Intended for development and testing only.

public sealed class TestUserStore : ITestUserStore
Inheritance
TestUserStore
Implements
Inherited Members

Constructors

TestUserStore(IEnumerable<TestUser>)

Creates the store holding a copy of users.

public TestUserStore(IEnumerable<TestUser> users)

Parameters

users IEnumerable<TestUser>

The initial users. The store keeps its own list, so later changes to this sequence are not seen.

Methods

AutoProvisionUser(string, string, IEnumerable<Claim>)

Creates and links a new local user from an external provider identity.

public TestUser AutoProvisionUser(string provider, string providerSubjectId, IEnumerable<Claim> claims)

Parameters

provider string
providerSubjectId string
claims IEnumerable<Claim>

Returns

TestUser

Remarks

The new user gets a random subject id, the provider's claims less any sub, and as username the name claim, else Name, else providerSubjectId. It has no password.

CreateUser(string, string, string?, string?)

Adds a local user with a password, for a development registration page. Duende's.

public TestUser CreateUser(string username, string password, string? name = null, string? email = null)

Parameters

username string

The new user's username, which no user may have already.

password string

The password, kept as given: this store is for development only.

name string

The user's name, carried as a Name claim when given.

email string

The user's email address, carried as a Email claim when given.

Returns

TestUser

Remarks

Duende 8.0.1's, measured: the subject 32 random bytes in hex, the name and email as claims when given, refused with "That username already exists." Where ours differs: taken means what FindByUsername(string) finds, ignoring case, where Duende's compares ordinally — two users whose names differ only in case would sign in as the first — and the refusal is an InvalidOperationException rather than an Exception.

Exceptions

InvalidOperationException

A user already has username.

FindByExternalProvider(string, string)

Finds a user previously linked to an external provider identity.

public TestUser? FindByExternalProvider(string provider, string providerSubjectId)

Parameters

provider string
providerSubjectId string

Returns

TestUser

FindBySubjectId(string)

Finds a user by subject identifier.

public TestUser? FindBySubjectId(string subjectId)

Parameters

subjectId string

The subject identifier, the sub claim.

Returns

TestUser

The user, or null when there is none.

Remarks

Compared ordinally.

FindByUsername(string)

Finds a user by username.

public TestUser? FindByUsername(string username)

Parameters

username string

The username.

Returns

TestUser

The user, or null when there is none.

Remarks

Compared ignoring case.

ValidateCredentials(string, string)

Checks a username and password for a local sign-in.

public TestUser? ValidateCredentials(string username, string password)

Parameters

username string

The username entered.

password string

The password entered.

Returns

TestUser

The user, when the user is active and the password matches; otherwise null.

Remarks

The username is matched ignoring case and the password ordinally; a user without a password (an external-only user) never validates.