mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 20:02:05 +08:00
oauth2orize: Lint (#21045)
This commit is contained in:
49
types/oauth2orize/index.d.ts
vendored
49
types/oauth2orize/index.d.ts
vendored
@@ -8,41 +8,30 @@
|
||||
|
||||
import { ServerRequest, ServerResponse } from "http";
|
||||
|
||||
interface OAuth2 {
|
||||
export interface OAuth2 {
|
||||
client: any;
|
||||
|
||||
user: any;
|
||||
|
||||
transactionID: string;
|
||||
|
||||
redirectURI: string;
|
||||
|
||||
req: OAuth2Req;
|
||||
|
||||
info: OAuth2Info;
|
||||
}
|
||||
|
||||
interface OAuth2Req {
|
||||
export interface OAuth2Req {
|
||||
clientID: string;
|
||||
|
||||
redirectURI: string;
|
||||
|
||||
scope: string;
|
||||
|
||||
state: string;
|
||||
|
||||
type: string;
|
||||
|
||||
transactionID: string;
|
||||
}
|
||||
|
||||
interface OAuth2Info {
|
||||
export interface OAuth2Info {
|
||||
scope: string;
|
||||
}
|
||||
|
||||
export interface MiddlewareRequest extends ServerRequest {
|
||||
oauth2?: OAuth2;
|
||||
|
||||
user?: any;
|
||||
}
|
||||
|
||||
@@ -51,7 +40,7 @@ export interface ServerOptions {
|
||||
loadTransaction: boolean;
|
||||
}
|
||||
|
||||
export const createServer: (options?: ServerOptions) => OAuth2Server;
|
||||
export function createServer(options?: ServerOptions): OAuth2Server;
|
||||
|
||||
export interface AuthorizeOptions {
|
||||
idLength?: number;
|
||||
@@ -68,33 +57,31 @@ export interface ErrorHandlerOptions {
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
type MiddlewareFunction = (req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
export type MiddlewareFunction = (req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
|
||||
type MiddlewareErrorFunction = (err: Error, req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
export type MiddlewareErrorFunction = (err: Error, req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
|
||||
|
||||
type MiddlewareNextFunction = (err?: Error) => void;
|
||||
export type MiddlewareNextFunction = (err?: Error) => void;
|
||||
|
||||
type ValidateFunction = (clientId: string, redirectURI: string, validated: (err: Error | null, client?: any, redirectURI?: string) => void) => void;
|
||||
export type ValidateFunction = (clientId: string, redirectURI: string, validated: (err: Error | null, client?: any, redirectURI?: string) => void) => void;
|
||||
|
||||
type ImmediateFunction = (client: any, user: any, scope: string[], type: string, areq: any, done: (err: Error | null, allow: boolean, info: any, locals: any) => void) => void;
|
||||
export type ImmediateFunction = (client: any, user: any, scope: string[], type: string, areq: any, done: (err: Error | null, allow: boolean, info: any, locals: any) => void) => void;
|
||||
|
||||
type DecisionParseFunction = (req: MiddlewareRequest, done: (err: Error | null, params: any) => void) => void;
|
||||
export type DecisionParseFunction = (req: MiddlewareRequest, done: (err: Error | null, params: any) => void) => void;
|
||||
|
||||
type SerializeClientFunction = (client: any, done: SerializeClientDoneFunction) => void;
|
||||
type SerializeClientDoneFunction = (err: Error | null, id: string) => void;
|
||||
export type SerializeClientFunction = (client: any, done: SerializeClientDoneFunction) => void;
|
||||
export type SerializeClientDoneFunction = (err: Error | null, id: string) => void;
|
||||
|
||||
type DeserializeClientFunction = (id: string, done: DeserializeClientDoneFunction) => void;
|
||||
type DeserializeClientDoneFunction = (err: Error | null, client?: any | boolean) => void;
|
||||
export type DeserializeClientFunction = (id: string, done: DeserializeClientDoneFunction) => void;
|
||||
export type DeserializeClientDoneFunction = (err: Error | null, client?: any | boolean) => void;
|
||||
|
||||
type IssueGrantCodeFunction = (client: any, redirectUri: string, user: any, res: any, issued: (err: Error | null, code?: string) => void) => void;
|
||||
export type IssueGrantCodeFunction = (client: any, redirectUri: string, user: any, res: any, issued: (err: Error | null, code?: string) => void) => void;
|
||||
|
||||
type IssueGrantTokenFunction = (client: any, user: any, ares: any, issued: (err: Error | null, code?: string, params?: any) => void) => void;
|
||||
export type IssueGrantTokenFunction = (client: any, user: any, ares: any, issued: (err: Error | null, code?: string, params?: any) => void) => void;
|
||||
|
||||
export type IssueExchangeCodeFunction = (client: any, code: string, redirectURI: string, issued: ExchangeDoneFunction) => void;
|
||||
|
||||
type IssueExchangeCodeFunction = (client: any, code: string, redirectURI: string, issued: ExchangeDoneFunction) => void;
|
||||
|
||||
type ExchangeDoneFunction = (err: Error | null, accessToken?: string | boolean, refreshToken?: string, params?: any) => void;
|
||||
|
||||
export type ExchangeDoneFunction = (err: Error | null, accessToken?: string | boolean, refreshToken?: string, params?: any) => void;
|
||||
|
||||
export class OAuth2Server {
|
||||
grant(type: string, fn: MiddlewareFunction): OAuth2Server;
|
||||
|
||||
@@ -17,19 +17,20 @@ server.grant(oauth2orize.grant.code((client, redirectURI, user, ares, done) => {
|
||||
// });
|
||||
}));
|
||||
|
||||
|
||||
// Register Exchanges
|
||||
class AuthorizationCode {
|
||||
static findOne(code: string, callback: (err: Error, code: {
|
||||
clientId: string, userId: string, redirectURI: string, scope: string
|
||||
}) => void): void {}
|
||||
}
|
||||
function findOne(code: string, callback: (err: Error, code: {
|
||||
clientId: string, userId: string, redirectURI: string, scope: string
|
||||
}) => void): void {}
|
||||
|
||||
server.exchange(oauth2orize.exchange.code((client, code, redirectURI, done) => {
|
||||
AuthorizationCode.findOne(code, (err, code) => {
|
||||
if (err) { return done(err); }
|
||||
if (client.id !== code.clientId) { return done(null, false); }
|
||||
if (redirectURI !== code.redirectURI) { return done(null, false); }
|
||||
findOne(code, (err, code) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else if (client.id !== code.clientId) {
|
||||
done(null, false);
|
||||
} else if (redirectURI !== code.redirectURI) {
|
||||
done(null, false);
|
||||
}
|
||||
|
||||
// var token = utils.uid(256);
|
||||
// var at = new AccessToken(token, code.userId, code.clientId, code.scope);
|
||||
@@ -43,7 +44,7 @@ server.exchange(oauth2orize.exchange.code((client, code, redirectURI, done) => {
|
||||
// Implement Authorization Endpoint
|
||||
class Clients {
|
||||
static findOne(id: string, callback: (err: Error, client?: Clients) => void): void {
|
||||
callback(new Error(), {} as Clients);
|
||||
callback(new Error(), {} as Clients); // tslint:disable-line no-object-literal-type-assertion
|
||||
}
|
||||
redirectURI: string;
|
||||
}
|
||||
@@ -52,33 +53,41 @@ class Clients {
|
||||
// login.ensureLoggedIn(),
|
||||
server.authorize((clientID, redirectURI, done) => {
|
||||
Clients.findOne(clientID, (err, client) => {
|
||||
if (err) { return done(err); }
|
||||
if (!client) { return done(null, false); }
|
||||
if (client.redirectURI != redirectURI) { return done(null, false); }
|
||||
return done(null, client, client.redirectURI);
|
||||
if (err) {
|
||||
done(err);
|
||||
} else if (!client) {
|
||||
done(null, false);
|
||||
} else if (client.redirectURI !== redirectURI) {
|
||||
done(null, false);
|
||||
} else {
|
||||
done(null, client, client.redirectURI);
|
||||
}
|
||||
});
|
||||
}),
|
||||
});
|
||||
(req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
// res.render('dialog', { transactionID: req.oauth2.transactionID,
|
||||
// user: req.user, client: req.oauth2.client });
|
||||
}
|
||||
};
|
||||
// );
|
||||
|
||||
// Session Serialization
|
||||
server.serializeClient((client, done) => {
|
||||
return done(null, client.id);
|
||||
done(null, client.id);
|
||||
});
|
||||
|
||||
server.deserializeClient((id, done) => {
|
||||
Clients.findOne(id, (err, client) => {
|
||||
if (err) { return done(err); }
|
||||
return done(null, client);
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
done(null, client);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Implement Token Endpoint
|
||||
// app.post('/token',
|
||||
// passport.authenticate(['basic', 'oauth2-client-password'], { session: false }),
|
||||
server.token(),
|
||||
server.errorHandler()
|
||||
server.token();
|
||||
server.errorHandler();
|
||||
// );
|
||||
|
||||
@@ -1,79 +1,8 @@
|
||||
{
|
||||
"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,
|
||||
// TODOs
|
||||
"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
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user