Added definition file, exported UnauthorizedError
This commit is contained in:
parent
90f431741b
commit
72f3846fcf
@ -221,3 +221,4 @@ function getSecret(request, secret, token, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.authorize = authorize;
|
exports.authorize = authorize;
|
||||||
|
exports.UnauthorizedError = UnauthorizedError;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
"description": "authenticate socket.io connections using JWTs",
|
"description": "authenticate socket.io connections using JWTs",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
|
"types": "./types/index.d.ts",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"socket",
|
"socket",
|
||||||
"socket.io",
|
"socket.io",
|
||||||
@ -22,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/socket.io": "~1.4.29",
|
||||||
"jsonwebtoken": "^5.0.0",
|
"jsonwebtoken": "^5.0.0",
|
||||||
"xtend": "~2.1.2"
|
"xtend": "~2.1.2"
|
||||||
},
|
},
|
||||||
|
70
types/index.d.ts
vendored
Normal file
70
types/index.d.ts
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* This module allows to authenticate socket.io connections with JWTs.
|
||||||
|
* This is especially if you do not want to use cookies in a single page application.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// <reference types="socket.io" />
|
||||||
|
|
||||||
|
declare module 'socketio-jwt' {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines possible errors for the secret-callback.
|
||||||
|
*/
|
||||||
|
interface ISocketIOError {
|
||||||
|
readonly code: string;
|
||||||
|
readonly message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback gets called, if secret is given dynamically.
|
||||||
|
*/
|
||||||
|
interface ISocketCallback {
|
||||||
|
(err: ISocketIOError, success: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ISocketIOMiddleware {
|
||||||
|
(socket: SocketIO.Socket, fn: (err?: any) => void): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IOptions {
|
||||||
|
additional_auth?: (decoded: object, onSuccess: () => void, onError: (err: (string | ISocketIOError), code: string) => void) => void;
|
||||||
|
|
||||||
|
callback?: (false | number);
|
||||||
|
secret: (string | ((request: any, decodedToken: object, callback: ISocketCallback) => void));
|
||||||
|
|
||||||
|
decodedPropertyName?: string;
|
||||||
|
auth_header_required?: boolean;
|
||||||
|
handshake?: boolean;
|
||||||
|
required?: boolean;
|
||||||
|
timeout?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function authorize(options: IOptions/*, onConnection: Function*/): ISocketIOMiddleware;
|
||||||
|
|
||||||
|
interface UnauthorizedError extends Error {
|
||||||
|
readonly message: string;
|
||||||
|
readonly inner: object;
|
||||||
|
readonly data: { message: string, code: string, type: 'UnauthorizedError' }
|
||||||
|
}
|
||||||
|
|
||||||
|
var UnauthorizedError: {
|
||||||
|
prototype: UnauthorizedError;
|
||||||
|
new (code: string, error: { message: string }): UnauthorizedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an augmented version of the SocketIO.Server.
|
||||||
|
* It knows the 'authenticated' event and should be extended in future.
|
||||||
|
* @see SocketIO.Server
|
||||||
|
*/
|
||||||
|
export interface JWTServer extends SocketIO.Server {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event gets fired when a new connection is authenticated via JWT.
|
||||||
|
* @param event The event being fired: 'authenticated'
|
||||||
|
* @param listener A listener that should take one parameter of type Socket
|
||||||
|
* @return The default '/' Namespace
|
||||||
|
*/
|
||||||
|
on(event: ('authenticated' | string), listener: (socket: SocketIO.Socket) => void): SocketIO.Namespace;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user