@@ -4,24 +4,81 @@ This project is focused on providing web client support for the OpenTDF platform
4
4
This includes encrypting and decrypting TDF content,
5
5
and some management tasks for ABAC.
6
6
7
- ## Usage
7
+ ## Usage (NanoTDF)
8
8
9
9
``` typescript
10
- // currently we support only ESM import
11
- import { AuthProviders , NanoTDFClient } from ' @opentdf/client' ;
12
-
13
- const oidcCredentials: RefreshTokenCredentials = {
14
- clientId: keycloakClientId ,
15
- exchange: ' refresh' ,
16
- refreshToken: refreshToken ,
17
- oidcOrigin: keycloakUrlWithRealm ,
18
- }
19
- const authProvider = await AuthProviders .refreshAuthProvider (oidcCredentials );
20
- const client = new NanoTDFClient (authProvider , access );
21
- const cipherText = await client .encrypt (plainText );
22
- const clearText = await client .decrypt (cipherText );
10
+ import { AuthProviders , NanoTDFClient } from ' @opentdf/client' ;
11
+
12
+ // Configuration Options
13
+ const kasEndpoint = " http://localhost:65432/kas" ;
14
+
15
+ // Authentication options (vary by middleware)
16
+ const oidcOrigin = " http://localhost:65432/auth/realms/tdf" ;
17
+ const clientId = " applicationNameFromIdP" ;
18
+ const refreshToken = " refreshTokenValueFromIdP" ;
19
+
20
+ // AuthProviders are middlewares that add `Authorization` or other bearer tokens to requests.
21
+ // These include The `refresh` provider can be handed a refresh and optional access token.
22
+ const authProvider = await AuthProviders .refreshAuthProvider ({
23
+ clientId ,
24
+ exchange: ' refresh' ,
25
+ refreshToken ,
26
+ oidcOrigin ,
27
+ });
28
+
29
+ const client = new NanoTDFClient ({
30
+ authProvider ,
31
+ kasEndpoint ,
32
+ });
33
+ client .dataAttributes = [" http://opentdf.io/attr/class/value/secret" ]
34
+ const cipherText = await client .encrypt (plainText );
35
+ const clearText = await client .decrypt (cipherText );
23
36
```
24
37
38
+ ### Authorization Middleware Options
39
+
40
+ #### Client Credentials
41
+
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.
44
+
45
+ ``` typescript
46
+ import { AuthProviders } from ' @opentdf/client' ;
47
+
48
+ // Authentication options (vary by middleware)
49
+ const oidcOrigin = " http://localhost:65432/auth/realms/tdf" ;
50
+ const clientId = " username" ;
51
+ const clientSecret = " IdP_GENERATED_SECRET" ;
52
+
53
+ const authProvider = await AuthProviders .clientSecretAuthProvider ({
54
+ clientId ,
55
+ clientSecret ,
56
+ oidcOrigin ,
57
+ exchange: ' client' ,
58
+ });
59
+ ```
60
+
61
+ #### Given Credentials
62
+
63
+ The ` refreshAuthProvider ` and ` externalAuthProvder ` allow the application developer to use existing tokens.
64
+
65
+ ``` typescript
66
+ import { AuthProviders , NanoTDFClient } from ' @opentdf/client' ;
67
+
68
+ const oidcCredentials: RefreshTokenCredentials = {
69
+ clientId: keycloakClientId ,
70
+ exchange: ' refresh' ,
71
+ refreshToken: refreshToken ,
72
+ oidcOrigin: keycloakUrlWithRealm ,
73
+ }
74
+ ```
75
+
76
+ #### Building your own provider
77
+
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 )
81
+
25
82
## Build and Test
26
83
27
84
``` shell
@@ -37,7 +94,7 @@ We develop using [nvm](https://github.com/nvm-sh/nvm#readme),
37
94
which allows us to pin to the same version of ` npm ` easily.
38
95
39
96
- Install [ nvm] ( https://github.com/nvm-sh/nvm#readme )
40
- - see https://github.com/nvm-sh/nvm#installing-and-updating
97
+ - see < https://github.com/nvm-sh/nvm#installing-and-updating >
41
98
- ` nvm use ` will install ` npm ` and ` node `
42
99
43
100
[ ![ Build] ( https://github.com/opentdf/client-web/actions/workflows/build.yaml/badge.svg )] ( https://github.com/opentdf/client-web/actions/workflows/build.yaml )
0 commit comments