@haus-tech/bankid-auth-plugin 1.0.3 → 1.0.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.0.4
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **bankid-auth-plugin:** update rejectUnauthorized logic to use environment variable ([62de1e7](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/62de1e7))
6
+
7
+ ## 1.0.3
8
+
9
+ This was a version bump only for bankid-auth-plugin to align it with other projects, there were no code changes.
10
+
1
11
  ## 1.0.2
2
12
 
3
13
  ### 🚀 Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/bankid-auth-plugin",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Support for authentication via Swedish BankID",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -0,0 +1 @@
1
+ export declare const shopSchema: import("graphql").DocumentNode;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shopSchema = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ exports.shopSchema = (0, graphql_tag_1.gql) `
6
+ extend type Mutation {
7
+ initiateBankidAuth: InitiateBankidAuthResponse!
8
+ }
9
+
10
+ type InitiateBankidAuthResponse {
11
+ autoStartToken: String!
12
+ }
13
+
14
+ extend type Mutation {
15
+ getBankidAuthStatus(input: GetBankidAuthStatusInput!): GetBankidAuthStatusResponse!
16
+ }
17
+
18
+ input GetBankidAuthStatusInput {
19
+ isSameDevice: Boolean!
20
+ }
21
+
22
+ type GetBankidAuthStatusResponse {
23
+ status: String!
24
+ hintCode: String
25
+ autoStartToken: String
26
+ qrData: String
27
+ }
28
+ extend type Mutation {
29
+ cancelBankidAuth: Boolean!
30
+ }
31
+ `;
32
+ //# sourceMappingURL=api-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-extensions.js","sourceRoot":"","sources":["../../../../../packages/bankid-auth-plugin/src/api/api-extensions.ts"],"names":[],"mappings":";;;AAAA,6CAAiC;AAEpB,QAAA,UAAU,GAAG,IAAA,iBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B5B,CAAA"}
@@ -11,15 +11,15 @@ exports.BankIdAuthPlugin = void 0;
11
11
  const core_1 = require("@vendure/core");
12
12
  const constants_1 = require("./constants");
13
13
  const bankid_auth_service_1 = require("./services/bankid-auth.service");
14
- const bankid_auth_controller_1 = require("./bankid-auth.controller");
14
+ const bankid_api_service_1 = require("./services/bankid-api.service");
15
+ const bankid_session_service_1 = require("./services/bankid-session.service");
16
+ const api_extensions_1 = require("./api/api-extensions");
17
+ const bankid_auth_resolver_1 = require("./bankid-auth.resolver");
15
18
  let BankIdAuthPlugin = class BankIdAuthPlugin {
16
19
  static { BankIdAuthPlugin_1 = this; }
17
20
  static options;
18
21
  static init(options) {
19
22
  this.options = options;
20
- if (!options.postAuthStrategy) {
21
- throw new Error('BankIdAuthPlugin requires a PostAuthenticateStrategy but none was provided');
22
- }
23
23
  if (!options.bankIdApiBaseUrl) {
24
24
  throw new Error('BankIdAuthPlugin requires a bankIdApiBaseUrl but none was provided');
25
25
  }
@@ -32,16 +32,17 @@ exports.BankIdAuthPlugin = BankIdAuthPlugin = BankIdAuthPlugin_1 = __decorate([
32
32
  imports: [core_1.PluginCommonModule],
33
33
  providers: [
34
34
  { provide: constants_1.BANKID_AUTH_PLUGIN_OPTIONS, useFactory: () => BankIdAuthPlugin.options },
35
+ bankid_api_service_1.BankIdApiService,
36
+ bankid_session_service_1.BankIdSessionService,
35
37
  bankid_auth_service_1.BankIdAuthService,
36
38
  ],
39
+ shopApiExtensions: {
40
+ resolvers: [bankid_auth_resolver_1.BankIdAuthResolver],
41
+ schema: api_extensions_1.shopSchema,
42
+ },
37
43
  configuration: (config) => {
38
- // Plugin-specific configuration
39
- // such as custom fields, custom permissions,
40
- // strategies etc. can be configured here by
41
- // modifying the `config` object.
42
44
  return config;
43
45
  },
44
- controllers: [bankid_auth_controller_1.BankIdAuthController],
45
46
  compatibility: '^3.0.0',
46
47
  })
47
48
  ], BankIdAuthPlugin);
