Skip to content
This repository was archived by the owner on Apr 8, 2023. It is now read-only.

Commit 54d8ffd

Browse files
first project
1 parent 3572885 commit 54d8ffd

9 files changed

+578
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.history
2+
node_modules
3+
package-lock.json

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Bruno Nascimento
3+
Copyright (c) 2020 Bruno Nascimento
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# `@buuhv/jwt-js`
2+
3+
JWT is a service class to your manage the sessions of your application
4+
5+
6+
## Getting started
7+
8+
`npm install @buuhv/jwt-js --save`
9+
10+
## Usage
11+
12+
```javascript
13+
import JWT from '@buuhv/jwt-js';
14+
15+
const jwtService = new JWT('SECRET_KEY', 'ISS');
16+
17+
//expires is optional and you can use any value inside object
18+
const newToken = jwtService.register({
19+
expires: new Date().getTime() 'optional'
20+
'OBJECT DATA'
21+
});
22+
23+
const isValid = jwtService.checkJWT('OBJECT WITH HEADERS OF REQUEST');
24+
if (isValid.status === false) console.log(isValid.message);
25+
26+
const jwtData = jwtService.data('OBJECT WITH HEADERS OF REQUEST');
27+
if (jwtData.status === true) console.log(jwtData.data);
28+
if (jwtData.status === false) console.log(jwtData.message);
29+
30+
```
31+
---
32+
33+
## Request Object with Headers Example
34+
35+
```
36+
req: {
37+
headers: {
38+
Authorization|authorization: 'Bearer ....'
39+
};
40+
}
41+
```
42+
43+
---
44+
45+
## Contributors
46+
47+
This module was extracted from `Crypto-Js` core. Please reffer to https://github.com/geeknection/jwt-js/contributors for the complete list of contributors.
48+
49+
## License
50+
The library is released under the MIT licence. For more information see `LICENSE`.

index.d.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as CryptoJS from 'crypto-js';
2+
declare type WordArray = CryptoJS.lib.WordArray;
3+
interface jwtProps {
4+
enc: {
5+
Utf8: {
6+
stringify(wordArray: WordArray): string;
7+
parse(str: string): WordArray;
8+
};
9+
Base64: {
10+
stringify(wordArray: WordArray): string;
11+
parse(str: string): WordArray;
12+
};
13+
};
14+
}
15+
interface req {
16+
headers: {
17+
Authorization?: string;
18+
authorization?: string;
19+
};
20+
}
21+
interface checkJWT {
22+
status: boolean;
23+
message?: string;
24+
}
25+
interface dataJWT {
26+
status: boolean;
27+
data?: any;
28+
message?: string;
29+
}
30+
/**
31+
* @todo Classe de controle de sessão onde pode ser gerado um JWT e validar o mesmo
32+
* @todo Depende do módulo CryptoJS - [npm i --save crypto-js]
33+
* @author Bruno Nascimento <[email protected]>
34+
*/
35+
declare class JWT {
36+
props: jwtProps;
37+
ISS: string;
38+
SECRET_KEY: string;
39+
constructor(SECRET_KEY: string, ISS: string);
40+
/**
41+
* @todo Constroi o cabeçalho do JWT
42+
* @returns {String} - base64
43+
*/
44+
buildHeader: () => string;
45+
/**
46+
* @todo Constroi o payload/corpo(onde ficam os dados utilizados do jwt como user_id, tempo de expiração)
47+
* @returns {String} - base64
48+
*/
49+
buildPayload: (params: object) => string;
50+
/**
51+
* @todo Constroi a assinatura do JWT
52+
* @returns {String} - base64
53+
*/
54+
buildSignature: (prev_token: string) => string;
55+
/**
56+
* @todo Verifica se o token é valido
57+
* @param {req} - dados da requisição
58+
* @returns {Object} - status e o conteúdo
59+
*/
60+
checkJWT: (req: req) => checkJWT;
61+
/**
62+
* @todo Retorna os dados contidos no JWT
63+
* @param {req} - dados da requisição
64+
* @returns {Object} - status e conteúdo
65+
*/
66+
data: (req: req) => dataJWT;
67+
/**
68+
* Registra um JWT
69+
* @return String
70+
*/
71+
register: (params?: object) => string;
72+
}
73+
export default JWT;

index.js

+199
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)