@apiverve/jwtdecoder 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/examples/basic.js +38 -0
- package/index.d.ts +42 -0
- package/index.js +124 -0
- package/package.json +35 -0
- package/tmp/build.dat +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 APIVerve, and EvlarSoft LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# JWT Decoder API
|
|
2
|
+
|
|
3
|
+
JWT Decoder decodes JWT tokens to reveal header and payload information without performing signature verification.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
This is a Javascript Wrapper for the [JWT Decoder API](https://apiverve.com/marketplace/jwtdecoder)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Using npm:
|
|
16
|
+
```shell
|
|
17
|
+
npm install @apiverve/jwtdecoder
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Using yarn:
|
|
21
|
+
```shell
|
|
22
|
+
yarn add @apiverve/jwtdecoder
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
Before using the JWT Decoder API client, you have to setup your account and obtain your API Key.
|
|
30
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
[Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
|
|
37
|
+
|
|
38
|
+
The JWT Decoder API documentation is found here: [https://docs.apiverve.com/ref/jwtdecoder](https://docs.apiverve.com/ref/jwtdecoder).
|
|
39
|
+
You can find parameters, example responses, and status codes documented here.
|
|
40
|
+
|
|
41
|
+
### Setup
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
const jwtdecoderAPI = require('@apiverve/jwtdecoder');
|
|
45
|
+
const api = new jwtdecoderAPI({
|
|
46
|
+
api_key: '[YOUR_API_KEY]'
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### Perform Request
|
|
57
|
+
|
|
58
|
+
Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var query = {
|
|
62
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
api.execute(query, function (error, data) {
|
|
66
|
+
if (error) {
|
|
67
|
+
return console.error(error);
|
|
68
|
+
} else {
|
|
69
|
+
console.log(data);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### Using Promises
|
|
77
|
+
|
|
78
|
+
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
var query = {
|
|
82
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
api.execute(query)
|
|
86
|
+
.then(data => {
|
|
87
|
+
console.log(data);
|
|
88
|
+
})
|
|
89
|
+
.catch(error => {
|
|
90
|
+
console.error(error);
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### Using Async/Await
|
|
97
|
+
|
|
98
|
+
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
async function makeRequest() {
|
|
102
|
+
var query = {
|
|
103
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const data = await api.execute(query);
|
|
108
|
+
console.log(data);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Example Response
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"status": "ok",
|
|
122
|
+
"error": null,
|
|
123
|
+
"data": {
|
|
124
|
+
"header": {
|
|
125
|
+
"alg": "HS256",
|
|
126
|
+
"typ": "JWT"
|
|
127
|
+
},
|
|
128
|
+
"payload": {
|
|
129
|
+
"sub": "1234567890",
|
|
130
|
+
"name": "John Doe",
|
|
131
|
+
"iat": 1516239022
|
|
132
|
+
},
|
|
133
|
+
"signature": "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
|
|
134
|
+
"isExpired": false,
|
|
135
|
+
"expiresAt": null,
|
|
136
|
+
"warning": "This API only decodes JWT tokens. It does NOT verify signatures. Do not use for security validation."
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Customer Support
|
|
144
|
+
|
|
145
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact).
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Updates
|
|
150
|
+
|
|
151
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Legal
|
|
156
|
+
|
|
157
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms) and all legal documents and agreements.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
Licensed under the The MIT License (MIT)
|
|
163
|
+
|
|
164
|
+
Copyright (©) 2025 APIVerve, and EvlarSoft LLC
|
|
165
|
+
|
|
166
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
167
|
+
|
|
168
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
169
|
+
|
|
170
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Example - JWT Decoder API
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the JWT Decoder API.
|
|
5
|
+
* Make sure to set your API key in the .env file or replace '[YOUR_API_KEY]' below.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
require('dotenv').config();
|
|
9
|
+
const jwtdecoderAPI = require('../index.js');
|
|
10
|
+
|
|
11
|
+
// Initialize the API client
|
|
12
|
+
const api = new jwtdecoderAPI({
|
|
13
|
+
api_key: process.env.API_KEY || '[YOUR_API_KEY]'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Example query
|
|
17
|
+
var query = {
|
|
18
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Make the API request using callback
|
|
22
|
+
console.log('Making request to JWT Decoder API...\n');
|
|
23
|
+
|
|
24
|
+
api.execute(query, function (error, data) {
|
|
25
|
+
if (error) {
|
|
26
|
+
console.error('Error occurred:');
|
|
27
|
+
if (error.error) {
|
|
28
|
+
console.error('Message:', error.error);
|
|
29
|
+
console.error('Status:', error.status);
|
|
30
|
+
} else {
|
|
31
|
+
console.error(JSON.stringify(error, null, 2));
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log('Response:');
|
|
37
|
+
console.log(JSON.stringify(data, null, 2));
|
|
38
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '@apiverve/jwtdecoder' {
|
|
2
|
+
export interface jwtdecoderOptions {
|
|
3
|
+
api_key: string;
|
|
4
|
+
secure?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface jwtdecoderResponse {
|
|
8
|
+
status: string;
|
|
9
|
+
error: string | null;
|
|
10
|
+
data: JWTDecoderData;
|
|
11
|
+
code?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
interface JWTDecoderData {
|
|
16
|
+
header: Header;
|
|
17
|
+
payload: Payload;
|
|
18
|
+
signature: string;
|
|
19
|
+
isExpired: boolean;
|
|
20
|
+
expiresAt: null;
|
|
21
|
+
warning: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Header {
|
|
25
|
+
alg: string;
|
|
26
|
+
typ: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface Payload {
|
|
30
|
+
sub: string;
|
|
31
|
+
name: string;
|
|
32
|
+
iat: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default class jwtdecoderWrapper {
|
|
36
|
+
constructor(options: jwtdecoderOptions);
|
|
37
|
+
|
|
38
|
+
execute(callback: (error: any, data: jwtdecoderResponse | null) => void): Promise<jwtdecoderResponse>;
|
|
39
|
+
execute(query: Record<string, any>, callback: (error: any, data: jwtdecoderResponse | null) => void): Promise<jwtdecoderResponse>;
|
|
40
|
+
execute(query?: Record<string, any>): Promise<jwtdecoderResponse>;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
class jwtdecoderWrapper {
|
|
4
|
+
|
|
5
|
+
constructor(options) {
|
|
6
|
+
if (!options || typeof options !== 'object') {
|
|
7
|
+
throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/jwtdecoder');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { api_key, secure = true } = options;
|
|
11
|
+
|
|
12
|
+
if (!api_key || typeof api_key !== 'string') {
|
|
13
|
+
throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Validate API key format (GUID or alphanumeric with hyphens)
|
|
17
|
+
const apiKeyPattern = /^[a-zA-Z0-9-]+$/;
|
|
18
|
+
if (!apiKeyPattern.test(api_key)) {
|
|
19
|
+
throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens. Get your API key at: https://apiverve.com');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check minimum length (GUIDs are typically 36 chars with hyphens, or 32 without)
|
|
23
|
+
const trimmedKey = api_key.replace(/-/g, '');
|
|
24
|
+
if (trimmedKey.length < 32) {
|
|
25
|
+
throw new Error('Invalid API key. API key appears to be too short. Get your API key at: https://apiverve.com');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof secure !== 'boolean') {
|
|
29
|
+
throw new Error('Secure parameter must be a boolean value.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.APIKey = api_key;
|
|
33
|
+
this.IsSecure = secure;
|
|
34
|
+
|
|
35
|
+
// secure is deprecated, all requests must be made over HTTPS
|
|
36
|
+
this.baseURL = 'https://api.apiverve.com/v1/jwtdecoder';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async execute(query, callback) {
|
|
40
|
+
// Handle different argument patterns
|
|
41
|
+
if(arguments.length === 0) {
|
|
42
|
+
// execute() - no args
|
|
43
|
+
query = {};
|
|
44
|
+
callback = null;
|
|
45
|
+
} else if(arguments.length === 1) {
|
|
46
|
+
if (typeof query === 'function') {
|
|
47
|
+
// execute(callback)
|
|
48
|
+
callback = query;
|
|
49
|
+
query = {};
|
|
50
|
+
} else {
|
|
51
|
+
// execute(query)
|
|
52
|
+
callback = null;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// execute(query, callback)
|
|
56
|
+
if (!query || typeof query !== 'object') {
|
|
57
|
+
throw new Error('Query parameters must be provided as an object.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var requiredParams = ["token"];
|
|
62
|
+
if (requiredParams.length > 0) {
|
|
63
|
+
for (var i = 0; i < requiredParams.length; i++) {
|
|
64
|
+
if (!query[requiredParams[i]]) {
|
|
65
|
+
throw new Error(`Required parameter [${requiredParams[i]}] is missing. See documentation: https://docs.apiverve.com/ref/jwtdecoder`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const method = 'POST';
|
|
71
|
+
const url = method === 'POST' ? this.baseURL : this.constructURL(query);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const response = await axios({
|
|
75
|
+
method,
|
|
76
|
+
url,
|
|
77
|
+
headers: {
|
|
78
|
+
'Content-Type': 'application/json',
|
|
79
|
+
'x-api-key': this.APIKey,
|
|
80
|
+
'auth-mode': 'npm-package'
|
|
81
|
+
},
|
|
82
|
+
data: method === 'POST' ? query : undefined
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const data = response.data;
|
|
86
|
+
if (callback) callback(null, data);
|
|
87
|
+
return data;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
let apiError;
|
|
90
|
+
|
|
91
|
+
if (error.response && error.response.data) {
|
|
92
|
+
apiError = error.response.data;
|
|
93
|
+
} else if (error.message) {
|
|
94
|
+
apiError = { error: error.message, status: 'error' };
|
|
95
|
+
} else {
|
|
96
|
+
apiError = { error: 'An unknown error occurred', status: 'error' };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (callback) {
|
|
100
|
+
callback(apiError, null);
|
|
101
|
+
return; // Don't throw if callback is provided
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw apiError;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
constructURL(query) {
|
|
109
|
+
let url = this.baseURL;
|
|
110
|
+
|
|
111
|
+
if(query && typeof query === 'object')
|
|
112
|
+
{
|
|
113
|
+
if (Object.keys(query).length > 0) {
|
|
114
|
+
const queryString = Object.keys(query)
|
|
115
|
+
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
|
|
116
|
+
.join('&');
|
|
117
|
+
url += `?${queryString}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return url;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = jwtdecoderWrapper;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apiverve/jwtdecoder",
|
|
3
|
+
"version": "1.1.12",
|
|
4
|
+
"description": "JWT Decoder decodes JWT tokens to reveal header and payload information without performing signature verification.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "mocha",
|
|
9
|
+
"example": "node examples/basic.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/apiverve/jwtdecoder-api.git",
|
|
14
|
+
"directory": "npm"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"jwt decoder", "token decoder", "jwt parser", "authentication token", "decode jwt"
|
|
18
|
+
],
|
|
19
|
+
"author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/apiverve/jwtdecoder-api/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://apiverve.com/marketplace/jwtdecoder?utm_source=npm",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"mocha": "^11.0.1",
|
|
27
|
+
"chai": "^5.1.2",
|
|
28
|
+
"dotenv": "^16.4.7"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"node-fetch": "^3.3.2",
|
|
32
|
+
"promise": "^8.3.0",
|
|
33
|
+
"axios": "1.13.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/tmp/build.dat
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#
|