mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-02 08:10:05 +00:00
Merge pull request #21956 from tlaziuk/koa-passport
[koa-passport] upgrade to v4.0
This commit is contained in:
72
types/koa-passport/index.d.ts
vendored
72
types/koa-passport/index.d.ts
vendored
@@ -1,6 +1,7 @@
|
||||
// Type definitions for koa-passport 2.x
|
||||
// Type definitions for koa-passport 4.0
|
||||
// Project: https://github.com/rkusa/koa-passport
|
||||
// Definitions by: horiuchi <https://github.com/horiuchi>
|
||||
// Tomek Łaziuk <https://github.com/tlaziuk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -12,52 +13,51 @@
|
||||
|
||||
=============================================== */
|
||||
|
||||
import * as Koa from "koa";
|
||||
import {
|
||||
Middleware,
|
||||
} from "koa";
|
||||
|
||||
import * as passport from "passport";
|
||||
|
||||
declare module "koa" {
|
||||
interface Context {
|
||||
authInfo?: any;
|
||||
user?: any;
|
||||
|
||||
login(user: any): Promise<void>;
|
||||
login(user: any, options: Object): Promise<void>;
|
||||
logIn(user: any): Promise<void>;
|
||||
logIn(user: any, options: Object): Promise<void>;
|
||||
login(user: any, options?: any): Promise<void>;
|
||||
logIn: Context["login"];
|
||||
|
||||
logout(): void;
|
||||
logOut(): void;
|
||||
logOut: Context["logout"];
|
||||
|
||||
isAuthenticated(): boolean;
|
||||
isUnauthenticated(): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
import * as passport from "passport";
|
||||
|
||||
interface KoaPassport {
|
||||
use(strategy: passport.Strategy): this;
|
||||
use(name: string, strategy: passport.Strategy): this;
|
||||
unuse(name: string): this;
|
||||
framework(fw: passport.Framework): this;
|
||||
initialize(options?: { userProperty: string; }): Koa.Middleware;
|
||||
session(options?: { pauseStream: boolean; }): Koa.Middleware;
|
||||
|
||||
authenticate(strategy: string, callback?: Function): Koa.Middleware;
|
||||
authenticate(strategy: string, options: Object, callback?: Function): Koa.Middleware;
|
||||
authenticate(strategies: string[], callback?: Function): Koa.Middleware;
|
||||
authenticate(strategies: string[], options: Object, callback?: Function): Koa.Middleware;
|
||||
authorize(strategy: string, callback?: Function): Koa.Middleware;
|
||||
authorize(strategy: string, options: Object, callback?: Function): Koa.Middleware;
|
||||
authorize(strategies: string[], callback?: Function): Koa.Middleware;
|
||||
authorize(strategies: string[], options: Object, callback?: Function): Koa.Middleware;
|
||||
serializeUser(fn: (user: any, done: (err: any, id: any) => void) => void): void;
|
||||
deserializeUser(fn: (id: any, done: (err: any, user: any) => void) => void): void;
|
||||
transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void;
|
||||
}
|
||||
declare const koaPassport: KoaPassport;
|
||||
|
||||
declare namespace KoaPassport {
|
||||
interface Profile extends passport.Profile { }
|
||||
interface Framework extends passport.Framework { }
|
||||
class KoaPassport {
|
||||
use(strategy: passport.Strategy): this;
|
||||
use(name: string, strategy: passport.Strategy): this;
|
||||
unuse(name: string): this;
|
||||
framework(fw: passport.Framework): this;
|
||||
initialize(options?: { userProperty: string; }): Middleware;
|
||||
session(options?: { pauseStream: boolean; }): Middleware;
|
||||
|
||||
authenticate(strategy: string | string[], callback?: (...args: any[]) => any): Middleware;
|
||||
authenticate(strategy: string | string[], options: passport.AuthenticateOptions, callback?: (...args: any[]) => any): Middleware;
|
||||
authorize(strategy: string | string[], callback?: (...args: any[]) => any): Middleware;
|
||||
authorize(strategy: string | string[], options: any, callback?: (...args: any[]) => any): Middleware;
|
||||
|
||||
serializeUser: passport.Passport["serializeUser"];
|
||||
deserializeUser: passport.Passport["deserializeUser"];
|
||||
transformAuthInfo: passport.Passport["transformAuthInfo"];
|
||||
}
|
||||
|
||||
interface Static extends KoaPassport {
|
||||
KoaPassport: typeof KoaPassport;
|
||||
Passport: typeof passport.Passport;
|
||||
Authenticator: Static["Passport"];
|
||||
}
|
||||
}
|
||||
|
||||
declare const koaPassport: KoaPassport.Static;
|
||||
|
||||
export = koaPassport;
|
||||
|
||||
@@ -2,13 +2,11 @@ import * as Koa from 'koa';
|
||||
import * as passport from 'koa-passport';
|
||||
|
||||
const app = new Koa();
|
||||
let ctx: Koa.Context;
|
||||
|
||||
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session());
|
||||
|
||||
app.use(async (ctx: Koa.Context): Promise<void> => {
|
||||
app.use(async (ctx): Promise<void> => {
|
||||
ctx.isAuthenticated();
|
||||
ctx.isUnauthenticated();
|
||||
ctx.login({});
|
||||
@@ -16,8 +14,7 @@ app.use(async (ctx: Koa.Context): Promise<void> => {
|
||||
ctx.state.user;
|
||||
});
|
||||
|
||||
|
||||
app.use(async (ctx: Koa.Context, next: () => Promise<any>) => {
|
||||
app.use(async (ctx, next) => {
|
||||
return passport.authenticate('local', (user: any, info: any, status: any) => {
|
||||
if (user === false) {
|
||||
ctx.status = 401;
|
||||
@@ -36,3 +33,4 @@ app.use(
|
||||
})
|
||||
);
|
||||
|
||||
class KoaPasspordChild extends passport.KoaPassport { }
|
||||
|
||||
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user