@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.
@@ -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
@@ -1,6 +1,7 @@
1
1
  import { BankIdInternalCtx } from "../BankIdInternalContext";
2
2
  export interface AuthOptions {
3
3
  endUserIp?: string;
4
+ payload?: Record<string, any>;
4
5
  }
5
6
  export interface AuthResponse {
6
7
  orderRef: string;
@@ -87,6 +87,7 @@ function auth(ctx_1) {
87
87
  createdAt: new Date(),
88
88
  ip: clientIp,
89
89
  autoStartToken: authResponse.autoStartToken,
90
+ payload: options.payload,
90
91
  qr: {
91
92
  qrStartToken: authResponse.qrStartToken,
92
93
  qrStartSecret: authResponse.qrStartSecret,
@@ -51,7 +51,7 @@ function getAuthStatus(ctx, options) {
51
51
  case 1:
52
52
  session = _c.sent();
53
53
  if (!session) {
54
- throw new Error("BankId session not found");
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 new Error("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)];
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();
@@ -3,6 +3,7 @@ export interface SignOptions {
3
3
  userVisibleData: string;
4
4
  userNonVisibleData?: string;
5
5
  endUserIp?: string;
6
+ payload?: Record<string, any>;
6
7
  }
7
8
  export interface SignResponse {
8
9
  orderRef: string;
@@ -96,6 +96,7 @@ function sign(ctx, options) {
96
96
  createdAt: new Date(),
97
97
  ip: clientIp,
98
98
  autoStartToken: signResponse.autoStartToken,
99
+ payload: options.payload,
99
100
  qr: {
100
101
  qrStartToken: signResponse.qrStartToken,
101
102
  qrStartSecret: signResponse.qrStartSecret,
@@ -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, error_1;
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 2:
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, error_1;
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 2:
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, { endUserIp: clientIp })];
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*/, {
@@ -1,2 +1,3 @@
1
1
  export default interface AuthInitiateReq {
2
+ payload?: Record<string, any>;
2
3
  }
@@ -22,6 +22,7 @@ export default interface BankIdSession {
22
22
  hintCode?: string | null;
23
23
  ip: string;
24
24
  autoStartToken: string;
25
+ payload?: Record<string, any>;
25
26
  qr?: {
26
27
  qrStartToken: string;
27
28
  qrStartSecret: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/bankid-plugin",
3
- "version": "0.12.1-alpha.23",
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": "ab25ba2532fd79e5452390591c1899fbe3eae230"
35
+ "gitHead": "44a1bf5bb2b2c7d18e4cecc06da626700639f82a"
36
36
  }
@@ -0,0 +1,5 @@
1
+ describe("BankID Plugin", () => {
2
+ it("should be testable", () => {
3
+ expect(true).toBe(true);
4
+ });
5
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "spec_dir": "spec",
3
+ "spec_files": ["**/*[sS]pec.ts"],
4
+ "helpers": ["helpers/**/*.ts"],
5
+ "stopSpecOnExpectationFailure": false,
6
+ "random": true
7
+ }
@@ -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.
@@ -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 new Error("BankId session not found");
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 new Error("User data is missing");
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",
@@ -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, internalServerError, notFound } from "@flink-app/flink";
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
- try {
15
- const authStatus = await getAuthStatus(ctx, { orderRef });
14
+ const authStatus = await getAuthStatus(ctx, { orderRef });
16
15
 
17
- return {
18
- data: authStatus,
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, internalServerError, notFound } from "@flink-app/flink";
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
- try {
15
- const signStatus = await getSignStatus(ctx, { orderRef });
14
+ const signStatus = await getSignStatus(ctx, { orderRef });
16
15
 
17
- return {
18
- data: signStatus,
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, { endUserIp: clientIp });
18
+ const authResponse = await auth(ctx, {
19
+ endUserIp: clientIp,
20
+ payload: req.body.payload
21
+ });
19
22
 
20
23
  return {
21
24
  data: authResponse,
@@ -1 +1,3 @@
1
- export default interface AuthInitiateReq {}
1
+ export default interface AuthInitiateReq {
2
+ payload?: Record<string, any>;
3
+ }
@@ -24,6 +24,7 @@ export default interface BankIdSession {
24
24
  hintCode?: string | null;
25
25
  ip: string;
26
26
  autoStartToken: string;
27
+ payload?: Record<string, any>;
27
28
  qr?: {
28
29
  qrStartToken: string;
29
30
  qrStartSecret: string;