-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df37b29
commit aded6b6
Showing
5 changed files
with
57 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const jwt = require('jsonwebtoken'); | ||
import {promisify} from 'util'; | ||
const signAsync = promisify(jwt.sign); | ||
const verifyAsync = promisify(jwt.verify); | ||
// Consider turn it to a binding | ||
const SECRET = 'secretforjwt'; | ||
|
||
export class JWTStrategy { | ||
// tslint:disable-next-line:no-any | ||
async authenticate(request: Request): Promise<any> { | ||
// A mock for sign in | ||
const payload = {admin: true}; | ||
await signAsync(payload, SECRET, {expiresIn: 300}); | ||
// const token = | ||
// request.body!.token || | ||
// request.query.token || | ||
// request.headers['x-access-token']; | ||
const token = 'not the right token'; | ||
|
||
if (token) { | ||
try { | ||
return await verifyAsync(token, SECRET); | ||
} catch (err) { | ||
if (err) return Promise.reject('Authentication failed!'); | ||
} | ||
} | ||
// should we return some meaningful message? | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters