1
1
# OpenTDF Web Browser Client opentdf
2
2
3
- This project is focused on providing web client support for the OpenTDF platform.
4
- This includes encrypting and decrypting TDF content,
5
- and some management tasks for ABAC.
3
+ This project is focused on providing web client support for the OpenTDF platform. This includes
4
+ encrypting and decrypting TDF content, and management tasks for ABAC.
5
+
6
+ ** [ OpenTDF Web Documentation] ( https://opentdf.github.io/web-sdk/ ) **
6
7
7
8
## Usage (NanoTDF)
8
9
9
10
``` typescript
10
11
import { AuthProviders , NanoTDFClient } from ' @opentdf/sdk' ;
11
12
12
13
// Configuration Options
13
- const kasEndpoint = " http://localhost:65432/kas" ;
14
+ const kasEndpoint = ' http://localhost:65432/kas' ;
14
15
15
16
// Authentication options (vary by middleware)
16
- const oidcOrigin = " http://localhost:65432/auth/realms/opentdf" ;
17
- const clientId = " applicationNameFromIdP" ;
18
- const refreshToken = " refreshTokenValueFromIdP" ;
17
+ const oidcOrigin = ' http://localhost:65432/auth/realms/opentdf' ;
18
+ const clientId = ' applicationNameFromIdP' ;
19
+ const refreshToken = ' refreshTokenValueFromIdP' ;
19
20
20
21
// AuthProviders are middlewares that add `Authorization` or other bearer tokens to requests.
21
22
// These include The `refresh` provider can be handed a refresh and optional access token.
@@ -30,7 +31,7 @@ const client = new NanoTDFClient({
30
31
authProvider ,
31
32
kasEndpoint ,
32
33
});
33
- client .dataAttributes = [" http://opentdf.io/attr/class/value/secret" ]
34
+ client .dataAttributes = [' http://opentdf.io/attr/class/value/secret' ];
34
35
const cipherText = await client .encrypt (plainText );
35
36
const clearText = await client .decrypt (cipherText );
36
37
```
@@ -39,16 +40,16 @@ const clearText = await client.decrypt(cipherText);
39
40
40
41
#### Client Credentials
41
42
42
- For long running server-side apps, a client id + secret is allowed with OAuth2.
43
- This should not be used in a browser, but within a Deno or Node process.
43
+ For long running server-side apps, a client id + secret is allowed with OAuth2. This should not be
44
+ used in a browser, but within a Deno or Node process.
44
45
45
46
``` typescript
46
47
import { AuthProviders } from ' @opentdf/sdk' ;
47
48
48
49
// Authentication options (vary by middleware)
49
- const oidcOrigin = " http://localhost:65432/auth/realms/opentdf" ;
50
- const clientId = " username" ;
51
- const clientSecret = " IdP_GENERATED_SECRET" ;
50
+ const oidcOrigin = ' http://localhost:65432/auth/realms/opentdf' ;
51
+ const clientId = ' username' ;
52
+ const clientSecret = ' IdP_GENERATED_SECRET' ;
52
53
53
54
const authProvider = await AuthProviders .clientSecretAuthProvider ({
54
55
clientId ,
@@ -60,7 +61,8 @@ const authProvider = await AuthProviders.clientSecretAuthProvider({
60
61
61
62
#### Given Credentials
62
63
63
- The ` refreshAuthProvider ` and ` externalAuthProvder ` allow the application developer to use existing tokens.
64
+ The ` refreshAuthProvider ` and ` externalAuthProvder ` allow the application developer to use existing
65
+ tokens.
64
66
65
67
``` typescript
66
68
import { AuthProviders , NanoTDFClient } from ' @opentdf/sdk' ;
@@ -70,14 +72,13 @@ const oidcCredentials: RefreshTokenCredentials = {
70
72
exchange: ' refresh' ,
71
73
refreshToken: refreshToken ,
72
74
oidcOrigin: keycloakUrlWithRealm ,
73
- }
75
+ };
74
76
```
75
77
76
78
#### Building your own provider
77
79
78
- A more complete example of using an OIDC compatible provider
79
- with support for authorization code flow with PKCE and DPoP
80
- is available in the [ sample ` web-app ` folder] ( ./web-app/src/session.ts )
80
+ A more complete example of using an OIDC compatible provider with support for authorization code
81
+ flow with PKCE and DPoP is available in the [ sample ` web-app ` folder] ( ./web-app/src/session.ts )
81
82
82
83
## Platform Client
83
84
@@ -91,7 +92,9 @@ Below is an example of how to use the `PlatformClient` to interact with the plat
91
92
import { AuthProvider , OpenTDF } from ' @opentdf/sdk' ;
92
93
import { PlatformClient } from ' @opentdf/sdk/platform' ;
93
94
94
- const authProvider: AuthProvider = {/* configure your auth provider */ };
95
+ const authProvider: AuthProvider = {
96
+ /* configure your auth provider */
97
+ };
95
98
const platform = new PlatformClient ({
96
99
authProvider ,
97
100
platformUrl: ' /api' ,
@@ -112,9 +115,12 @@ exampleUsage();
112
115
113
116
### Using Interceptor
114
117
115
- The ` PlatformClient ` client supports the use of interceptors for customizing RPC calls. Interceptors allow you to modify requests or responses, such as adding custom headers or handling authentication, before or after the RPC call is executed.
118
+ The ` PlatformClient ` client supports the use of interceptors for customizing RPC calls. Interceptors
119
+ allow you to modify requests or responses, such as adding custom headers or handling authentication,
120
+ before or after the RPC call is executed.
116
121
117
- Below is an example of using an interceptor to add an ` Authorization ` header to all outgoing requests:
122
+ Below is an example of using an interceptor to add an ` Authorization ` header to all outgoing
123
+ requests:
118
124
119
125
``` typescript
120
126
import { platformConnect , PlatformClient } from ' @opentdf/sdk/platform' ;
@@ -131,42 +137,43 @@ const platform = new PlatformClient({
131
137
```
132
138
133
139
### Key Notes
134
- Interceptors are particularly useful for scenarios where you need to dynamically modify requests, such as adding authentication tokens or logging request/response data.
135
140
141
+ Interceptors are particularly useful for scenarios where you need to dynamically modify requests,
142
+ such as adding authentication tokens or logging request/response data.
136
143
137
144
## Building and Testing
138
145
139
146
### Makefile Commands
140
147
141
- The project provides a ` Makefile ` to simplify common development tasks. Below are the available commands:
142
-
143
- | Command | Description |
144
- | -------------------| ----------------------------------------------------------------------------------------------|
145
- | ` make ` | Builds and tests everything (default target). |
146
- | ` make start ` | Builds all packages and starts the web application in development mode. |
147
- | ` make ci ` | Installs dependencies and links the SDK package for all subprojects. |
148
- | ` make i ` | Installs dependencies and links the SDK package for all subprojects (without clean install). |
149
- | ` make clean ` | Removes build artifacts, packed files, and ` node_modules ` directories. |
150
- | ` make cli ` | Builds and packs the CLI tool. |
151
- | ` make audit ` | Runs ` npm audit ` for all packages except dev dependencies. |
152
- | ` make format ` | Runs code formatting for all packages. |
153
- | ` make lint ` | Runs linter for all packages. |
154
- | ` make test ` | Runs tests for all packages. |
155
- | ` make license-check ` | Checks license compliance for all packages. |
156
- | ` make doc ` | Generates documentation for the SDK. |
157
- | ` make generate-platform ` | Runs the platform code generation script. |
158
- | ` make dist ` | Copies the SDK package to the root directory. |
148
+ The project provides a ` Makefile ` to simplify common development tasks. Below are the available
149
+ commands:
150
+
151
+ | Command | Description |
152
+ | ------------------------ | -------------------------------------------------------------------------------------------- |
153
+ | ` make ` | Builds and tests everything (default target). |
154
+ | ` make start ` | Builds all packages and starts the web application in development mode. |
155
+ | ` make ci ` | Installs dependencies and links the SDK package for all subprojects. |
156
+ | ` make i ` | Installs dependencies and links the SDK package for all subprojects (without clean install). |
157
+ | ` make clean ` | Removes build artifacts, packed files, and ` node_modules ` directories. |
158
+ | ` make cli ` | Builds and packs the CLI tool. |
159
+ | ` make audit ` | Runs ` npm audit ` for all packages except dev dependencies. |
160
+ | ` make format ` | Runs code formatting for all packages. |
161
+ | ` make lint ` | Runs linter for all packages. |
162
+ | ` make test ` | Runs tests for all packages. |
163
+ | ` make license-check ` | Checks license compliance for all packages. |
164
+ | ` make doc ` | Generates documentation for the SDK. |
165
+ | ` make generate-platform ` | Runs the platform code generation script. |
166
+ | ` make dist ` | Copies the SDK package to the root directory. |
159
167
160
168
You can run any of these commands using ` make <command> ` .
161
169
162
-
163
170
## Contribute
164
171
165
172
### Prerequisites
166
173
167
- Developing with this code requires a recent version of ` npm ` and ` node ` .
168
- We develop using [ nvm] ( https://github.com/nvm-sh/nvm#readme ) ,
169
- which allows us to pin to the same version of ` npm ` easily.
174
+ Developing with this code requires a recent version of ` npm ` and ` node ` . We develop using
175
+ [ nvm] ( https://github.com/nvm-sh/nvm#readme ) , which allows us to pin to the same version of ` npm `
176
+ easily.
170
177
171
178
- Install [ nvm] ( https://github.com/nvm-sh/nvm#readme )
172
179
- see < https://github.com/nvm-sh/nvm#installing-and-updating >
@@ -180,4 +187,4 @@ To check out, build, and validate your installation, and test the sample web app
180
187
nvm use
181
188
make test
182
189
make start
183
- ```
190
+ ```
0 commit comments