UNPKG

2.89 kBTypeScriptView Raw
1/// <reference types="passport"/>
2
3/**
4 * Using this module, one can easily implement a strategy using typescript by
5 * inheriting the 'Strategy' class and reimplementing the 'authenticate' method.
6 */
7
8/// <reference types="express" />
9
10import passport = require("passport");
11import express = require("express");
12
13declare class Strategy implements passport.Strategy {
14 /**
15 * Performs authentication for the request.
16 * Note: Virtual function - re-implement in the strategy.
17 * @param req The request to authenticate.
18 * @param options Options passed to the strategy.
19 */
20 authenticate(req: express.Request, options?: any): void;
21
22 //
23 // Augmented strategy functions.
24 // These are available only from the 'authenticate' function.
25 // They are added manually by the passport framework.
26 //
27
28 /**
29 * Authenticate `user`, with optional `info`.
30 *
31 * Strategies should call this function to successfully authenticate a
32 * user. `user` should be an object supplied by the application after it
33 * has been given an opportunity to verify credentials. `info` is an
34 * optional argument containing additional user information. This is
35 * useful for third-party authentication strategies to pass profile
36 * details.
37 *
38 * @param {Object} user
39 * @param {Object} info
40 * @api public
41 */
42 success(user: any, info?: any): void;
43
44 /**
45 * Fail authentication, with optional `challenge` and `status`, defaulting
46 * to 401.
47 *
48 * Strategies should call this function to fail an authentication attempt.
49 *
50 * @param {String} challenge (Can also be an object with 'message' and 'type' fields).
51 * @param {Number} status
52 * @api public
53 */
54 fail(challenge: any, status: number): void;
55 fail(status: number): void;
56
57 /**
58 * Redirect to `url` with optional `status`, defaulting to 302.
59 *
60 * Strategies should call this function to redirect the user (via their
61 * user agent) to a third-party website for authentication.
62 *
63 * @param {String} url
64 * @param {Number} status
65 * @api public
66 */
67 redirect(url: string, status?: number): void;
68
69 /**
70 * Pass without making a success or fail decision.
71 *
72 * Under most circumstances, Strategies should not need to call this
73 * function. It exists primarily to allow previous authentication state
74 * to be restored, for example from an HTTP session.
75 *
76 * @api public
77 */
78 pass(): void;
79
80 /**
81 * Internal error while performing authentication.
82 *
83 * Strategies should call this function when an internal error occurs
84 * during the process of performing authentication; for example, if the
85 * user directory is not available.
86 *
87 * @param {Error} err
88 * @api public
89 */
90 error(err: Error): void;
91}