Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
43dc2eca
Commit
43dc2eca
authored
Sep 16, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check token and role
parent
8b4f9441
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
authhook/checkClientRole.js
+84
-0
No files found.
authhook/checkClientRole.js
0 → 100644
View file @
43dc2eca
var
jwt
=
require
(
'jsonwebtoken'
)
var
config
=
require
(
'config'
)
function
checkRealDB
(
token
,
cb
)
{
const
verifyOptions
=
{
algorithms
:
[
'RS256'
]
};
jwt
.
verify
(
token
,
config
.
get
(
'pubca'
),
verifyOptions
,
(
err
,
decoded
)
=>
{
cb
(
err
,
decoded
)
})
}
module
.
exports
.
checkRealDB
=
checkRealDB
function
getRole
(
token
,
cb
)
{
var
secret
=
'nexpie'
jwt
.
verify
(
token
,
secret
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
// console.log(err)
cb
(
false
)
}
else
{
// console.log(decoded)
cb
(
decoded
)
}
})
}
module
.
exports
.
getRole
=
getRole
function
signRole
(
req
,
res
)
{
var
secret
=
'nexpie'
if
(
req
.
body
.
scope
&&
req
.
body
.
exp
)
{
const
signOptions
=
{
expiresIn
:
getExp
(
req
.
body
.
exp
)
}
var
payload
=
req
.
body
delete
payload
[
'exp'
]
res
.
send
(
jwt
.
sign
(
payload
,
secret
,
signOptions
))
}
else
{
res
.
send
(
'role not complete'
)
}
}
module
.
exports
.
signRole
=
signRole
function
getExp
(
expires
)
{
var
exp
if
(
expires
.
endsWith
(
'y'
))
{
exp
=
getYears
(
expires
.
split
(
'y'
)[
0
])
}
else
if
(
expires
.
endsWith
(
'm'
))
{
exp
=
getMonths
(
expires
.
split
(
'm'
)[
0
])
}
else
if
(
expires
.
endsWith
(
'd'
))
{
exp
=
expires
.
split
(
'd'
)[
0
]
+
'd'
}
else
if
(
expires
.
endsWith
(
'h'
))
{
exp
=
expires
.
split
(
'h'
)[
0
]
+
'h'
}
else
if
(
expires
.
endsWith
(
'mi'
))
{
exp
=
getMinutes
(
expires
.
split
(
'mi'
)[
0
])
}
else
if
(
expires
.
endsWith
(
's'
))
{
exp
=
getSeconds
(
expires
.
split
(
's'
)[
0
])
}
else
exp
=
getYears
(
10
)
return
exp
}
function
getMonths
(
d
)
{
return
(
d
*
30
)
+
'd'
}
function
getYears
(
m
)
{
return
(
m
*
30
*
12
)
+
'd'
}
function
getMinutes
(
mi
)
{
return
(
mi
*
1000
*
60
)
+
'ms'
}
function
getSeconds
(
ms
)
{
return
(
ms
*
1000
)
+
'ms'
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment