@ovok/core 0.3.1 → 0.3.2

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/README.md CHANGED
@@ -90,3 +90,16 @@ await client.revokeSessions("other");
90
90
 
91
91
  Pass `onUnauthenticated` in the normal Medplum client options to react when a request can no
92
92
  longer refresh its session.
93
+
94
+ ## Multi-factor authentication
95
+
96
+ When password login requires MFA, `login()` returns a verification step instead of an
97
+ `AuthResponse`. Submit the one-time code with `verify()` and use the returned `AuthResponse`:
98
+
99
+ ```typescript
100
+ const result = await client.login(loginBody);
101
+
102
+ if ("nextStep" in result && result.nextStep === "mfa") {
103
+ const authenticated = await result.verify(oneTimeCode);
104
+ }
105
+ ```
@@ -1,4 +1,4 @@
1
1
  import { OvokClient } from "../../ovok-client";
2
- import { AuthResponse } from "../types/AuthResponse";
3
2
  import { LoginBody } from "../types/LoginBody";
4
- export declare function login(this: OvokClient, body: LoginBody): Promise<AuthResponse>;
3
+ import { LoginResponse } from "../types/LoginResponse";
4
+ export declare function login(this: OvokClient, body: LoginBody): Promise<LoginResponse>;
@@ -20,6 +20,32 @@ async function login(body) {
20
20
  if (!tenantCode) {
21
21
  throw new Error("No tenant code found");
22
22
  }
23
+ if (startResponse.nextStep === "mfa") {
24
+ return {
25
+ nextStep: "mfa",
26
+ verify: async (code) => {
27
+ const mfaResponse = await this.post(`auth/tenant/${body.type}/login/mfa`, {
28
+ loginId: startResponse.loginId,
29
+ mfaToken: code,
30
+ }, "application/json");
31
+ if (body.type === "Practitioner") {
32
+ return (0, exchange_code_1.exchangeCode)({
33
+ client: this,
34
+ type: "Practitioner",
35
+ sessionCode: mfaResponse.sessionCode,
36
+ codeVerifier,
37
+ tenantCode,
38
+ });
39
+ }
40
+ return (0, exchange_code_1.exchangeCode)({
41
+ client: this,
42
+ type: "Patient",
43
+ sessionCode: mfaResponse.sessionCode,
44
+ codeVerifier,
45
+ });
46
+ },
47
+ };
48
+ }
23
49
  const exchangeCodeProps = body.type === "Practitioner"
24
50
  ? {
25
51
  client: this,
@@ -0,0 +1,7 @@
1
+ import { AuthResponse } from "./AuthResponse";
2
+ /** The second step returned when password login requires MFA verification. */
3
+ export type MfaLoginStep = {
4
+ nextStep: "mfa";
5
+ verify: (code: string) => Promise<AuthResponse>;
6
+ };
7
+ export type LoginResponse = AuthResponse | MfaLoginStep;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,15 @@
1
1
  import { ContactPoint, HumanName, Patient, Practitioner, ProjectLink, Reference } from "@medplum/fhirtypes";
2
- export interface StartLoginResponse {
3
- nextStep: string;
2
+ export type StartLoginResponse = TokenStartLoginResponse | MfaStartLoginResponse;
3
+ export interface TokenStartLoginResponse {
4
+ nextStep: "token";
4
5
  sessionCode: string;
5
6
  profiles?: ProfileElement[];
6
7
  }
8
+ export interface MfaStartLoginResponse {
9
+ nextStep: "mfa";
10
+ loginId: string;
11
+ profiles?: ProfileElement[];
12
+ }
7
13
  interface ProfileElement {
8
14
  tenantCode: string;
9
15
  project: Project;
@@ -48,7 +48,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
48
48
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
49
49
  software: {
50
50
  name: "@ovok/core",
51
- version: "0.3.0",
51
+ version: "0.3.1",
52
52
  },
53
53
  fhirVersion: "4.0.1",
54
54
  format: ["json"],
@@ -1,4 +1,5 @@
1
1
  export * from "../client/auth/types/AuthResponse";
2
+ export * from "../client/auth/types/LoginResponse";
2
3
  export * from "../client/auth/types/LoginBody";
3
4
  export * from "../client/auth/types/RegisterBody";
4
5
  export * from "../client/auth/types/ChangePasswordBody";
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Auth types
18
18
  __exportStar(require("../client/auth/types/AuthResponse"), exports);
19
+ __exportStar(require("../client/auth/types/LoginResponse"), exports);
19
20
  __exportStar(require("../client/auth/types/LoginBody"), exports);
20
21
  __exportStar(require("../client/auth/types/RegisterBody"), exports);
21
22
  __exportStar(require("../client/auth/types/ChangePasswordBody"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",