This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathauthorization.ts
153 lines (140 loc) · 5.16 KB
/
authorization.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { BatchReadWriteRequest } from './bundle';
import { TypeOperation, SystemOperation, KeyValueMap } from './constants';
import { ExportType } from './bulkDataAccess';
import { SearchFilter } from './search';
export interface BulkDataAuth {
operation:
| 'initiate-export'
| 'initiate-import'
| 'get-status-export'
| 'get-status-import'
| 'cancel-export'
| 'cancel-import';
exportType?: ExportType;
importResources?: string[];
}
export type VerbType = 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
/**
* Contains information from incoming http request. As well as
* additional context information such as use case specific auth handlers or
* operational information specific to this request.
*/
export interface RequestContext {
verb?: VerbType;
url: string;
hostname: string;
headers: KeyValueMap;
contextInfo: KeyValueMap;
}
export interface VerifyAccessTokenRequest {
accessToken: string;
operation: TypeOperation | SystemOperation;
resourceType?: string;
requestContext?: RequestContext;
id?: string;
vid?: string;
bulkDataAuth?: BulkDataAuth;
/**
* The FHIR server base URL. It may contain a path in addition to the hostname. See: https://www.hl7.org/fhir/http.html#root
* @example https://fhir-server/path
*/
fhirServiceBaseUrl?: string;
}
export interface AuthorizationBundleRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
requests: BatchReadWriteRequest[];
/**
* The FHIR server base URL. It may contain a path in addition to the hostname. See: https://www.hl7.org/fhir/http.html#root
* @example https://fhir-server/path
*/
fhirServiceBaseUrl?: string;
}
export interface AllowedResourceTypesForOperationRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
operation: TypeOperation | SystemOperation;
}
export interface AccessBulkDataJobRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
jobOwnerId: string;
}
export interface ReadResponseAuthorizedRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
operation: TypeOperation | SystemOperation;
readResponse: any;
/**
* The FHIR server base URL. It may contain a path in addition to the hostname. See: https://www.hl7.org/fhir/http.html#root
* @example https://fhir-server/path
*/
fhirServiceBaseUrl?: string;
}
export interface WriteRequestAuthorizedRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
operation: TypeOperation;
resourceBody: any;
/**
* The FHIR server base URL. It may contain a path in addition to the hostname. See: https://www.hl7.org/fhir/http.html#root
* @example https://fhir-server/path
*/
fhirServiceBaseUrl?: string;
}
export interface GetSearchFilterBasedOnIdentityRequest {
userIdentity: KeyValueMap;
requestContext?: RequestContext;
operation: 'search-type' | 'search-system' | 'history-type' | 'history-system' | 'history-instance';
/** Used for type and instance based searching */
resourceType?: string;
/** Used exclusively for `history-instance` operation */
id?: string;
/**
* The FHIR server base URL. It may contain a path in addition to the hostname. See: https://www.hl7.org/fhir/http.html#root
* @example https://fhir-server/path
*/
fhirServiceBaseUrl?: string;
}
export interface Authorization {
/**
* Validates the access token and returns the userIdentity
* @returns decoded access token; effectively the userIdentity
* @throws UnauthorizedError
*/
verifyAccessToken(request: VerifyAccessTokenRequest): Promise<KeyValueMap>;
/**
* Used to authorize Bundle transactions
* @throws UnauthorizedError
*/
isBundleRequestAuthorized(request: AuthorizationBundleRequest): Promise<void>;
/*
* Used to determine if a requester can access a Bulk Data Job
* @throws UnauthorizedError
*/
isAccessBulkDataJobAllowed(request: AccessBulkDataJobRequest): Promise<void>;
/**
* @returns resourceTypes for which the requester is allowed to perform the requested operation.
*/
getAllowedResourceTypesForOperation(request: AllowedResourceTypesForOperationRequest): Promise<string[]>;
/**
* Filters and validates the read response per the specific user
* @returns a potentially filtered readResponse
* @throws UnauthorizedError
*/
authorizeAndFilterReadResponse(request: ReadResponseAuthorizedRequest): Promise<any>;
/**
* Examines the writes request body to authorize if user is allowed to perform the action requested
* @throws UnauthorizedError
*/
isWriteRequestAuthorized(request: WriteRequestAuthorizedRequest): Promise<void>;
/**
* Returns search filters to prevent doing expensive overly permissive search
* @returns Search filter
*/
getSearchFilterBasedOnIdentity(request: GetSearchFilterBasedOnIdentityRequest): Promise<SearchFilter[]>;
}