@trimble-oss/trimble-id-react 0.1.1 → 1.0.0-rc.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 +9 -15
- package/dist/TIDClient/TIDClient.d.ts +0 -19
- package/dist/TIDClient/index.d.ts +0 -2
- package/dist/TIDClient/interfaces.d.ts +1 -42
- package/dist/TIDClient/storage/cache-storage/CacheManager.d.ts +1 -34
- package/dist/TIDProvider/TIDProvider.d.ts +1 -9
- package/dist/index.d.ts +0 -1
- package/dist/trimble-id-react.es.js +147 -378
- package/dist/trimble-id-react.umd.js +1 -1
- package/package.json +2 -2
- package/dist/TIDClient/storage/cache-storage/CacheKey.d.ts +0 -46
- package/dist/TIDClient/storage/cache-storage/LocalStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/SessionStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/constants.d.ts +0 -15
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @trimble-oss/trimble-id-react
|
|
|
16
16
|
|
|
17
17
|
### Configure Trimble Identity
|
|
18
18
|
|
|
19
|
-
Create a new application in the [Trimble Developer Console](https://
|
|
19
|
+
Create a new application in the [Trimble Developer Console](https://console.trimble.com) portal and configure the following settings:
|
|
20
20
|
|
|
21
21
|
To register your application in Trimble Developer Console:
|
|
22
22
|
|
|
@@ -75,14 +75,13 @@ After wrapping your app with the TIDProvider, you have to configure the TID cred
|
|
|
75
75
|
redirectUrl: "http://localhost:3000/callback",
|
|
76
76
|
logoutRedirectUrl: "http://localhost:3000/logout-callback",
|
|
77
77
|
scopes: ['test']
|
|
78
|
-
}
|
|
79
|
-
persistentOptions: {
|
|
80
|
-
persistentStore: "localStorage"
|
|
81
|
-
}
|
|
78
|
+
}
|
|
82
79
|
})} onRedirectCallback={handleRedirect}>
|
|
83
80
|
<Component/>
|
|
84
81
|
</TIDProvider>
|
|
85
82
|
```
|
|
83
|
+
> **_NOTE:_** Tokens are stored in the browser's memory, as it is considered the most secure option.
|
|
84
|
+
|
|
86
85
|
**2.** You can send the properties directly
|
|
87
86
|
|
|
88
87
|
```tsx
|
|
@@ -92,7 +91,6 @@ After wrapping your app with the TIDProvider, you have to configure the TID cred
|
|
|
92
91
|
redirectUrl={"http://localhost:3000/callback"}
|
|
93
92
|
logoutRedirectUrl={"http://localhost:3000/logout-callback"}
|
|
94
93
|
scopes={['test']}
|
|
95
|
-
persistentStore ={"localStorage"}
|
|
96
94
|
onRedirectCallback={handleRedirect}>
|
|
97
95
|
<Component/>
|
|
98
96
|
</TIDProvider>
|
|
@@ -108,14 +106,12 @@ Production: https://id.trimble.com/.well-known/openid-configuration <br />
|
|
|
108
106
|
* **logoutRedirectUrl** : The URL to which Trimble Identity should redirect after successfully logout a user
|
|
109
107
|
* **scopes** : The type of credentials you want (openID, or application_name)
|
|
110
108
|
|
|
111
|
-
### 2. PersistentOptions configuration
|
|
112
|
-
Type of persistence you want the user and token to be store
|
|
113
|
-
* **in-memory** - This one will only persist will the user stays in the page. By default, persistence will be in-memory.
|
|
114
|
-
* **localStorage** - This persistent doesn't have expiration date
|
|
115
|
-
* **sessionStorage** - This one is cleared when the page session ends
|
|
116
109
|
|
|
117
|
-
> **_NOTE:_**
|
|
110
|
+
> **_NOTE:_**
|
|
111
|
+
>
|
|
112
|
+
> As of version 1.0.0, PersistentOptions have been removed. By default, the SDK now supports in-memory token storage. Using localStorage and sessionStorage for storing sensitive information poses several security risks, including vulnerability to XSS attacks, lack of secure attributes and session hijacking.
|
|
118
113
|
|
|
114
|
+
> When you upgrade to version 1.x, storage options will no longer be available, resulting in a breaking change. For those using an older version of the SDK (i.e., <1.x), it is highly recommended to use the default in-memory storage to avoid any security issues.
|
|
119
115
|
### useAuth
|
|
120
116
|
Use the `useAuth` hook in your components to access authentication state (`isLoading`, `isAuthenticated`, `user`, `error`) and authentication methods (`loginWithRedirect` and `logout`):
|
|
121
117
|
|
|
@@ -126,7 +122,6 @@ Redirect the user to TID using the browser
|
|
|
126
122
|
```tsx
|
|
127
123
|
const {loginWithRedirect}= useAuth()
|
|
128
124
|
await loginWithRedirect()
|
|
129
|
-
|
|
130
125
|
```
|
|
131
126
|
|
|
132
127
|
### logout
|
|
@@ -193,9 +188,8 @@ var error = error.message
|
|
|
193
188
|
It renders a component if the user is authenticated, otherwise redirects the user to the login page. It can be used to protect private components. If the user is not authenticated, they will be redirected to the login page.
|
|
194
189
|
|
|
195
190
|
```tsx
|
|
196
|
-
<AuthenticationGuard renderComponent={
|
|
191
|
+
<AuthenticationGuard renderComponent={<MyPrivateComponent/>}/>
|
|
197
192
|
```
|
|
198
|
-
|
|
199
193
|
> **_NOTE:_** Refer samples for better understanding.
|
|
200
194
|
|
|
201
195
|
## Sample Code
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BearerTokenHttpClientProvider } from '@trimble-oss/trimble-id';
|
|
2
|
-
import { PersistentStore } from './storage/cache-storage/CacheManager';
|
|
3
2
|
import { AuthState, TIDUser, TokenResponse } from './interfaces';
|
|
4
3
|
interface TIDClientConfig {
|
|
5
4
|
/**
|
|
@@ -38,19 +37,6 @@ interface LoginWithRedirectOptions {
|
|
|
38
37
|
*/
|
|
39
38
|
onRedirect?: (url: string) => void;
|
|
40
39
|
}
|
|
41
|
-
interface PersistentOptions {
|
|
42
|
-
/**
|
|
43
|
-
* Type of persistent store you want the user and token to be stored
|
|
44
|
-
*
|
|
45
|
-
* in-memory - This one will only persist will the user stays in the page
|
|
46
|
-
*
|
|
47
|
-
* localStorage - This persistent doesn't have expiration date
|
|
48
|
-
*
|
|
49
|
-
* sessionStorage - This one is cleared when the page session ends
|
|
50
|
-
* @type {PersistentStore}
|
|
51
|
-
*/
|
|
52
|
-
persistentStore: PersistentStore;
|
|
53
|
-
}
|
|
54
40
|
interface LogoutOptions {
|
|
55
41
|
/**
|
|
56
42
|
* Function called when the user redirection is occurring
|
|
@@ -77,11 +63,6 @@ export interface TIDClientOptions {
|
|
|
77
63
|
* @type {TIDClientConfig}
|
|
78
64
|
*/
|
|
79
65
|
config: TIDClientConfig;
|
|
80
|
-
/**
|
|
81
|
-
* Persistent options configuration
|
|
82
|
-
* @type {PersistentOptions}
|
|
83
|
-
*/
|
|
84
|
-
persistentOptions?: PersistentOptions;
|
|
85
66
|
}
|
|
86
67
|
export declare class TIDClient {
|
|
87
68
|
/**
|
|
@@ -45,58 +45,18 @@ export interface TIDUser {
|
|
|
45
45
|
given_name?: string;
|
|
46
46
|
/** Surname(s) or last name(s) of the End-User */
|
|
47
47
|
family_name?: string;
|
|
48
|
-
/** Middle name(s) of the End-User */
|
|
49
|
-
middle_name?: string;
|
|
50
|
-
/** Casual name of the End-User that may or may not be the same as the given_name. */
|
|
51
|
-
nickname?: string;
|
|
52
|
-
/** Shorthand name that the End-User wishes to be referred to at the RP, such as janedoe or j.doe. */
|
|
53
|
-
preferred_username?: string;
|
|
54
|
-
/** URL of the End-User's profile page */
|
|
55
|
-
profile?: string;
|
|
56
48
|
/** URL of the End-User's profile picture */
|
|
57
49
|
picture?: string;
|
|
58
|
-
/** URL of the End-User's Web page or blog */
|
|
59
|
-
website?: string;
|
|
60
50
|
/** End-User's preferred e-mail address */
|
|
61
51
|
email?: string;
|
|
62
52
|
/** True if the End-User's e-mail address has been verified; otherwise false. */
|
|
63
53
|
email_verified?: boolean;
|
|
64
|
-
/** End-User's gender. Values defined by this specification are female and male. */
|
|
65
|
-
gender?: string;
|
|
66
|
-
/** End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format */
|
|
67
|
-
birthdate?: string;
|
|
68
|
-
/** String from zoneinfo [zoneinfo] time zone database representing the End-User's time zone. */
|
|
69
|
-
zoneinfo?: string;
|
|
70
|
-
/** End-User's locale, represented as a BCP47 [RFC5646] language tag. */
|
|
71
|
-
locale?: string;
|
|
72
|
-
/** End-User's preferred telephone number. */
|
|
73
|
-
phone_number?: string;
|
|
74
|
-
/** True if the End-User's phone number has been verified; otherwise false. */
|
|
75
|
-
phone_number_verified?: boolean;
|
|
76
|
-
/** object End-User's preferred address in JSON [RFC4627] */
|
|
77
|
-
address?: OidcAddress;
|
|
78
|
-
/** Time the End-User's information was last updated. */
|
|
79
|
-
updated_at?: number;
|
|
80
|
-
}
|
|
81
|
-
interface OidcAddress {
|
|
82
|
-
/** Full mailing address, formatted for display or use on a mailing label */
|
|
83
|
-
formatted?: string;
|
|
84
|
-
/** Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information */
|
|
85
|
-
street_address?: string;
|
|
86
|
-
/** City or locality component */
|
|
87
|
-
locality?: string;
|
|
88
|
-
/** State, province, prefecture, or region component */
|
|
89
|
-
region?: string;
|
|
90
|
-
/** Zip code or postal code component */
|
|
91
|
-
postal_code?: string;
|
|
92
|
-
/** Country name component */
|
|
93
|
-
country?: string;
|
|
94
54
|
}
|
|
95
55
|
export interface TIDJWTUser {
|
|
96
56
|
/**
|
|
97
57
|
* The issuer of a token
|
|
98
58
|
* Prod: https://id.trimble.com
|
|
99
|
-
* Stage: https://
|
|
59
|
+
* Stage: https://stage.id.trimblecloud.com
|
|
100
60
|
* @type {string}
|
|
101
61
|
*/
|
|
102
62
|
iss: string;
|
|
@@ -216,4 +176,3 @@ export interface TIDJWTUser {
|
|
|
216
176
|
export interface AuthState {
|
|
217
177
|
authState: any;
|
|
218
178
|
}
|
|
219
|
-
export {};
|
|
@@ -1,45 +1,12 @@
|
|
|
1
1
|
import { TIDAuthToken, TIDUser } from '../../interfaces';
|
|
2
|
-
export type PersistentStore = 'in-memory' | 'localStorage' | 'sessionStorage';
|
|
3
|
-
export interface CacheManagerOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Client id of the application created in trimble developer console
|
|
6
|
-
* @type {string}
|
|
7
|
-
*/
|
|
8
|
-
clientId: string;
|
|
9
|
-
/**
|
|
10
|
-
* Type persistent you want the user and token to be store
|
|
11
|
-
* in-memory - This one will only persist will the user stays in the page
|
|
12
|
-
* localStorage - This persistent doesn't have expiration date
|
|
13
|
-
* sessionStorage - This one is cleared when the page session ends
|
|
14
|
-
* @type {PersistentStore}
|
|
15
|
-
*/
|
|
16
|
-
persistentStore: PersistentStore;
|
|
17
|
-
}
|
|
18
2
|
/** Class to manage the store types */
|
|
19
3
|
export declare class CacheManager {
|
|
20
|
-
/**
|
|
21
|
-
* Type persistent you want the user and token to be store
|
|
22
|
-
* in-memory - This one will only persist will the user stays in the page
|
|
23
|
-
* localStorage - This persistent doesn't have expiration date
|
|
24
|
-
* sessionStorage - This one is cleared when the page session ends
|
|
25
|
-
* @type {PersistentStore}
|
|
26
|
-
*/
|
|
27
|
-
private readonly persistentStore;
|
|
28
4
|
/**
|
|
29
5
|
* Cache option selected
|
|
30
6
|
* @type {CacheStorage}
|
|
31
7
|
*/
|
|
32
8
|
private readonly cacheStorage;
|
|
33
|
-
|
|
34
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
35
|
-
* @type {CacheKey}
|
|
36
|
-
*/
|
|
37
|
-
private readonly cacheKey;
|
|
38
|
-
/**
|
|
39
|
-
* Create a cache manager to extract or save the user, and token
|
|
40
|
-
* @param {CacheManagerOptions} options - Configuration for the managing the caching
|
|
41
|
-
*/
|
|
42
|
-
constructor(options: CacheManagerOptions);
|
|
9
|
+
constructor();
|
|
43
10
|
/**
|
|
44
11
|
* Store token in cache
|
|
45
12
|
* @param {TIDAuthToken} token - Token that you want to store in cache
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { TIDClient,
|
|
2
|
+
import { TIDClient, AuthState } from '../TIDClient';
|
|
3
3
|
export interface TIDProviderProps extends PropsWithChildren {
|
|
4
4
|
/**
|
|
5
5
|
* The URL for the Trimble Identity OpenID well known configuration endpoint
|
|
@@ -28,14 +28,6 @@ export interface TIDProviderProps extends PropsWithChildren {
|
|
|
28
28
|
* @type {string[]}
|
|
29
29
|
*/
|
|
30
30
|
scopes?: string[];
|
|
31
|
-
/**
|
|
32
|
-
* Type persistent you want the user and token to be store
|
|
33
|
-
* in-memory - This one will only persist will the user stays in the page
|
|
34
|
-
* localStorage - This persistent doesn't have expiration date
|
|
35
|
-
* sessionStorage - This one is cleared when the page session ends
|
|
36
|
-
* @type {PersistentStore}
|
|
37
|
-
*/
|
|
38
|
-
persistentStore?: PersistentStore;
|
|
39
31
|
/**
|
|
40
32
|
* TID client instance. You can send an instance of the TID Client
|
|
41
33
|
* if you want to handle the initialization yourself
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export { TIDClient } from './TIDClient';
|
|
|
2
2
|
export { TIDContext, useAuth, TIDProvider } from './TIDProvider';
|
|
3
3
|
export { AuthenticationGuard } from './AuthenticationGuard/AuthenticationGuard';
|
|
4
4
|
export type { TokenResponse } from './TIDClient';
|
|
5
|
-
export type { PersistentStore } from './TIDClient';
|