@flink-app/bankid-plugin 0.12.1-alpha.23 → 0.12.1-alpha.25
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/dist/BankIdPluginOptions.d.ts +4 -2
- package/dist/functions/auth.d.ts +1 -0
- package/dist/functions/auth.js +1 -0
- package/dist/functions/getAuthStatus.js +3 -3
- package/dist/functions/getSignStatus.js +1 -1
- package/dist/functions/sign.d.ts +1 -0
- package/dist/functions/sign.js +1 -0
- package/dist/handlers/GetBankIdAuth.js +2 -12
- package/dist/handlers/GetBankIdSign.js +2 -12
- package/dist/handlers/PostBankIdAuth.js +4 -1
- package/dist/schemas/AuthInitiateReq.d.ts +1 -0
- package/dist/schemas/BankIdSession.d.ts +1 -0
- package/package.json +2 -2
- package/spec/bankid-plugin.spec.ts +5 -0
- package/spec/support/jasmine.json +7 -0
- package/src/BankIdPluginOptions.ts +4 -2
- package/src/functions/auth.ts +2 -0
- package/src/functions/getAuthStatus.ts +5 -5
- package/src/functions/getSignStatus.ts +1 -1
- package/src/functions/sign.ts +2 -0
- package/src/handlers/GetBankIdAuth.ts +6 -13
- package/src/handlers/GetBankIdSign.ts +6 -13
- package/src/handlers/PostBankIdAuth.ts +4 -1
- package/src/schemas/AuthInitiateReq.ts +3 -1
- package/src/schemas/BankIdSession.ts +1 -0
|
@@ -48,18 +48,20 @@ export interface BankIdPluginOptions {
|
|
|
48
48
|
* token. This will be relayed in the collect response to client.
|
|
49
49
|
* @param userData
|
|
50
50
|
* @param ip
|
|
51
|
+
* @param payload
|
|
51
52
|
* @returns
|
|
52
53
|
*/
|
|
53
|
-
onAuthSuccess: (userData: BankIdUserData, ip?: string) => Promise<AuthSuccessCallbackResponse>;
|
|
54
|
+
onAuthSuccess: (userData: BankIdUserData, ip?: string, payload?: Record<string, any>) => Promise<AuthSuccessCallbackResponse>;
|
|
54
55
|
/**
|
|
55
56
|
* Callback invoked when BankID sign is successful.
|
|
56
57
|
* Callback must return an object containing user information and
|
|
57
58
|
* signature data. This will be relayed in the collect response to client.
|
|
58
59
|
* @param userData
|
|
59
60
|
* @param signature
|
|
61
|
+
* @param payload
|
|
60
62
|
* @returns
|
|
61
63
|
*/
|
|
62
|
-
onSignSuccess?: (userData: BankIdUserData, signature: BankIdSignature) => Promise<void>;
|
|
64
|
+
onSignSuccess?: (userData: BankIdUserData, signature: BankIdSignature, payload?: Record<string, any>) => Promise<void>;
|
|
63
65
|
/**
|
|
64
66
|
* For how long to keep sessions in database.
|
|
65
67
|
* This has nothing to do with how long the user is logged in, only
|
package/dist/functions/auth.d.ts
CHANGED
package/dist/functions/auth.js
CHANGED
|
@@ -51,7 +51,7 @@ function getAuthStatus(ctx, options) {
|
|
|
51
51
|
case 1:
|
|
52
52
|
session = _c.sent();
|
|
53
53
|
if (!session) {
|
|
54
|
-
throw
|
|
54
|
+
throw (0, flink_1.notFound)("BankId session not found");
|
|
55
55
|
}
|
|
56
56
|
if (!(session.status === "complete")) return [3 /*break*/, 5];
|
|
57
57
|
if (!!session.user) return [3 /*break*/, 3];
|
|
@@ -59,8 +59,8 @@ function getAuthStatus(ctx, options) {
|
|
|
59
59
|
return [4 /*yield*/, ctx.repos.bankIdSessionRepo.failSession(orderRef, "USER_DATA_MISSING")];
|
|
60
60
|
case 2:
|
|
61
61
|
_c.sent();
|
|
62
|
-
throw
|
|
63
|
-
case 3: return [4 /*yield*/, pluginOptions.onAuthSuccess(session.user, (_a = session.device) === null || _a === void 0 ? void 0 : _a.ipAddress)];
|
|
62
|
+
throw (0, flink_1.internalServerError)("Session is completed but user data is missing");
|
|
63
|
+
case 3: return [4 /*yield*/, pluginOptions.onAuthSuccess(session.user, (_a = session.device) === null || _a === void 0 ? void 0 : _a.ipAddress, session.payload)];
|
|
64
64
|
case 4:
|
|
65
65
|
authCallbackRes = _c.sent();
|
|
66
66
|
return [2 /*return*/, {
|
|
@@ -73,7 +73,7 @@ function getSignStatus(ctx, options) {
|
|
|
73
73
|
throw new Error("Signature data is missing");
|
|
74
74
|
case 5:
|
|
75
75
|
// Invoke host app callback
|
|
76
|
-
return [4 /*yield*/, pluginOptions.onSignSuccess(session.user, session.signature)];
|
|
76
|
+
return [4 /*yield*/, pluginOptions.onSignSuccess(session.user, session.signature, session.payload)];
|
|
77
77
|
case 6:
|
|
78
78
|
// Invoke host app callback
|
|
79
79
|
_b.sent();
|
package/dist/functions/sign.d.ts
CHANGED
package/dist/functions/sign.js
CHANGED
|
@@ -44,28 +44,18 @@ exports.Route = {
|
|
|
44
44
|
method: flink_1.HttpMethod.get,
|
|
45
45
|
};
|
|
46
46
|
var GetBankIdAuth = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
47
|
-
var orderRef, authStatus
|
|
47
|
+
var orderRef, authStatus;
|
|
48
48
|
var ctx = _b.ctx, req = _b.req;
|
|
49
49
|
return __generator(this, function (_c) {
|
|
50
50
|
switch (_c.label) {
|
|
51
51
|
case 0:
|
|
52
52
|
orderRef = req.params.orderRef;
|
|
53
|
-
_c.label = 1;
|
|
54
|
-
case 1:
|
|
55
|
-
_c.trys.push([1, 3, , 4]);
|
|
56
53
|
return [4 /*yield*/, (0, getAuthStatus_1.getAuthStatus)(ctx, { orderRef: orderRef })];
|
|
57
|
-
case
|
|
54
|
+
case 1:
|
|
58
55
|
authStatus = _c.sent();
|
|
59
56
|
return [2 /*return*/, {
|
|
60
57
|
data: authStatus,
|
|
61
58
|
}];
|
|
62
|
-
case 3:
|
|
63
|
-
error_1 = _c.sent();
|
|
64
|
-
if (error_1.message === "BankId session not found") {
|
|
65
|
-
return [2 /*return*/, (0, flink_1.notFound)("BankId session not found")];
|
|
66
|
-
}
|
|
67
|
-
return [2 /*return*/, (0, flink_1.internalServerError)(error_1.message || "Failed to get auth status")];
|
|
68
|
-
case 4: return [2 /*return*/];
|
|
69
59
|
}
|
|
70
60
|
});
|
|
71
61
|
}); };
|
|
@@ -44,28 +44,18 @@ exports.Route = {
|
|
|
44
44
|
method: flink_1.HttpMethod.get,
|
|
45
45
|
};
|
|
46
46
|
var GetBankIdSign = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
47
|
-
var orderRef, signStatus
|
|
47
|
+
var orderRef, signStatus;
|
|
48
48
|
var ctx = _b.ctx, req = _b.req;
|
|
49
49
|
return __generator(this, function (_c) {
|
|
50
50
|
switch (_c.label) {
|
|
51
51
|
case 0:
|
|
52
52
|
orderRef = req.params.orderRef;
|
|
53
|
-
_c.label = 1;
|
|
54
|
-
case 1:
|
|
55
|
-
_c.trys.push([1, 3, , 4]);
|
|
56
53
|
return [4 /*yield*/, (0, getSignStatus_1.getSignStatus)(ctx, { orderRef: orderRef })];
|
|
57
|
-
case
|
|
54
|
+
case 1:
|
|
58
55
|
signStatus = _c.sent();
|
|
59
56
|
return [2 /*return*/, {
|
|
60
57
|
data: signStatus,
|
|
61
58
|
}];
|
|
62
|
-
case 3:
|
|
63
|
-
error_1 = _c.sent();
|
|
64
|
-
if (error_1.message === "BankId session not found") {
|
|
65
|
-
return [2 /*return*/, (0, flink_1.notFound)("BankId session not found")];
|
|
66
|
-
}
|
|
67
|
-
return [2 /*return*/, (0, flink_1.internalServerError)(error_1.message || "Failed to get sign status")];
|
|
68
|
-
case 4: return [2 /*return*/];
|
|
69
59
|
}
|
|
70
60
|
});
|
|
71
61
|
}); };
|
|
@@ -56,7 +56,10 @@ var PostBankIdAuth = function (_a) { return __awaiter(void 0, [_a], void 0, func
|
|
|
56
56
|
return [4 /*yield*/, options.onGetEndUserIp(req)];
|
|
57
57
|
case 2:
|
|
58
58
|
clientIp = _c.sent();
|
|
59
|
-
return [4 /*yield*/, (0, auth_1.auth)(ctx, {
|
|
59
|
+
return [4 /*yield*/, (0, auth_1.auth)(ctx, {
|
|
60
|
+
endUserIp: clientIp,
|
|
61
|
+
payload: req.body.payload
|
|
62
|
+
})];
|
|
60
63
|
case 3:
|
|
61
64
|
authResponse = _c.sent();
|
|
62
65
|
return [2 /*return*/, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/bankid-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.25",
|
|
4
4
|
"description": "Flink plugin for Swedish BankID authentication and document signing",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --preserve-symlinks -r ts-node/register -- node_modules/jasmine/bin/jasmine --config=./spec/support/jasmine.json",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"tsc-watch": "^4.2.9",
|
|
33
33
|
"typescript": "5.4.5"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "44a1bf5bb2b2c7d18e4cecc06da626700639f82a"
|
|
36
36
|
}
|
|
@@ -57,9 +57,10 @@ export interface BankIdPluginOptions {
|
|
|
57
57
|
* token. This will be relayed in the collect response to client.
|
|
58
58
|
* @param userData
|
|
59
59
|
* @param ip
|
|
60
|
+
* @param payload
|
|
60
61
|
* @returns
|
|
61
62
|
*/
|
|
62
|
-
onAuthSuccess: (userData: BankIdUserData, ip?: string) => Promise<AuthSuccessCallbackResponse>;
|
|
63
|
+
onAuthSuccess: (userData: BankIdUserData, ip?: string, payload?: Record<string, any>) => Promise<AuthSuccessCallbackResponse>;
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* Callback invoked when BankID sign is successful.
|
|
@@ -67,9 +68,10 @@ export interface BankIdPluginOptions {
|
|
|
67
68
|
* signature data. This will be relayed in the collect response to client.
|
|
68
69
|
* @param userData
|
|
69
70
|
* @param signature
|
|
71
|
+
* @param payload
|
|
70
72
|
* @returns
|
|
71
73
|
*/
|
|
72
|
-
onSignSuccess?: (userData: BankIdUserData, signature: BankIdSignature) => Promise<void>;
|
|
74
|
+
onSignSuccess?: (userData: BankIdUserData, signature: BankIdSignature, payload?: Record<string, any>) => Promise<void>;
|
|
73
75
|
|
|
74
76
|
/**
|
|
75
77
|
* For how long to keep sessions in database.
|
package/src/functions/auth.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { checkAndGenerateQr } from "../bankid-utils";
|
|
|
5
5
|
|
|
6
6
|
export interface AuthOptions {
|
|
7
7
|
endUserIp?: string;
|
|
8
|
+
payload?: Record<string, any>;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface AuthResponse {
|
|
@@ -55,6 +56,7 @@ export async function auth(ctx: BankIdInternalCtx, options: AuthOptions = {}): P
|
|
|
55
56
|
createdAt: new Date(),
|
|
56
57
|
ip: clientIp,
|
|
57
58
|
autoStartToken: authResponse.autoStartToken,
|
|
59
|
+
payload: options.payload,
|
|
58
60
|
qr: {
|
|
59
61
|
qrStartToken: authResponse.qrStartToken,
|
|
60
62
|
qrStartSecret: authResponse.qrStartSecret,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { log } from "@flink-app/flink";
|
|
1
|
+
import { internalServerError, log, notFound } from "@flink-app/flink";
|
|
2
2
|
import { BankIdInternalCtx } from "../BankIdInternalContext";
|
|
3
3
|
|
|
4
4
|
export interface AuthStatusOptions {
|
|
@@ -23,7 +23,7 @@ export async function getAuthStatus(ctx: BankIdInternalCtx, options: AuthStatusO
|
|
|
23
23
|
const session = await ctx.repos.bankIdSessionRepo.getSession(orderRef, "auth");
|
|
24
24
|
|
|
25
25
|
if (!session) {
|
|
26
|
-
throw
|
|
26
|
+
throw notFound("BankId session not found");
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// Session is completed, create tokens
|
|
@@ -32,7 +32,7 @@ export async function getAuthStatus(ctx: BankIdInternalCtx, options: AuthStatusO
|
|
|
32
32
|
if (!session.user) {
|
|
33
33
|
log.error(`Auth session ${orderRef} marked complete but user data is missing`);
|
|
34
34
|
await ctx.repos.bankIdSessionRepo.failSession(orderRef, "USER_DATA_MISSING");
|
|
35
|
-
throw
|
|
35
|
+
throw internalServerError("Session is completed but user data is missing");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// Invoke host app callback which will (probably) do the following:
|
|
@@ -40,7 +40,7 @@ export async function getAuthStatus(ctx: BankIdInternalCtx, options: AuthStatusO
|
|
|
40
40
|
// - Create user if not found
|
|
41
41
|
// - Create access token
|
|
42
42
|
// If host app throws for example notFound error, this will be propagated as response here
|
|
43
|
-
const authCallbackRes = await pluginOptions.onAuthSuccess(session.user, session.device?.ipAddress);
|
|
43
|
+
const authCallbackRes = await pluginOptions.onAuthSuccess(session.user, session.device?.ipAddress, session.payload);
|
|
44
44
|
|
|
45
45
|
return {
|
|
46
46
|
status: "complete",
|
|
@@ -65,4 +65,4 @@ export async function getAuthStatus(ctx: BankIdInternalCtx, options: AuthStatusO
|
|
|
65
65
|
hintCode: session.hintCode || undefined,
|
|
66
66
|
qr: session.qr?.qr,
|
|
67
67
|
};
|
|
68
|
-
}
|
|
68
|
+
}
|
|
@@ -48,7 +48,7 @@ export async function getSignStatus(ctx: BankIdInternalCtx, options: SignStatusO
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// Invoke host app callback
|
|
51
|
-
await pluginOptions.onSignSuccess(session.user, session.signature);
|
|
51
|
+
await pluginOptions.onSignSuccess(session.user, session.signature, session.payload);
|
|
52
52
|
|
|
53
53
|
return {
|
|
54
54
|
status: "complete",
|
package/src/functions/sign.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface SignOptions {
|
|
|
7
7
|
userVisibleData: string;
|
|
8
8
|
userNonVisibleData?: string;
|
|
9
9
|
endUserIp?: string;
|
|
10
|
+
payload?: Record<string, any>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface SignResponse {
|
|
@@ -69,6 +70,7 @@ export async function sign(ctx: BankIdInternalCtx, options: SignOptions): Promis
|
|
|
69
70
|
createdAt: new Date(),
|
|
70
71
|
ip: clientIp,
|
|
71
72
|
autoStartToken: signResponse.autoStartToken,
|
|
73
|
+
payload: options.payload,
|
|
72
74
|
qr: {
|
|
73
75
|
qrStartToken: signResponse.qrStartToken,
|
|
74
76
|
qrStartSecret: signResponse.qrStartSecret,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Handler, HttpMethod, RouteProps
|
|
1
|
+
import { Handler, HttpMethod, RouteProps } from "@flink-app/flink";
|
|
2
2
|
import { BankIdInternalCtx } from "../BankIdInternalContext";
|
|
3
|
-
import AuthStatusRes from "../schemas/AuthStatusRes";
|
|
4
3
|
import { getAuthStatus } from "../functions/getAuthStatus";
|
|
4
|
+
import AuthStatusRes from "../schemas/AuthStatusRes";
|
|
5
5
|
|
|
6
6
|
export const Route: RouteProps = {
|
|
7
7
|
path: "/bankid/auth/:orderRef",
|
|
@@ -11,18 +11,11 @@ export const Route: RouteProps = {
|
|
|
11
11
|
const GetBankIdAuth: Handler<BankIdInternalCtx, any, AuthStatusRes, { orderRef: string }> = async ({ ctx, req }) => {
|
|
12
12
|
const { orderRef } = req.params;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const authStatus = await getAuthStatus(ctx, { orderRef });
|
|
14
|
+
const authStatus = await getAuthStatus(ctx, { orderRef });
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} catch (error: any) {
|
|
21
|
-
if (error.message === "BankId session not found") {
|
|
22
|
-
return notFound("BankId session not found");
|
|
23
|
-
}
|
|
24
|
-
return internalServerError(error.message || "Failed to get auth status");
|
|
25
|
-
}
|
|
16
|
+
return {
|
|
17
|
+
data: authStatus,
|
|
18
|
+
};
|
|
26
19
|
};
|
|
27
20
|
|
|
28
21
|
export default GetBankIdAuth;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Handler, HttpMethod, RouteProps
|
|
1
|
+
import { Handler, HttpMethod, RouteProps } from "@flink-app/flink";
|
|
2
2
|
import { BankIdInternalCtx } from "../BankIdInternalContext";
|
|
3
|
-
import SignStatusRes from "../schemas/SignStatusRes";
|
|
4
3
|
import { getSignStatus } from "../functions/getSignStatus";
|
|
4
|
+
import SignStatusRes from "../schemas/SignStatusRes";
|
|
5
5
|
|
|
6
6
|
export const Route: RouteProps = {
|
|
7
7
|
path: "/bankid/sign/:orderRef",
|
|
@@ -11,18 +11,11 @@ export const Route: RouteProps = {
|
|
|
11
11
|
const GetBankIdSign: Handler<BankIdInternalCtx, any, SignStatusRes, { orderRef: string }> = async ({ ctx, req }) => {
|
|
12
12
|
const { orderRef } = req.params;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const signStatus = await getSignStatus(ctx, { orderRef });
|
|
14
|
+
const signStatus = await getSignStatus(ctx, { orderRef });
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} catch (error: any) {
|
|
21
|
-
if (error.message === "BankId session not found") {
|
|
22
|
-
return notFound("BankId session not found");
|
|
23
|
-
}
|
|
24
|
-
return internalServerError(error.message || "Failed to get sign status");
|
|
25
|
-
}
|
|
16
|
+
return {
|
|
17
|
+
data: signStatus,
|
|
18
|
+
};
|
|
26
19
|
};
|
|
27
20
|
|
|
28
21
|
export default GetBankIdSign;
|
|
@@ -15,7 +15,10 @@ const PostBankIdAuth: Handler<BankIdInternalCtx, AuthInitiateReq, AuthInitiateRe
|
|
|
15
15
|
try {
|
|
16
16
|
let clientIp = await options.onGetEndUserIp(req);
|
|
17
17
|
|
|
18
|
-
const authResponse = await auth(ctx, {
|
|
18
|
+
const authResponse = await auth(ctx, {
|
|
19
|
+
endUserIp: clientIp,
|
|
20
|
+
payload: req.body.payload
|
|
21
|
+
});
|
|
19
22
|
|
|
20
23
|
return {
|
|
21
24
|
data: authResponse,
|