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