HTTP API Toolkit HTTP API Toolkit
HTTP API Toolkit HTTP API Toolkit
DocFX + Singulink = ♥

Search Results for

    Class TestSessionContext<TSessionToken>

    A session context for testing code that takes one, without a request or a session store. It has the token of a session or none, and checks the request's origin and user ID precondition as session handling does. Signing in calls the session creation function with a SignInInfo for the expiries of Options, and keeps the token that the function returns.

    Inheritance
    object
    SessionContext<TSessionToken>
    TestSessionContext<TSessionToken>
    Implements
    IBindableFromHttpContext<SessionContext<TSessionToken>>
    Inherited Members
    SessionContext<TSessionToken>.EnsureSignInOriginAllowed()
    SessionContext<TSessionToken>.IBindableFromHttpContext<SessionContext<TSessionToken>>.BindAsync(HttpContext, ParameterInfo)
    Namespace: Singulink.Net.Http.Api.Service.Testing
    Assembly: Singulink.Net.Http.Api.Service.Testing.dll
    Syntax
    public class TestSessionContext<TSessionToken> : SessionContext<TSessionToken>, IBindableFromHttpContext<SessionContext<TSessionToken>> where TSessionToken : class, ISessionToken
    Type Parameters
    Name Description
    TSessionToken

    The session token type.

    Remarks

    The session is not validated against a session store: ForceValidate has no effect, and the token is never replaced by one from a store.

    Constructors

    Name Description
    TestSessionContext(TSessionToken?, string?, IPAddress?)

    Initializes a new instance of the TestSessionContext<TSessionToken> class.

    Fields

    Name Description
    DefaultDevice

    The device of a test session context that is created without one.

    Properties

    Name Description
    Device

    Gets the device that is making the current request, at most MaxDeviceLength long (see GetClientDevice(HttpContext)).

    IpAddress

    Gets the IP address of the client that is making the current request, with an IPv4-mapped IPv6 address as the IPv4 address it maps, or null if the address is not known (see GetClientIpAddress(HttpContext)).

    IsOriginAllowed

    Gets or sets a value indicating whether the request's origin is allowed. Default is true.

    IsSignedOut

    Gets a value indicating whether the session was signed out with SignOutAsync().

    LastSignIn

    Gets the sign-in info that the session creation function of the last sign-in received, or null if there was no sign-in.

    Options

    Gets the session handling options: the forced access options of token retrievals, and the expiries and maximum lifetimes of sign-ins.

    TimeProvider

    Gets the clock of sign-ins. Default is System.

    Token

    Gets or sets the token of the request's session, or null if the request has no session.

    UserIdPrecondition

    Gets or sets the user ID precondition of the request, or null for a request without one.

    Methods

    Name Description
    ClearToken()

    Clears the session cookie of the current request. Subsequent token retrievals in the current request return null, and any pending deferred session refresh is cancelled.

    GetRequiredTokenAsync(SessionAccessOptions)

    Gets the session token from the current request. If the user is not signed in, throws an UnauthorizedApiException.

    GetTokenAsync(SessionAccessOptions)

    Gets the session token from the current request. If the user is not signed in, returns null.

    IsRequestOriginAllowed()

    Determines whether the origin of the current request is allowed: a request with an Origin header must have one of the allowed origins, and a request without one is allowed.

    SetToken(TSessionToken)

    Replaces the session token of the current request's session and issues the session cookie with it. Subsequent token retrievals in the current request return the specified token, and any pending deferred session refresh is cancelled.

    SignInAsync(bool, Func<SignInInfo, Task<TSessionToken>>)

    Signs in a user by creating a new session with the provided function and issuing the session cookie with the session token that the function returns. The request's previous session, if it has one, is then ended with InvalidateSessionAsync(TSessionToken, CancellationToken), unless the function returned its token (compared with Equals(Object, Object)). The response is marked with a Session-Change: sign-in header, so that the toolkit's clients take its cookie whatever session the device has by then.

    SignOutAsync()

    Signs out: ends the request's session with InvalidateSessionAsync(TSessionToken, CancellationToken) and clears the session cookie. The response is marked with a Session-Change: sign-out header, so that the toolkit's clients take its deletion whatever session the device has by then, unless the response has started, as in a hub connection, where the cookie can't be cleared either.

    © Singulink. All rights reserved.