@@ -1 +1 @@
1
- {"version":3,"file":"bankid-auth.plugin.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/bankid-auth.plugin.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,wCAAuE;AAEvE,2CAAwD;AACxD,wEAAkE;AAClE,qEAA+D;AAmBxD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;;IAC3B,MAAM,CAAC,OAAO,CAAyB;IAEvC,MAAM,CAAC,IAAI,CAAC,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAA;QAC/F,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;QACvF,CAAC;QACD,OAAO,kBAAgB,CAAA;IACzB,CAAC;CACF,CAAA;AAbY,4CAAgB;2BAAhB,gBAAgB;IAhB5B,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE;YACT,EAAE,OAAO,EAAE,sCAA0B,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;YACnF,uCAAiB;SAClB;QACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;YACxB,gCAAgC;YAChC,6CAA6C;YAC7C,4CAA4C;YAC5C,iCAAiC;YACjC,OAAO,MAAM,CAAA;QACf,CAAC;QACD,WAAW,EAAE,CAAC,6CAAoB,CAAC;QACnC,aAAa,EAAE,QAAQ;KACxB,CAAC;GACW,gBAAgB,CAa5B"}
1
+ {"version":3,"file":"bankid-auth.plugin.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/bankid-auth.plugin.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,wCAAuE;AACvE,2CAAwD;AACxD,wEAAkE;AAClE,sEAAgE;AAChE,8EAAwE;AAExE,yDAAiD;AACjD,iEAA2D;AAmBpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;;IAC3B,MAAM,CAAC,OAAO,CAAyB;IAEvC,MAAM,CAAC,IAAI,CAAC,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;QACvF,CAAC;QACD,OAAO,kBAAgB,CAAA;IACzB,CAAC;CACF,CAAA;AAVY,4CAAgB;2BAAhB,gBAAgB;IAjB5B,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE;YACT,EAAE,OAAO,EAAE,sCAA0B,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE;YACnF,qCAAgB;YAChB,6CAAoB;YACpB,uCAAiB;SAClB;QACD,iBAAiB,EAAE;YACjB,SAAS,EAAE,CAAC,yCAAkB,CAAC;YAC/B,MAAM,EAAE,2BAAU;SACnB;QACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;YACxB,OAAO,MAAM,CAAA;QACf,CAAC;QACD,aAAa,EAAE,QAAQ;KACxB,CAAC;GACW,gBAAgB,CAU5B"}
@@ -0,0 +1,25 @@
1
+ import { BankIdAuthService } from './services/bankid-auth.service';
2
+ import { BankIdSessionService } from './services/bankid-session.service';
3
+ import { RequestContext } from '@vendure/core';
4
+ import { GetBankidAuthStatusInput } from './types';
5
+ import { Request } from 'express';
6
+ export declare class BankIdAuthResolver {
7
+ private bankIdAuthService;
8
+ private bankIdSessionService;
9
+ constructor(bankIdAuthService: BankIdAuthService, bankIdSessionService: BankIdSessionService);
10
+ initiateBankidAuth(ctx: RequestContext, req: Request): Promise<Pick<import("./types").InitiateResponse, "autoStartToken">>;
11
+ getBankidAuthStatus(ctx: RequestContext, args: {
12
+ input: GetBankidAuthStatusInput;
13
+ }): Promise<{
14
+ status: string;
15
+ hintCode: null;
16
+ autoStartToken: null;
17
+ qrData: null;
18
+ } | {
19
+ status: import("./types").BankIdOrderStatus;
20
+ hintCode: string;
21
+ autoStartToken: string;
22
+ qrData: string | undefined;
23
+ }>;
24
+ cancelBankidAuth(ctx: RequestContext): Promise<boolean>;
25
+ }
@@ -12,40 +12,55 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.BankIdAuthController = void 0;
15
+ exports.BankIdAuthResolver = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const bankid_auth_service_1 = require("./services/bankid-auth.service");
18
+ const bankid_session_service_1 = require("./services/bankid-session.service");
18
19
  const core_1 = require("@vendure/core");
19
20
  const utils_1 = require("./utils");
20
21
  const utils_2 = require("./utils");
