mirror of
https://github.com/Thream/socketio-jwt.git
synced 2024-07-21 09:38:31 +02:00
style: run npm run format
This commit is contained in:
parent
6ea9d6f933
commit
243a598f37
18
src/index.ts
18
src/index.ts
@ -2,9 +2,9 @@ import jwt from 'jsonwebtoken'
|
|||||||
|
|
||||||
class UnauthorizedError extends Error {
|
class UnauthorizedError extends Error {
|
||||||
public inner: { message: string }
|
public inner: { message: string }
|
||||||
public data: { message: string; code: string; type: 'UnauthorizedError' }
|
public data: { message: string, code: string, type: 'UnauthorizedError' }
|
||||||
|
|
||||||
constructor(code: string, error: { message: string }) {
|
constructor (code: string, error: { message: string }) {
|
||||||
super(error.message)
|
super(error.message)
|
||||||
this.message = error.message
|
this.message = error.message
|
||||||
this.inner = error
|
this.inner = error
|
||||||
@ -17,7 +17,7 @@ class UnauthorizedError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function noQsMethod(options: any) {
|
function noQsMethod (options: any) {
|
||||||
const defaults = { required: true }
|
const defaults = { required: true }
|
||||||
options = Object.assign(defaults, options)
|
options = Object.assign(defaults, options)
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ function noQsMethod(options: any) {
|
|||||||
if (server.$emit) {
|
if (server.$emit) {
|
||||||
server.$emit('authenticated', socket)
|
server.$emit('authenticated', socket)
|
||||||
} else {
|
} else {
|
||||||
//try getting the current namespace otherwise fallback to all sockets.
|
// try getting the current namespace otherwise fallback to all sockets.
|
||||||
const namespace =
|
const namespace =
|
||||||
(server.nsps && socket.nsp && server.nsps[socket.nsp.name]) ||
|
(server.nsps && socket.nsp && server.nsps[socket.nsp.name]) ||
|
||||||
server.sockets
|
server.sockets
|
||||||
@ -138,7 +138,7 @@ function noQsMethod(options: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function authorize(options: any) {
|
export function authorize (options: any) {
|
||||||
options = Object.assign(
|
options = Object.assign(
|
||||||
{
|
{
|
||||||
decodedPropertyName: 'decoded_token',
|
decodedPropertyName: 'decoded_token',
|
||||||
@ -190,8 +190,8 @@ export function authorize(options: any) {
|
|||||||
if (authorization_header) {
|
if (authorization_header) {
|
||||||
const parts = authorization_header.split(' ')
|
const parts = authorization_header.split(' ')
|
||||||
if (parts.length == 2) {
|
if (parts.length == 2) {
|
||||||
const scheme = parts[0],
|
const scheme = parts[0]
|
||||||
credentials = parts[1]
|
const credentials = parts[1]
|
||||||
|
|
||||||
if (scheme.toLowerCase() === 'bearer') {
|
if (scheme.toLowerCase() === 'bearer') {
|
||||||
token = credentials
|
token = credentials
|
||||||
@ -260,7 +260,7 @@ export function authorize(options: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSecret(request: any, secret: any, token: any, callback: Function) {
|
function getSecret (request: any, secret: any, token: any, callback: Function) {
|
||||||
if (typeof secret === 'function') {
|
if (typeof secret === 'function') {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return callback({
|
return callback({
|
||||||
@ -282,7 +282,7 @@ function getSecret(request: any, secret: any, token: any, callback: Function) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let decodedToken: any = jwt.decode(token, { complete: true })
|
const decodedToken: any = jwt.decode(token, { complete: true })
|
||||||
|
|
||||||
if (!decodedToken) {
|
if (!decodedToken) {
|
||||||
return callback({ code: 'invalid_token', message: 'jwt malformed' })
|
return callback({ code: 'invalid_token', message: 'jwt malformed' })
|
||||||
|
Loading…
Reference in New Issue
Block a user