Class IdentityProvider

Namespace
Cratis.Arc.Identity
Assembly
Cratis.Arc.Core.dll

Represents an implementation of IIdentityProvider.

[Singleton]
public class IdentityProvider : IIdentityProvider
Inheritance
IdentityProvider
Implements
Inherited Members
Extension Methods

Constructors

IdentityProvider(IHttpRequestContextAccessor, IOptions<ArcOptions>, IActivitySource<IdentityProvider>)

Represents an implementation of IIdentityProvider.

public IdentityProvider(IHttpRequestContextAccessor httpRequestContextAccessor, IOptions<ArcOptions> options, IActivitySource<IdentityProvider> activitySource)

Parameters

httpRequestContextAccessor IHttpRequestContextAccessor

The IHttpRequestContextAccessor.

options IOptions<ArcOptions>

The IOptions<TOptions>.

activitySource IActivitySource<IdentityProvider>

The IActivitySource<T> for tracing.

Fields

IdentityCookieName

The name of the identity cookie earlier versions of Arc wrote.

[Obsolete("Arc no longer reads or writes the identity cookie. Get the identity from the /.cratis/me endpoint instead.")]
public const string IdentityCookieName = ".cratis-identity"

Field Value

string

Remarks

Arc neither reads nor writes this cookie: the identity is always derived from the authenticated request, and frontends get it from the /.cratis/me endpoint.

Methods

Get()

Generates an IdentityProviderResult from the authenticated principal of the current HTTP context.

public Task<IdentityProviderResult> Get()

Returns

Task<IdentityProviderResult>

The IdentityProviderResult.

Remarks

The identity is always derived from the authenticated request. Nothing the client sends besides its credentials, such as an identity cookie, is read.

Get<TDetails>()

Gets an IdentityProviderResult<TDetails> from the authenticated principal of the current HTTP context.

public Task<IdentityProviderResult<TDetails>> Get<TDetails>()

Returns

Task<IdentityProviderResult<TDetails>>

The IdentityProviderResult<TDetails>.

Type Parameters

TDetails

Type of the details.

ModifyDetails<TDetails>(Func<TDetails, TDetails>)

Modifies the details of the current identity and writes the result to the response.

public Task ModifyDetails<TDetails>(Func<TDetails, TDetails> details)

Parameters

details Func<TDetails, TDetails>

Function to modify the details.

Returns

Task

Awaitable task.

Type Parameters

TDetails

Type of the details.

Remarks

The modification applies to the current response only. It is not stored: the next request derives the identity from the authenticated principal again.

SetCookieForHttpResponse(IdentityProviderResult)

Writes the IdentityProviderResult to the response body as JSON, with headers that keep it out of shared caches.

public Task SetCookieForHttpResponse(IdentityProviderResult result)

Parameters

result IdentityProviderResult

The IdentityProviderResult.

Returns

Task

Awaitable task.

Remarks

Despite its name, this no longer writes an identity cookie: it expires a .cratis-identity cookie written by an earlier version, if the request carries one. The name is kept for compatibility.