跳到主要内容
版本:Next

PassportAuthenticator

Index

Constructors

constructor

Properties

_deserializers

_deserializers: any[] = []

_infoTransformers

_infoTransformers: any[] = []

_key

_key: string = 'passport'

_serializers

_serializers: any[] = []

applicationContext

applicationContext: IMidwayContainer

passportConfig

passportConfig: any

Methods

publicaddDeserializer

  • addDeserializer(fn: any): void

publicaddInfoTransformer

  • addInfoTransformer(fn: any): void

publicaddSerializer

  • addSerializer(fn: any): void

publicauthenticate

  • authenticate(strategies: Strategy[], options?: AuthenticateOptions): (req: any) => Promise<{ failResult?: { failures: { challenge: string; status: number }[] }; redirectResult?: { status: number; url: string }; successResult?: { info: any; user: any } }>
  • Authenticates requests.

    Applies the nameed strategy (or strategies) to the incoming request, in order to authenticate the request. If authentication is successful, the user will be logged in and populated at req.user and a session will be established by default. If authentication fails, an unauthorized response will be sent.

    Options:

    • session Save login state in session, defaults to true
    • successRedirect After successful login, redirect to given URL
    • successMessage True to store success message in req.session.messages, or a string to use as override message for success.
    • successFlash True to flash success messages or a string to use as a flash message for success (overrides any from the strategy itself).
    • failureRedirect After failed login, redirect to given URL
    • failureMessage True to store failure message in req.session.messages, or a string to use as override message for failure.
    • failureFlash True to flash failure messages or a string to use as a flash message for failures (overrides any from the strategy itself).
    • assignProperty Assign the object provided by the verify callback to given property

publicdeserializeUser

  • deserializeUser(obj: any, req: any, done: any): void
  • Registers a function used to deserialize user objects out of the session.

    Examples:

    passport.deserializeUser(function(id, done) {
    User.findById(id, function (err, user) {
    done(err, user);
    });
    });
    @api

    public

publicgetSessionUserProperty

  • getSessionUserProperty(): string

publicgetUserProperty

  • getUserProperty(): string

publicisEnableSession

  • isEnableSession(): boolean

publicisExpressMode

  • isExpressMode(): boolean

publiclogInToSession

  • logInToSession(req: IncomingMessage & { session: any }, user: any): Promise<void>

publiclogOutFromSession

  • logOutFromSession(req: any, options?: { keepSessionInfo?: boolean }): Promise<void>

publicserializeUser

  • serializeUser(user: any, req: any, done: any): void

publictransformAuthInfo

  • transformAuthInfo(info: any, req: any, done: any): void
  • Registers a function used to transform auth info.

    In some circumstances authorization details are contained in authentication credentials or loaded as part of verification.

    For example, when using bearer tokens for API authentication, the tokens may encode (either directly or indirectly in a database), details such as scope of access or the client to which the token was issued.

    Such authorization details should be enforced separately from authentication. Because Passport deals only with the latter, this is the responsiblity of middleware or routes further along the chain. However, it is not optimal to decode the same data or execute the same database query later. To avoid this, Passport accepts optional info along with the authenticated user in a strategy’s success() action. This info is set at req.authInfo, where said later middlware or routes can access it.

    Optionally, applications can register transforms to proccess this info, which take effect prior to req.authInfo being set. This is useful, for example, when the info contains a client ID. The transform can load the client from the database and include the instance in the transformed info, allowing the full set of client properties to be convieniently accessed.

    If no transforms are registered, info supplied by the strategy will be left unmodified.

    Examples:

    passport.transformAuthInfo(function(info, done) {
    Client.findById(info.clientID, function (err, client) {
    info.client = client;
    done(err, info);
    });
    });
    @api

    public

publicunuse

publicuse