21
- let BankIdAuthController = class BankIdAuthController {
22
+ const graphql_1 = require("@nestjs/graphql");
23
+ const graphql_2 = require("@nestjs/graphql");
24
+ const lodash_1 = require("lodash");
25
+ const constants_1 = require("./constants");
26
+ let BankIdAuthResolver = class BankIdAuthResolver {
22
27
  bankIdAuthService;
23
- cacheService;
24
- constructor(bankIdAuthService, cacheService) {
28
+ bankIdSessionService;
29
+ constructor(bankIdAuthService, bankIdSessionService) {
25
30
  this.bankIdAuthService = bankIdAuthService;
26
- this.cacheService = cacheService;
31
+ this.bankIdSessionService = bankIdSessionService;
27
32
  }
28
- async initiate(ctx) {
29
- const endUserIp = (0, utils_1.getEndUserIp)(ctx);
33
+ async initiateBankidAuth(ctx, req) {
30
34
  try {
35
+ const endUserIp = (0, utils_1.getClientIp)(req);
31
36
  const result = await this.bankIdAuthService.initiate(ctx, endUserIp);
32
- const cacheKey = `bankid:session:${result.orderRef}`;
33
- this.cacheService.set(cacheKey, endUserIp, { ttl: 120000 });
34
- return { data: result };
37
+ await this.bankIdSessionService.save(ctx, result, endUserIp);
38
+ return (0, lodash_1.pick)(result, ['autoStartToken']);
35
39
  }
36
40
  catch (error) {
41
+ const err = error;
42
+ core_1.Logger.error(`BankID initiate failed: ${err.message}`, constants_1.loggerCtx, err.stack);
37
43
  throw (0, utils_1.handleBankIdError)(error);
38
44
  }
39
45
  }
40
- async authenticate(ctx, body) {
41
- if (!body.orderRef) {
42
- throw new common_1.HttpException('orderRef is required', common_1.HttpStatus.BAD_REQUEST);
46
+ async getBankidAuthStatus(ctx, args) {
47
+ const data = await this.bankIdSessionService.get(ctx);
48
+ if (!data || !data.orderRef) {
49
+ return {
50
+ status: 'NOT_INITIATED',
51
+ hintCode: null,
52
+ autoStartToken: null,
53
+ qrData: null,
54
+ };
43
55
  }
44
- const cacheKey = `bankid:session:${body.orderRef}`;
45
- const cachedIpAddress = (await this.cacheService.get(cacheKey));
46
56
  try {
47
- const res = await this.bankIdAuthService.authenticate(ctx, body.orderRef, cachedIpAddress, body.isSameDevice);
48
- return { data: res };
57
+ const statusResponse = await this.bankIdAuthService.getBankidAuthStatus(ctx, data, args.input.isSameDevice);
58
+ return {
59
+ status: statusResponse.status,
60
+ hintCode: statusResponse.hintCode,
61
+ autoStartToken: data.autoStartToken,
62
+ qrData: statusResponse.qrData,
63
+ };
49
64
  }
50
65
  catch (error) {
51
66
  if (error instanceof utils_2.IpMismatchError) {
@@ -54,48 +69,48 @@ let BankIdAuthController = class BankIdAuthController {
54
69
  throw (0, utils_1.handleBankIdError)(error);
55
70
  }
56
71
  }
57
- async cancel(ctx, body) {
58
- if (!body.orderRef) {
59
- throw new common_1.HttpException('orderRef is required', common_1.HttpStatus.BAD_REQUEST);
72
+ async cancelBankidAuth(ctx) {
73
+ const data = await this.bankIdSessionService.get(ctx);
74
+ if (!data || !data.orderRef) {
75
+ throw new common_1.HttpException('No active BankID order to cancel', common_1.HttpStatus.BAD_REQUEST);
60
76
  }
61
77
  try {
62
- await this.bankIdAuthService.cancel(ctx, body.orderRef);
78
+ await this.bankIdAuthService.cancel(ctx, data.orderRef);
79
+ await this.bankIdSessionService.clear(ctx);
80
+ return true;
63
81
  }
64
82
  catch (error) {
65
83
  throw (0, utils_1.handleBankIdError)(error);
66
84
  }
67
85
  }
68
86
  };
69
- exports.BankIdAuthController = BankIdAuthController;
87
+ exports.BankIdAuthResolver = BankIdAuthResolver;
70
88
  __decorate([
71
- (0, common_1.Post)('initiate'),
72
- (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
89
+ (0, graphql_1.Mutation)(),
73
90
  __param(0, (0, core_1.Ctx)()),
91
+ __param(1, (0, graphql_2.Context)('req')),
74
92
  __metadata("design:type", Function),
75
- __metadata("design:paramtypes", [core_1.RequestContext]),
93
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
76
94
  __metadata("design:returntype", Promise)
77
- ], BankIdAuthController.prototype, "initiate", null);
95
+ ], BankIdAuthResolver.prototype, "initiateBankidAuth", null);
78
96
  __decorate([
79
- (0, common_1.Post)('authenticate'),
80
- (0, common_1.HttpCode)(common_1.HttpStatus.OK),
97
+ (0, graphql_1.Mutation)(),
81
98
  __param(0, (0, core_1.Ctx)()),
82
- __param(1, (0, common_1.Body)()),
99
+ __param(1, (0, graphql_1.Args)()),
83
100
  __metadata("design:type", Function),
84
101
  __metadata("design:paramtypes", [core_1.RequestContext, Object]),
85
102
  __metadata("design:returntype", Promise)
86
- ], BankIdAuthController.prototype, "authenticate", null);
103
+ ], BankIdAuthResolver.prototype, "getBankidAuthStatus", null);
87
104
  __decorate([
88
- (0, common_1.Post)('cancel'),
89
- (0, common_1.HttpCode)(common_1.HttpStatus.OK),
105
+ (0, graphql_1.Mutation)(),
90
106
  __param(0, (0, core_1.Ctx)()),
91
- __param(1, (0, common_1.Body)()),
92
107
  __metadata("design:type", Function),
93
- __metadata("design:paramtypes", [core_1.RequestContext, Object]),
108
+ __metadata("design:paramtypes", [core_1.RequestContext]),
94
109
  __metadata("design:returntype", Promise)
95
- ], BankIdAuthController.prototype, "cancel", null);
96
- exports.BankIdAuthController = BankIdAuthController = __decorate([
97
- (0, common_1.Controller)('api/bankid'),
110
+ ], BankIdAuthResolver.prototype, "cancelBankidAuth", null);
111
+ exports.BankIdAuthResolver = BankIdAuthResolver = __decorate([
112
+ (0, graphql_1.Resolver)(),
98
113
  __metadata("design:paramtypes", [bankid_auth_service_1.BankIdAuthService,
99
- core_1.CacheService])
100
- ], BankIdAuthController);
101
- //# sourceMappingURL=bankid-auth.controller.js.map
114
+ bankid_session_service_1.BankIdSessionService])
115
+ ], BankIdAuthResolver);
116
+ //# sourceMappingURL=bankid-auth.resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bankid-auth.resolver.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/bankid-auth.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAiF;AACjF,wEAAkE;AAClE,8EAAwE;AACxE,wCAA2D;AAC3D,mCAAwD;AACxD,mCAAyC;AACzC,6CAA0D;AAG1D,6CAAyC;AACzC,mCAA6B;AAE7B,2CAAuC;AAGhC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEnB;IACA;IAFV,YACU,iBAAoC,EACpC,oBAA0C;QAD1C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,yBAAoB,GAApB,oBAAoB,CAAsB;IACjD,CAAC;IAGE,AAAN,KAAK,CAAC,kBAAkB,CAAQ,GAAmB,EAAkB,GAAY;QAC/E,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,GAAG,CAAC,CAAA;YAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB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AkB,CAyE9B"}
package/src/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './bankid-auth.plugin';
2
+ export * from './services/bankid-session.service';
package/src/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./bankid-auth.plugin"), exports);
18
+ __exportStar(require("./services/bankid-session.service"), exports);
18
19
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC;AACpC,oEAAiD"}
@@ -0,0 +1,10 @@
1
+ import { RequestContext } from '@vendure/core';
2
+ import { InitiateResponse, CollectResponse, BankIdAuthPluginOptions } from '../types';
3
+ export declare class BankIdApiService {
4
+ private options;
5
+ private readonly axiosInstance;
6
+ constructor(options: BankIdAuthPluginOptions);
7
+ initiate(_ctx: RequestContext, endUserIp: string): Promise<InitiateResponse>;
8
+ collect(_ctx: RequestContext, orderRef: string): Promise<CollectResponse>;
9
+ cancel(_ctx: RequestContext, orderRef: string): Promise<boolean>;
10
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BankIdApiService = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const core_1 = require("@vendure/core");
21
+ const constants_1 = require("../constants");
22
+ const constants_2 = require("../constants");
23
+ const axios_1 = __importDefault(require("axios"));
24
+ const https_1 = __importDefault(require("https"));
25
+ let BankIdApiService = class BankIdApiService {
26
+ options;
27
+ axiosInstance;
28
+ constructor(options) {
29
+ this.options = options;
30
+ this.axiosInstance = axios_1.default.create({
31
+ baseURL: this.options.bankIdApiBaseUrl,
32
+ httpsAgent: new https_1.default.Agent({
33
+ cert: this.options.clientCert,
34
+ key: this.options.privateKey,
35
+ ca: this.options.caCert,
36
+ rejectUnauthorized: process.env.BANKID_REJECT_UNAUTHORIZED !== 'false',
37
+ }),
38
+ });
39
+ }
40
+ async initiate(_ctx, endUserIp) {
41
+ const response = await this.axiosInstance.post('/auth', { endUserIp });
42
+ return response.data;
43
+ }
44
+ async collect(_ctx, orderRef) {
45
+ try {
46
+ const response = await this.axiosInstance.post('/collect', { orderRef });
47
+ return response.data;
48
+ }
49
+ catch (error) {
50
+ core_1.Logger.error('BankID collect error', constants_1.loggerCtx);
51
+ throw error;
52
+ }
53
+ }
54
+ async cancel(_ctx, orderRef) {
55
+ const response = await this.axiosInstance.post('/cancel', { orderRef });
56
+ if (response.status !== 200) {
57
+ throw new Error('Failed to cancel order');
58
+ }
59
+ return true;
60
+ }
61
+ };
62
+ exports.BankIdApiService = BankIdApiService;
63
+ exports.BankIdApiService = BankIdApiService = __decorate([
64
+ (0, common_1.Injectable)(),
65
+ __param(0, (0, common_1.Inject)(constants_2.BANKID_AUTH_PLUGIN_OPTIONS)),
66
+ __metadata("design:paramtypes", [Object])
67
+ ], BankIdApiService);
68
+ //# sourceMappingURL=bankid-api.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bankid-api.service.js","sourceRoot":"","sources":["../../../../../packages/bankid-auth-plugin/src/services/bankid-api.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAmD;AACnD,wCAAsD;AACtD,4CAAwC;AACxC,4CAAyD;AACzD,kDAA4C;AAC5C,kDAAyB;AAIlB,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAG6B;IAFvC,aAAa,CAAe;IAE7C,YAAwD,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;QACtF,IAAI,CAAC,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;YAChC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;YACtC,UAAU,EAAE,IAAI,eAAK,CAAC,KAAK,CAAC;gBAC1B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;gBAC7B,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;gBAC5B,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;gBACvB,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,0BAA0B,KAAK,OAAO;aACvE,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAoB,EAAE,SAAiB;QACpD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;QACtE,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAoB,EAAE,QAAgB;QAClD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAkB,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;YACzF,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,qBAAS,CAAC,CAAA;YAC/C,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAoB,EAAE,QAAgB;QACjD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;QACvE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC3C,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AAtCY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,eAAM,EAAC,sCAA0B,CAAC,CAAA;;GAHpC,gBAAgB,CAsC5B"}
@@ -1,13 +1,14 @@
1
- import { ModuleRef } from '@nestjs/core';
2
1
  import { RequestContext } from '@vendure/core';
3
- import { InitiateResponse, AuthResponse, BankIdAuthPluginOptions } from '../types';
2
+ import { InitiateResponse, OrderStatusResponse, CollectResponse } from '../types';
3
+ import { BankIdApiService } from './bankid-api.service';
4
+ import { BankIdSessionService } from './bankid-session.service';
5
+ import { BankIdSessionData } from '../types';
4
6
  export declare class BankIdAuthService {
5
- private options;
6
- private moduleRef;
7
- private readonly axiosInstance;
8
- constructor(options: BankIdAuthPluginOptions, moduleRef: ModuleRef);
7
+ private apiService;
8
+ private bankIdSessionService;
9
+ constructor(apiService: BankIdApiService, bankIdSessionService: BankIdSessionService);
9
10
  initiate(ctx: RequestContext, endUserIp: string): Promise<InitiateResponse>;
10
- authenticate(ctx: RequestContext, orderRef: string, cachedIpAddress: string, isSameDevice: boolean): Promise<AuthResponse>;
11
+ getBankidAuthStatus(ctx: RequestContext, data: BankIdSessionData, isSameDevice: boolean): Promise<OrderStatusResponse>;
12
+ handleComplete(ctx: RequestContext, response: CollectResponse, isSameDevice: boolean, cachedIpAddress: string): Promise<Pick<CollectResponse, "orderRef" | "status" | "hintCode">>;
11
13
  cancel(ctx: RequestContext, orderRef: string): Promise<boolean>;
12
- private collect;
13
14
  }
@@ -8,111 +8,65 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
11
  Object.defineProperty(exports, "__esModule", { value: true });
18
12
  exports.BankIdAuthService = void 0;
19
13
  const common_1 = require("@nestjs/common");
20
- const core_1 = require("@nestjs/core");
21
- const core_2 = require("@vendure/core");
14
+ const core_1 = require("@vendure/core");
22
15
  const constants_1 = require("../constants");
23
- const axios_1 = __importDefault(require("axios"));
24
- const https_1 = require("https");
25
16
  const types_1 = require("../types");
26
17
  const utils_1 = require("../utils");
18
+ const lodash_1 = require("lodash");
19
+ const bankid_api_service_1 = require("./bankid-api.service");
20
+ const bankid_session_service_1 = require("./bankid-session.service");
27
21
  let BankIdAuthService = class BankIdAuthService {
28
- options;
29
- moduleRef;
30
- axiosInstance;
31
- constructor(options, moduleRef) {
32
- this.options = options;
33
- this.moduleRef = moduleRef;
34
- this.axiosInstance = axios_1.default.create({
35
- baseURL: this.options.bankIdApiBaseUrl,
36
- httpsAgent: new https_1.Agent({
37
- cert: this.options.clientCert,
38
- key: this.options.privateKey,
39
- ca: this.options.caCert,
40
- rejectUnauthorized: false,
41
- }),
42
- });
22
+ apiService;
23
+ bankIdSessionService;
24
+ constructor(apiService, bankIdSessionService) {
25
+ this.apiService = apiService;
26
+ this.bankIdSessionService = bankIdSessionService;
43
27
  }
44
28
  async initiate(ctx, endUserIp) {
45
- try {
46
- const response = await this.axiosInstance.post('/auth', { endUserIp });
47
- return response.data;
48
- }
49
- catch (error) {
50
- throw error;
51
- }
29
+ return this.apiService.initiate(ctx, endUserIp);
52
30
  }
53
- async authenticate(ctx, orderRef, cachedIpAddress, isSameDevice) {
31
+ async getBankidAuthStatus(ctx, data, isSameDevice) {
54
32
  try {
55
- const response = await this.collect(ctx, orderRef, 2000);
56
- if (response.status === types_1.BankIdOrderStatus.Failed) {
57
- return { success: false, hintCode: response?.hintCode };
58
- }
33
+ const response = await this.apiService.collect(ctx, data.orderRef);
59
34
  if (response.status === types_1.BankIdOrderStatus.Complete && response.completionData != null) {
60
- const { user, device } = response.completionData;
61
- if (isSameDevice && cachedIpAddress != device.ipAddress) {
62
- throw new utils_1.IpMismatchError(cachedIpAddress, device.ipAddress);
63
- }
64
- const { userId } = await this.options.postAuthStrategy.handleSuccess(ctx, new core_2.Injector(this.moduleRef), {
65
- personalNumber: user.personalNumber,
66
- });
67
- return {
68
- success: true,
69
- userId: userId,
70
- };
35
+ return await this.handleComplete(ctx, response, isSameDevice, data.endUserIp);
71
36
  }
37
+ const qrData = (0, utils_1.generateQrData)(data);
38
+ const result = {
39
+ ...response,
40
+ qrData: qrData,
41
+ };
42
+ return (0, lodash_1.pick)(result, ['status', 'hintCode', 'qrData', 'orderRef']);
72
43
  }
73
44
  catch (error) {
45
+ core_1.Logger.error('BankID collect error', constants_1.loggerCtx);
46
+ await this.bankIdSessionService.clear(ctx);
74
47
  throw error;
75
48
  }
76
- return { success: false };
77
49
  }
78
- async cancel(ctx, orderRef) {
79
- try {
80
- const response = await this.axiosInstance.post('/cancel', { orderRef });
81
- if (response.status !== 200) {
82
- throw new Error('Failed to cancel order');
83
- }
84
- return true;
50
+ async handleComplete(ctx, response, isSameDevice, cachedIpAddress) {
51
+ await this.bankIdSessionService.clear(ctx);
52
+ const { user, device } = response.completionData || {};
53
+ if (!user || !device) {
54
+ throw new Error('User or device not found'); // This should never happen since we check for completionData in the collect response
85
55
  }
86
- catch (error) {
87
- throw error;
56
+ if (isSameDevice && cachedIpAddress != device.ipAddress) {
57
+ throw new utils_1.IpMismatchError(cachedIpAddress, device.ipAddress);
88
58
  }
59
+ await this.bankIdSessionService.saveAuthenticatedUser(ctx, user.personalNumber);
60
+ return (0, lodash_1.pick)(response, ['status', 'hintCode', 'orderRef']);
89
61
  }
90
- async collect(ctx, orderRef, pollingIntervalMs) {
91
- return new Promise((resolve, reject) => {
92
- const interval = setInterval(async () => {
93
- try {
94
- const response = await this.axiosInstance.post('/collect', { orderRef });
95
- if (response.data.status === types_1.BankIdOrderStatus.Complete) {
96
- clearInterval(interval);
97
- resolve(response.data);
98
- }
99
- if (response.data.status === types_1.BankIdOrderStatus.Failed) {
100
- clearInterval(interval);
101
- reject(response.data);
102
- }
103
- }
104
- catch (error) {
105
- clearInterval(interval);
106
- reject(error);
107
- }
108
- }, pollingIntervalMs);
109
- });
62
+ async cancel(ctx, orderRef) {
63
+ return this.apiService.cancel(ctx, orderRef);
110
64
  }
111
65
  };
112
66
  exports.BankIdAuthService = BankIdAuthService;
113
67
  exports.BankIdAuthService = BankIdAuthService = __decorate([
114
68
  (0, common_1.Injectable)(),
115
- __param(0, (0, common_1.Inject)(constants_1.BANKID_AUTH_PLUGIN_OPTIONS)),
116
- __metadata("design:paramtypes", [Object, core_1.ModuleRef])
69
+ __metadata("design:paramtypes", [bankid_api_service_1.BankIdApiService,
70
+ bankid_session_service_1.BankIdSessionService])
117
71
  ], BankIdAuthService);
118
72
  //# sourceMappingURL=bankid-auth.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bankid-auth.service.js","sourceRoot":"","sources":["../../../../../packages/bankid-auth-plugin/src/services/bankid-au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O,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,OAAO,CACnB,GAAmB,EACnB,QAAgB,EAChB,iBAAyB;QAEzB,OAAO,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;gBACtC,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAkB,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;oBACzF,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,yBAAiB,CAAC,QAAQ,EAAE,CAAC;wBACxD,aAAa,CAAC,QAAQ,CAAC,CAAA;wBACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;oBACxB,CAAC;oBACD,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,yBAAiB,CAAC,MAAM,EAAE,CAAC;wBACtD,aAAa,CAAC,QAAQ,CAAC,CAAA;wBACvB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;oBACvB,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,aAAa,CAAC,QAAQ,CAAC,CAAA;oBACvB,MAAM,CAAC,KAAK,CAAC,CAAA;gBACf,CAAC;YACH,CAAC,EAAE,iBAAiB,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAtGY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,sCAA0B,CAAC,CAAA;6CAChB,gBAAS;GAJnB,iBAAiB,CAsG7B"}
1
+ {"version":3,"file":"bankid-auth.service.js","sourceRoot":"","sources":["../../../../../packages/bankid-auth-plugin/src/services/bankid-auth.service.ts"],"names":[],"mappings":";;;;;;;;;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I,CAAC,oBAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC1C,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,GAAmB,EACnB,QAAyB,EACzB,YAAqB,EACrB,eAAuB;QAEvB,MAAM,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC1C,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,cAAc,IAAI,EAAE,CAAA;QAEtD,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA,CAAC,qFAAqF;QACnI,CAAC;QAED,IAAI,YAAY,IAAI,eAAe,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACxD,MAAM,IAAI,uBAAe,CAAC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;QAC9D,CAAC;QAED,MAAM,IAAI,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QAE/E,OAAO,IAAA,aAAI,EAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAmB,EAAE,QAAgB;QAChD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IAC9C,CAAC;CACF,CAAA;AA9DY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGW,qCAAgB;QACN,6CAAoB;GAHzC,iBAAiB,CA8D7B"}
@@ -0,0 +1,13 @@
1
+ import { RequestContext, CacheService } from '@vendure/core';
2
+ import { InitiateResponse } from '../types';
3
+ import { BankIdSessionData } from '../types';
4
+ export declare class BankIdSessionService {
5
+ private cacheService;
6
+ constructor(cacheService: CacheService);
7
+ save(ctx: RequestContext, bankIdData: InitiateResponse, endUserIp: string): Promise<void>;
8
+ get(ctx: RequestContext): Promise<BankIdSessionData | undefined>;
9
+ clear(ctx: RequestContext): Promise<void>;
10
+ getSessionToken(ctx: RequestContext): Promise<string | undefined>;
11
+ saveAuthenticatedUser(ctx: RequestContext, ssn: string): Promise<void>;
12
+ getAuthenticatedUser(ctx: RequestContext): Promise<string | undefined>;
13
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BankIdSessionService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@vendure/core");
18
+ const lodash_1 = require("lodash");
19
+ const crypto_js_1 = __importDefault(require("crypto-js"));
20
+ const CACHE_TTL_MS = 1800000; // 30 minutes
21
+ const ENCRYPTION_KEY = process.env.BANKID_ENCRYPTION_KEY;
22
+ let BankIdSessionService = class BankIdSessionService {
23
+ cacheService;
24
+ constructor(cacheService) {
25
+ this.cacheService = cacheService;
26
+ }
27
+ async save(ctx, bankIdData, endUserIp) {
28
+ const sessionToken = await this.getSessionToken(ctx);
29
+ const data = {
30
+ ...(0, lodash_1.pick)(bankIdData, ['orderRef', 'autoStartToken', 'qrStartToken', 'qrStartSecret']),
31
+ endUserIp,
32
+ };
33
+ const cacheKey = `bankid:${sessionToken}:authExtra`;
34
+ await this.cacheService.set(cacheKey, data, { ttl: CACHE_TTL_MS });
35
+ }
36
+ async get(ctx) {
37
+ const sessionToken = await this.getSessionToken(ctx);
38
+ if (!sessionToken) {
39
+ return undefined;
40
+ }
41
+ const cacheKey = `bankid:${sessionToken}:authExtra`;
42
+ return await this.cacheService.get(cacheKey);
43
+ }
44
+ async clear(ctx) {
45
+ const sessionToken = await this.getSessionToken(ctx);
46
+ const cacheKey = `bankid:${sessionToken}:authExtra`;
47
+ await this.cacheService.delete(cacheKey);
48
+ }
49
+ async getSessionToken(ctx) {
50
+ return ctx.session?.token;
51
+ }
52
+ async saveAuthenticatedUser(ctx, ssn) {
53
+ const sessionToken = await this.getSessionToken(ctx);
54
+ if (!ENCRYPTION_KEY) {
55
+ throw new Error('BANKID_ENCRYPTION_KEY is not set');
56
+ }
57
+ const encrypted = crypto_js_1.default.AES.encrypt(ssn, ENCRYPTION_KEY).toString();
58
+ const cacheKey = `bankid:${sessionToken}:authUser`;
59
+ await this.cacheService.set(cacheKey, encrypted, { ttl: CACHE_TTL_MS });
60
+ }
61
+ async getAuthenticatedUser(ctx) {
62
+ const sessionToken = await this.getSessionToken(ctx);
63
+ if (!sessionToken) {
64
+ return undefined;
65
+ }
66
+ const cacheKey = `bankid:${sessionToken}:authUser`;
67
+ const encrypted = (await this.cacheService.get(cacheKey));
68
+ if (!encrypted || !ENCRYPTION_KEY) {
69
+ return undefined;
70
+ }
71
+ try {
72
+ const decrypted = crypto_js_1.default.AES.decrypt(encrypted, ENCRYPTION_KEY).toString(crypto_js_1.default.enc.Utf8);
73
+ return decrypted;
74
+ }
75
+ catch (error) {
76
+ console.error('error decrypting encrypted ssn', error);
77
+ return undefined;
78
+ }
79
+ }
80
+ };
81
+ exports.BankIdSessionService = BankIdSessionService;
82
+ exports.BankIdSessionService = BankIdSessionService = __decorate([
83
+ (0, common_1.Injectable)(),
84
+ __metadata("design:paramtypes", [core_1.CacheService])
85
+ ], BankIdSessionService);
86
+ //# sourceMappingURL=bankid-session.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bankid-session.service.js","sourceRoot":"","sources":["../../../../../packages/bankid-auth-plugin/src/services/bankid-session.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,wCAA4D;AAE5D,mCAA6B;AAC7B,0DAAgC;AAGhC,MAAM,YAAY,GAAG,OAAO,CAAA,CAAC,aAAa;AAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA;AAGjD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACX;IAApB,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAElD,KAAK,CAAC,IAAI,CAAC,GAAmB,EAAE,UAA4B,EAAE,SAAiB;QAC7E,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QACpD,MAAM,IAAI,GAAG;YACX,GAAG,IAAA,aAAI,EAAC,UAAU,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;YACpF,SAAS;SACV,CAAA;QACD,MAAM,QAAQ,GAAG,UAAU,YAAY,YAAY,CAAA;QACnD,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAmB;QAC3B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QAEpD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,MAAM,QAA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MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAW,CAAA;QACnE,IAAI,CAAC,SAAS,IAAI,CAAC,cAAc,EAAE,CAAC;YAClC,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,mBAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,mBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC7F,OAAO,SAAS,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAA;YACtD,OAAO,SAAS,CAAA;QAClB,CAAC;IACH,CAAC;CACF,CAAA;AAnEY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAEuB,mBAAY;GADnC,oBAAoB,CAmEhC"}
package/src/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { InjectableStrategy, Injector, RequestContext } from '@vendure/core';
2
1
  /**
3
2
  * @description
4
3
  * The plugin can be configured using the following options:
@@ -8,7 +7,9 @@ export interface BankIdAuthPluginOptions {
8
7
  clientCert: string;
9
8
  privateKey: string;
10
9
  caCert: string;
11
- postAuthStrategy: PostAuthenticateStrategy;
10
+ }
11
+ export interface GetBankidAuthStatusInput {
12
+ isSameDevice: boolean;
12
13
  }
13
14
  export interface InitiateResponse {
14
15
  orderRef: string;
@@ -17,8 +18,8 @@ export interface InitiateResponse {
17
18
  qrStartSecret: string;
18
19
  }
19
20
  export interface CollectResponse {
20
- orderRef: BankIdOrderStatus.Complete | BankIdOrderStatus.Failed | BankIdOrderStatus.Pending;
21
- status: string;
21
+ orderRef: string;
22
+ status: BankIdOrderStatus.Complete | BankIdOrderStatus.Failed | BankIdOrderStatus.Pending;
22
23
  hintCode: string;
23
24
  completionData?: CompletionData;
24
25
  }
@@ -39,6 +40,15 @@ export interface AuthResponse {
39
40
  userId?: string;
40
41
  hintCode?: string;
41
42
  }
43
+ export type OrderStatusResponse = {
44
+ orderRef: string;
45
+ status: BankIdOrderStatus;
46
+ hintCode: string;
47
+ autoStartToken?: string;
48
+ qrData?: string;
49
+ user?: User;
50
+ sessionToken?: string;
51
+ };
42
52
  export declare enum BankIdOrderStatus {
43
53
  Pending = "pending",
44
54
  Complete = "complete",
@@ -48,11 +58,13 @@ export interface BadRequestResponse {
48
58
  errorCode: string;
49
59
  details: string;
50
60
  }
51
- export interface PostAuthenticateStrategy extends InjectableStrategy {
52
- handleSuccess(ctx: RequestContext, injector: Injector, input: {
53
- personalNumber: string;
54
- }): Promise<AuthenticatedUser>;
55
- }
56
61
  export interface AuthenticatedUser {
57
62
  userId: string;
58
63
  }
64
+ export type BankIdSessionData = {
65
+ orderRef: string;
66
+ autoStartToken: string;
67
+ qrStartToken: string;
68
+ qrStartSecret: string;
69
+ endUserIp: string;
70
+ };
package/src/types.js CHANGED
@@ -1,4 +1,8 @@
1
1
  "use strict";
2
+ /**
3
+ * @description
4
+ * The plugin can be configured using the following options:
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.BankIdOrderStatus = void 0;
4
8
  var BankIdOrderStatus;
package/src/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/types.ts"],"names":[],"mappings":";;;AAkDA,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;AACnB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA0DH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;AACnB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B"}
package/src/utils.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { HttpException } from '@nestjs/common';
2
- import { RequestContext } from '@vendure/core';
3
- export declare function handleBankIdError(error: any): HttpException;
4
- export declare function getEndUserIp(ctx: RequestContext): string;
2
+ import { AxiosError } from 'axios';
3
+ import { Request } from 'express';
4
+ import { InitiateResponse } from './types';
5
+ export declare function handleBankIdError(error: AxiosError | Error): HttpException;
6
+ export declare function getClientIp(req: Request): string;
7
+ export declare function generateQrData(data: InitiateResponse | null): string;
5
8
  export declare class IpMismatchError extends Error {
6
9
  expected: string;
7
10
  actual: string;
package/src/utils.js CHANGED
@@ -2,12 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IpMismatchError = void 0;
4
4
  exports.handleBankIdError = handleBankIdError;
5
- exports.getEndUserIp = getEndUserIp;
5
+ exports.getClientIp = getClientIp;
6
+ exports.generateQrData = generateQrData;
6
7
  const common_1 = require("@nestjs/common");
8
+ const core_1 = require("@vendure/core");
9
+ const constants_1 = require("./constants");
10
+ const crypto_1 = require("crypto");
7
11
  function handleBankIdError(error) {
8
12
  if (error?.isAxiosError) {
9
13
  const axiosError = error;
10
14
  const status = axiosError.response?.status || 500;
15
+ core_1.Logger.error(`BankID error: ${status} - ${axiosError.message}`, constants_1.loggerCtx);
11
16
  if (status >= 500) {
12
17
  return new common_1.HttpException({
13
18
  message: 'BankID service unavailable',
@@ -24,15 +29,36 @@ function handleBankIdError(error) {
24
29
  message: 'Unexpected error',
25
30
  }, common_1.HttpStatus.INTERNAL_SERVER_ERROR);
26
31
  }
27
- function getEndUserIp(ctx) {
28
- const xForwardedFor = ctx.req?.headers['x-forwarded-for'];
29
- if (typeof xForwardedFor === 'string') {
32
+ function getClientIp(req) {
33
+ // Check various headers for the real client IP
34
+ const xForwardedFor = req.headers['x-forwarded-for'];
35
+ const xRealIp = req.headers['x-real-ip'];
36
+ const cfConnectingIp = req.headers['cf-connecting-ip']; // Cloudflare
37
+ if (xForwardedFor) {
30
38
  return xForwardedFor.split(',')[0].trim();
31
39
  }
32
- if (Array.isArray(xForwardedFor)) {
33
- return xForwardedFor[0];
40
+ if (xRealIp) {
41
+ return xRealIp;
34
42
  }
35
- throw new Error('Could not determine end user IP');
43
+ if (cfConnectingIp) {
44
+ return cfConnectingIp;
45
+ }
46
+ const remoteAddress = req.socket?.remoteAddress;
47
+ if (remoteAddress) {
48
+ return remoteAddress;
49
+ }
50
+ throw new Error('Could not determine client IP address');
51
+ }
52
+ function generateQrData(data) {
53
+ if (!data || !data.qrStartToken || !data.qrStartSecret) {
54
+ throw new Error('BankID data not found');
55
+ }
56
+ const orderTimeSeconds = Date.now() / 1000;
57
+ const qrTime = Math.floor(Date.now() / 1000 - orderTimeSeconds);
58
+ const qrTimeString = qrTime.toString();
59
+ const qrAuthCode = (0, crypto_1.createHmac)('sha256', data.qrStartSecret).update(qrTimeString).digest('hex');
60
+ const qrData = `bankid.${data.qrStartToken}.${qrTimeString}.${qrAuthCode}`;
61
+ return qrData;
36
62
  }
37
63
  class IpMismatchError extends Error {
38
64
  expected;
package/src/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/utils.ts"],"names":[],"mappings":";;;AAIA,8CA8BC;AAED,oCAYC;AAhDD,2CAA0D;AAI1D,SAAgB,iBAAiB,CAAC,KAAU;IAC1C,IAAK,KAAoB,EAAE,YAAY,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,KAAmB,CAAA;QACtC,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAA;QAEjD,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;YAClB,OAAO,IAAI,sBAAa,CACtB;gBACE,OAAO,EAAE,4BAA4B;gBACrC,OAAO,EAAE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E,CAAA;IAE1E,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAa,eAAgB,SAAQ,KAAK;IAE/B;IACA;IAFT,YACS,QAAgB,EAChB,MAAc;QAErB,KAAK,CAAC,yBAAyB,QAAQ,SAAS,MAAM,EAAE,CAAC,CAAA;QAHlD,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QAGrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACxD,CAAC;CACF;AAXD,0CAWC"}
@@ -1,19 +0,0 @@
1
- import { BankIdAuthService } from './services/bankid-auth.service';
2
- import { CacheService, RequestContext } from '@vendure/core';
3
- export declare class BankIdAuthController {
4
- private bankIdAuthService;
5
- private cacheService;
6
- constructor(bankIdAuthService: BankIdAuthService, cacheService: CacheService);
7
- initiate(ctx: RequestContext): Promise<{
8
- data: import("./types").InitiateResponse;
9
- }>;
10
- authenticate(ctx: RequestContext, body: {
11
- orderRef: string;
12
- isSameDevice: boolean;
13
- }): Promise<{
14
- data: import("./types").AuthResponse;
15
- }>;
16
- cancel(ctx: RequestContext, body: {
17
- orderRef: string;
18
- }): Promise<void>;
19
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"bankid-auth.controller.js","sourceRoot":"","sources":["../../../../packages/bankid-auth-plugin/src/bankid-auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQuB;AACvB,wEAAkE;AAClE,wCAAiE;AACjE,mCAAyD;AACzD,mCAAyC;AAGlC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAErB;IACA;IAFV,YACU,iBAAoC,EACpC,YAA0B;QAD1B,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ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