Skip to content

Commit 0bdaeec

Browse files
author
SSOfy
committed
build 1.1.5
1 parent bc8d04a commit 0bdaeec

21 files changed

+44
-32
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 1.1.5 - 2023-02-28
4+
5+
* Compliance with Draft 1.30 signature style
6+
* Entity models directory restructure and fixes
7+
38
## 1.1.4 - 2023-02-11
49

510
* Added UserEntity missing properties

build/Client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var Client = /** @class */ (function () {
7878
else {
7979
this.cache = config.cacheStore;
8080
}
81-
this.signatureGenerator = new SignatureGenerator_1.SignatureGenerator(config);
81+
this.signatureGenerator = new SignatureGenerator_1.SignatureGenerator();
8282
}
8383
Client.prototype.verifyAuthentication = function (token) {
8484
return __awaiter(this, void 0, void 0, function () {
@@ -247,7 +247,7 @@ var Client = /** @class */ (function () {
247247
salt = Math.random().toString(36).substring(2, saltLength + 2);
248248
_b = (_a = Buffer).from;
249249
_d = (_c = JSON).stringify;
250-
return [4 /*yield*/, this.signatureGenerator.generate(url.href, fields, salt)];
250+
return [4 /*yield*/, this.signatureGenerator.generate(url.href, fields, this.config.secret, salt)];
251251
case 1:
252252
signature = _b.apply(_a, [_d.apply(_c, [_e.sent()]),
253253
'utf8']).toString('base64');

build/Models/APIResponse.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Token } from "./Token";
2-
import { UserEntity } from "./UserEntity";
2+
import { UserEntity } from "./Entities/UserEntity";
33
export interface APIResponse {
44
token?: Token;
55
user?: UserEntity;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { TokenEntity } from "./TokenEntity";
2+
export interface AuthResponseEntity {
3+
user: string;
4+
token?: TokenEntity;
5+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface TokenEntity {
2+
token: string;
3+
ttl: number;
4+
}

build/Models/Entities/TokenEntity.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
File renamed without changes.

build/Models/Entities/UserEntity.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

build/SignatureGenerator.d.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { Signature } from "./Models/Signature";
2-
import { ClientConfig } from "./ClientConfig";
32
export declare class SignatureGenerator {
4-
private readonly key;
5-
private readonly secret;
6-
constructor(config: ClientConfig);
7-
generate(url: string, params: any, salt?: string): Promise<Signature>;
3+
generate(url: string, params: any, secret: string, salt?: string): Promise<Signature>;
84
private getValues;
9-
private sha256;
5+
private hmac;
106
}

build/SignatureGenerator.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6262
exports.SignatureGenerator = void 0;
6363
var crypto = __importStar(require("crypto"));
6464
var SignatureGenerator = /** @class */ (function () {
65-
function SignatureGenerator(config) {
66-
this.key = config.key;
67-
this.secret = config.secret;
65+
function SignatureGenerator() {
6866
}
69-
SignatureGenerator.prototype.generate = function (url, params, salt) {
67+
SignatureGenerator.prototype.generate = function (url, params, secret, salt) {
7068
return __awaiter(this, void 0, void 0, function () {
71-
var path, toSign, hash, e_1;
69+
var path, toSign, hash;
7270
return __generator(this, function (_a) {
7371
switch (_a.label) {
7472
case 0:
75-
_a.trys.push([0, 2, , 3]);
7673
path = (new URL(url)).pathname;
77-
toSign = path + this.getValues(params).join('') + this.key + this.secret + (salt || '');
78-
return [4 /*yield*/, this.sha256(toSign)];
74+
toSign = path + this.getValues(params).join('') + (salt || '');
75+
return [4 /*yield*/, this.hmac(toSign, secret)];
7976
case 1:
8077
hash = _a.sent();
8178
return [2 /*return*/, {
8279
hash: hash,
8380
salt: salt
8481
}];
85-
case 2:
86-
e_1 = _a.sent();
87-
return [2 /*return*/, {}];
88-
case 3: return [2 /*return*/];
8982
}
9083
});
9184
});
@@ -108,17 +101,17 @@ var SignatureGenerator = /** @class */ (function () {
108101
}
109102
return values;
110103
};
111-
SignatureGenerator.prototype.sha256 = function (message) {
104+
SignatureGenerator.prototype.hmac = function (message, secret) {
112105
return __awaiter(this, void 0, void 0, function () {
113-
var msgBuffer, hashBuffer, hashArray;
106+
var msgBuffer, hmacBuffer, hashArray;
114107
return __generator(this, function (_a) {
115108
switch (_a.label) {
116109
case 0:
117110
msgBuffer = new TextEncoder().encode(message);
118-
return [4 /*yield*/, crypto.subtle.digest('SHA-256', msgBuffer)];
111+
return [4 /*yield*/, crypto.subtle.importKey('raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']).then(function (key) { return crypto.subtle.sign('HMAC', key, msgBuffer); })];
119112
case 1:
120-
hashBuffer = _a.sent();
121-
hashArray = Array.from(new Uint8Array(hashBuffer));
113+
hmacBuffer = _a.sent();
114+
hashArray = Array.from(new Uint8Array(hmacBuffer));
122115
return [2 /*return*/, hashArray.map(function (b) { return b.toString(16).padStart(2, '0'); }).join('')];
123116
}
124117
});

build/SignatureValidator.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ClientConfig } from ".";
22
export declare class SignatureValidator {
3+
private config;
34
private signatureGenerator;
45
constructor(config: ClientConfig);
56
verifyBase64Signature(url: string, params: any, signature: string): Promise<boolean>;

build/SignatureValidator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ exports.SignatureValidator = void 0;
4040
var _1 = require(".");
4141
var SignatureValidator = /** @class */ (function () {
4242
function SignatureValidator(config) {
43-
this.signatureGenerator = new _1.SignatureGenerator(config);
43+
this.config = config;
44+
this.signatureGenerator = new _1.SignatureGenerator();
4445
}
4546
SignatureValidator.prototype.verifyBase64Signature = function (url, params, signature) {
4647
return __awaiter(this, void 0, void 0, function () {
@@ -50,7 +51,7 @@ var SignatureValidator = /** @class */ (function () {
5051
case 0:
5152
_a.trys.push([0, 2, , 3]);
5253
decodedSignature = (JSON.parse(Buffer.from(signature, 'base64').toString('utf8')));
53-
return [4 /*yield*/, this.signatureGenerator.generate(url, params, decodedSignature.salt)];
54+
return [4 /*yield*/, this.signatureGenerator.generate(url, params, this.config.secret, decodedSignature.salt)];
5455
case 1:
5556
generatedSignature = _a.sent();
5657
return [2 /*return*/, generatedSignature.hash === decodedSignature.hash];

build/index.d.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export { NullStorage } from "./Storage/NullStorage";
88
export { APIResponse } from "./Models/APIResponse";
99
export { Signature } from "./Models/Signature";
1010
export { Token } from "./Models/Token";
11-
export { ClientEntity } from "./Models/ClientEntity";
12-
export { ScopeEntity } from "./Models/ScopeEntity";
13-
export { UserEntity } from "./Models/UserEntity";
11+
export { AuthResponseEntity } from "./Models/Entities/AuthResponseEntity";
12+
export { TokenEntity } from "./Models/Entities/TokenEntity";
13+
export { ClientEntity } from "./Models/Entities/ClientEntity";
14+
export { OTPOptionEntity } from "./Models/Entities/OTPOptionEntity";
15+
export { ScopeEntity } from "./Models/Entities/ScopeEntity";
16+
export { UserEntity } from "./Models/Entities/UserEntity";

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ssofy/node-sdk",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Official SSOfy Node.js SDK for instant and efficient API access.",
55
"keywords": [
66
"ssofy",

0 commit comments

Comments
 (0)