@trimble-oss/trimble-id-react 0.0.1-rc.1
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 +186 -0
- package/dist/AuthenticationGuard/AuthenticationGuard.d.ts +13 -0
- package/dist/TIDClient/TIDClient.d.ts +207 -0
- package/dist/TIDClient/constants.d.ts +10 -0
- package/dist/TIDClient/exceptions.d.ts +8 -0
- package/dist/TIDClient/index.d.ts +5 -0
- package/dist/TIDClient/interfaces.d.ts +206 -0
- package/dist/TIDClient/storage/cache-storage/CacheKey.d.ts +46 -0
- package/dist/TIDClient/storage/cache-storage/CacheManager.d.ts +70 -0
- package/dist/TIDClient/storage/cache-storage/InMemoryCache.d.ts +12 -0
- package/dist/TIDClient/storage/cache-storage/LocalStorageCache.d.ts +67 -0
- package/dist/TIDClient/storage/cache-storage/SessionStorageCache.d.ts +67 -0
- package/dist/TIDClient/storage/cache-storage/constants.d.ts +15 -0
- package/dist/TIDClient/storage/cookies/CookiesManager.d.ts +48 -0
- package/dist/TIDClient/storage/cookies/CookiesStorage.d.ts +42 -0
- package/dist/TIDClient/storage/cookies/constants.d.ts +5 -0
- package/dist/TIDClient/utils.d.ts +61 -0
- package/dist/TIDProvider/TIDContext.d.ts +83 -0
- package/dist/TIDProvider/TIDProvider.d.ts +90 -0
- package/dist/TIDProvider/index.d.ts +4 -0
- package/dist/TIDProvider/reducer.d.ts +28 -0
- package/dist/TIDProvider/state.d.ts +26 -0
- package/dist/TIDProvider/useAuth.d.ts +16 -0
- package/dist/index.d.ts +4 -0
- package/dist/trimble-id-react.es.js +1457 -0
- package/dist/trimble-id-react.umd.js +27 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# @trimble-oss/trimble-id-react
|
|
2
|
+
|
|
3
|
+
Trimble Identity SDK for React app.
|
|
4
|
+
|
|
5
|
+
🚀 [Getting Started](#getting-started) - 📚 [Usage Reference](#usage-reference) - 💬 [Support](#support)
|
|
6
|
+
|
|
7
|
+
## <a name="getting-started">Getting Started</a>
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
|
|
11
|
+
Using [npm](https://npmjs.org) in your project directory run the following command:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @trimble-oss/trimble-id-react
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Configure Trimble Identity
|
|
18
|
+
|
|
19
|
+
Create a new application in the [Trimble Developer Console](https://developer.console.trimble.com) portal and configure the following settings:
|
|
20
|
+
|
|
21
|
+
To register your service application in Trimble Developer Console:
|
|
22
|
+
|
|
23
|
+
1. On the left pane select Identity Management > Applications.
|
|
24
|
+
|
|
25
|
+
2. On the Applications home page, in the top right corner select + NEW APPLICATION. The Create Application page displays.
|
|
26
|
+
|
|
27
|
+
3. Select Continue to enter the applications details.
|
|
28
|
+
|
|
29
|
+
| Field | Description |
|
|
30
|
+
| ----------- | ----------- |
|
|
31
|
+
| Name | Name of your application |
|
|
32
|
+
| Display Name| Provide a display name of the application. |
|
|
33
|
+
| Description | Provide a description for the application. |
|
|
34
|
+
|
|
35
|
+
4. Configure OAuth application grant types as `Authorization Code Grant` and `Use Refresh tokens` in order to use this SDK.
|
|
36
|
+
|
|
37
|
+
5. Select "Create Application" to save changes.
|
|
38
|
+
|
|
39
|
+
Take note of the Client ID and URLs under the "Basic Information" section. You'll need these values to configure the SDK.
|
|
40
|
+
|
|
41
|
+
For more information, see [Authentication documentation](https://developer.trimble.com/docs/authentication).
|
|
42
|
+
|
|
43
|
+
## <a name="usage-reference">Usage Reference</a>
|
|
44
|
+
|
|
45
|
+
### Configure the SDK
|
|
46
|
+
|
|
47
|
+
SDK provides a React component `TID Provider` that will handle the
|
|
48
|
+
process related to the authentication for you. Configure the SDK by wrapping your application in `TIDProvider`:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
<TIDProvider tidClient={new TIDClient(config)} onRedirectCallback={handleRedirect}>
|
|
52
|
+
<Component/>
|
|
53
|
+
</TIDProvider>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Here TIDProvider can take two parameters :
|
|
57
|
+
* **tidClient** : TID client instance. You can send an instance of the TID Client if you want to handle the initialization yourself
|
|
58
|
+
* **onRedirectCallback** - When the redirect callback occur this function will be call once the user is login using the TIDClient. This could allow you to redirect the user into another page after the login happen.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
After wrapping your app with the TIDProvider, you have to configure the TID credentials registered in TrimbleCloud console. There are two ways of doing this:
|
|
62
|
+
|
|
63
|
+
**1.** Using the `TIDClient`
|
|
64
|
+
```tsx
|
|
65
|
+
<TIDProvider tidClient={new TIDClient({
|
|
66
|
+
config: {
|
|
67
|
+
configurationEndpoint: "<OAUTH_WELL_KNOWN_URL>",
|
|
68
|
+
clientId: "CLIENT_ID",
|
|
69
|
+
redirectUrl: "http://localhost:3000/callback",
|
|
70
|
+
logoutRedirectUrl: "http://localhost:3000/logout-callback",
|
|
71
|
+
scopes: ['test']
|
|
72
|
+
},
|
|
73
|
+
persistentOptions: {
|
|
74
|
+
persistentStore: ('localStorage' as PersistentStore),
|
|
75
|
+
}
|
|
76
|
+
})} onRedirectCallback={handleRedirect}>
|
|
77
|
+
<Component/>
|
|
78
|
+
</TIDProvider>
|
|
79
|
+
```
|
|
80
|
+
**2.** You can send the properties directly
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
<TIDProvider
|
|
84
|
+
configurationEndpoint={"<OAUTH_WELL_KNOWN_URL>"}
|
|
85
|
+
clientId={"CLIENT_ID"}
|
|
86
|
+
redirectUrl={"http://localhost:3000/callback"}
|
|
87
|
+
logoutRedirectUrl={"http://localhost:3000/logout-callback"}
|
|
88
|
+
scopes={['test']}
|
|
89
|
+
onRedirectCallback={handleRedirect}>
|
|
90
|
+
<Component/>
|
|
91
|
+
</TIDProvider>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Below are the parameters of TIDClient.
|
|
95
|
+
### 1. TID Client configurations:
|
|
96
|
+
|
|
97
|
+
* **ConfigurationEndpoint** : The URL for the Trimble Identity OpenID well known configuration endpoint <br />
|
|
98
|
+
Production: https://id.trimble.com/.well-known/openid-configuration <br />
|
|
99
|
+
* **clientId** : Client id of the application created in Trimble Developer Console
|
|
100
|
+
* **redirectUrl** : The URL to which Trimble Identity should redirect after successfully authenticating a user
|
|
101
|
+
* **logoutRedirectUrl** : The URL to which Trimble Identity should redirect after successfully logout a user
|
|
102
|
+
* **scopes** : The type of credentials you want (openID, or application_name)
|
|
103
|
+
|
|
104
|
+
### 2. PersistentOptions configuration
|
|
105
|
+
Type of persistence you want the user and token to be store
|
|
106
|
+
* **localStorage** - This persistent doesn't have expiration date
|
|
107
|
+
* **sessionStorage** - This one is cleared when the page session ends
|
|
108
|
+
|
|
109
|
+
Use the `useAuth` hook in your components to access authentication state (`isLoading`, `isAuthenticated` and `user`) and authentication methods (`loginWithRedirect` and `logout`):
|
|
110
|
+
|
|
111
|
+
### loginWithRedirect
|
|
112
|
+
|
|
113
|
+
Redirect the user to TID using the browser
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
const {loginWithRedirect}= useAuth()
|
|
117
|
+
await loginWithRedirect()
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### logout
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
const {logout}= useAuth()
|
|
125
|
+
await logout()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### isAuthenticated
|
|
129
|
+
|
|
130
|
+
True if the user is authenticated.
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
const {isAuthenticated}= useAuth()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### isLoading
|
|
137
|
+
|
|
138
|
+
This property will indicate the developer that the TID Provider is still loading information from the cache By default, this state will be true, this will allow the developers to handle async functionality Note: This property will only be true the first time that the app executes.
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
const {isLoading}= useAuth()
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### getAccessTokenSilently
|
|
145
|
+
|
|
146
|
+
Gets the access token from cache. SDK handles token refresh when token expires.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
const {getAccessTokenSilently}= useAuth()
|
|
150
|
+
var access_token = await useAuth().getAccessTokenSilently()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### user
|
|
154
|
+
|
|
155
|
+
Information of the user in session
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
const {user}= useAuth()
|
|
159
|
+
var name = user?.name
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### AuthenticationGuard
|
|
164
|
+
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.
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
<AuthenticationGuard renderComponent={() => <MyPrivateComponent/>}/>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
> **_NOTE:_** Refer samples for better understanding.
|
|
171
|
+
|
|
172
|
+
## Sample Code
|
|
173
|
+
|
|
174
|
+
See here for [Sample Code](https://github.com/trimble-oss/trimble-id-sdk-docs-for-react/blob/main/samples) for reference.
|
|
175
|
+
|
|
176
|
+
## Release notes
|
|
177
|
+
|
|
178
|
+
See here for [releases](https://github.com/trimble-oss/trimble-id-sdk-docs-for-react/blob/main/release-notes/CHANGELOG.md)
|
|
179
|
+
|
|
180
|
+
## Raise an issue
|
|
181
|
+
|
|
182
|
+
To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/trimble-oss/tcp-sdk-docs-for-net/issues).
|
|
183
|
+
|
|
184
|
+
## <a name="support">Support</a>
|
|
185
|
+
|
|
186
|
+
Send email to [cloudplatform_support@trimble.com](mailto:cloudplatform_support@trimble.com)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
interface IAuthenticationGuard {
|
|
4
|
+
renderComponent: ReactElement;
|
|
5
|
+
loader?: ReactElement;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders a component if the user is authenticated, otherwise redirects the user to the login page.
|
|
9
|
+
* @param renderComponent The component to render if the user is authenticated
|
|
10
|
+
* @param loader The component to render while TIDProvider is loading
|
|
11
|
+
*/
|
|
12
|
+
export declare const AuthenticationGuard: ({ renderComponent, loader }: IAuthenticationGuard) => React.JSX.Element;
|
|
13
|
+
export default AuthenticationGuard;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { BearerTokenHttpClientProvider } from '@trimble-oss/trimble-id';
|
|
2
|
+
import { PersistentStore } from './storage/cache-storage/CacheManager';
|
|
3
|
+
import { AuthState, TIDUser } from './interfaces';
|
|
4
|
+
interface TIDClientConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The URL for the Trimble Identity OpenID well known configuration endpoint
|
|
7
|
+
* Staging: https://stage.id.trimblecloud.com/.well-known/openid-configuration
|
|
8
|
+
* Production: https://id.trimble.com/.well-known/openid-configuration
|
|
9
|
+
* @type {string}
|
|
10
|
+
*/
|
|
11
|
+
configurationEndpoint: string;
|
|
12
|
+
/**
|
|
13
|
+
* Client id of the application created in trimble developer console
|
|
14
|
+
* @type {string}
|
|
15
|
+
*/
|
|
16
|
+
clientId: string;
|
|
17
|
+
/**
|
|
18
|
+
* The URL to which Trimble Identity should redirect after successfully authenticating a user
|
|
19
|
+
* @type {string}
|
|
20
|
+
*/
|
|
21
|
+
redirectUrl: string;
|
|
22
|
+
/**
|
|
23
|
+
* The URL to which Trimble Identity should redirect after successfully logout a user
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
logoutRedirectUrl: string;
|
|
27
|
+
/**
|
|
28
|
+
* The type of credentials you want (openID, or application_name)
|
|
29
|
+
* @type {string[]}
|
|
30
|
+
*/
|
|
31
|
+
scopes: string[];
|
|
32
|
+
}
|
|
33
|
+
interface LoginWithRedirectOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Function called when the user redirection is occurring
|
|
36
|
+
* If you send this function you will need to handle the redirection
|
|
37
|
+
* @param {string} url - Redirect url to TID with the necessary information to log in the user
|
|
38
|
+
*/
|
|
39
|
+
onRedirect?: (url: string) => void;
|
|
40
|
+
}
|
|
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
|
+
interface LogoutOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Function called when the user redirection is occurring
|
|
57
|
+
* If you send this function you will need to handle the redirection
|
|
58
|
+
* @param {string} url - Redirect url to TID with the necessary information to log out the user
|
|
59
|
+
*/
|
|
60
|
+
onRedirect?: (url: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* If you want to disable the auto redirect to TID after the logout is successful you can set this to true
|
|
63
|
+
* If you set this to true you will need to handle the redirection and the provider will clear the user information from the context
|
|
64
|
+
*
|
|
65
|
+
* **IMPORTANT**: If you set this to true the user information will be cleared from the context and isAuthenticated will be false
|
|
66
|
+
* if you are using the AuthenticationGuard component it will redirect the user to the login page automatically
|
|
67
|
+
* @default false
|
|
68
|
+
* @type {boolean}
|
|
69
|
+
* @example
|
|
70
|
+
* logout({disabledAutoRedirect: true})
|
|
71
|
+
*/
|
|
72
|
+
disabledAutoRedirect?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface TIDClientOptions {
|
|
75
|
+
/**
|
|
76
|
+
* TID client configuration
|
|
77
|
+
* @type {TIDClientConfig}
|
|
78
|
+
*/
|
|
79
|
+
config: TIDClientConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Persistent options configuration
|
|
82
|
+
* @type {PersistentOptions}
|
|
83
|
+
*/
|
|
84
|
+
persistentOptions?: PersistentOptions;
|
|
85
|
+
}
|
|
86
|
+
export declare class TIDClient {
|
|
87
|
+
/**
|
|
88
|
+
* Token provider SDK. This object handles all necessary communication with TID
|
|
89
|
+
* @type {AuthorizationCodeGrantTokenProvider}
|
|
90
|
+
*/
|
|
91
|
+
private tokenProvider;
|
|
92
|
+
/**
|
|
93
|
+
* This object manage all caching, and all configurations necessary
|
|
94
|
+
* @type {CacheManager}
|
|
95
|
+
*/
|
|
96
|
+
private readonly cacheManager;
|
|
97
|
+
/**
|
|
98
|
+
* This object manage all cookies administration, and all configurations necessary
|
|
99
|
+
* @type {CookiesManager}
|
|
100
|
+
*/
|
|
101
|
+
private readonly cookiesManager;
|
|
102
|
+
/**
|
|
103
|
+
* Client id of the application created in trimble developer console
|
|
104
|
+
* @type {string}
|
|
105
|
+
*/
|
|
106
|
+
private readonly clientId;
|
|
107
|
+
/**
|
|
108
|
+
* Callback url to redirect the user after the authentication is successful
|
|
109
|
+
* @type {string}
|
|
110
|
+
*/
|
|
111
|
+
private readonly redirectUrl;
|
|
112
|
+
/**
|
|
113
|
+
* AnalyticsHttpClient for sending events
|
|
114
|
+
* @type {AnalyticsHttpClient}
|
|
115
|
+
*/
|
|
116
|
+
private readonly analyticshttpclient;
|
|
117
|
+
/**
|
|
118
|
+
* Create a TID client to handle manage all user authentication functions and information
|
|
119
|
+
* @param {CacheManagerOptions} props - TID client configuration
|
|
120
|
+
*/
|
|
121
|
+
constructor(props: TIDClientOptions);
|
|
122
|
+
/**
|
|
123
|
+
* Redirect the user to TID using the browser
|
|
124
|
+
* @param {LoginWithRedirectOptions} options - Custom configuration for the redirection
|
|
125
|
+
* @return {Promise<void>} Empty promise
|
|
126
|
+
* @example No configuration
|
|
127
|
+
* loginWithRedirect()
|
|
128
|
+
* // Automatically redirects the user to TID with all necessary parameters
|
|
129
|
+
* @example Custom redirect
|
|
130
|
+
* loginWithRedirect({onRedirect: (url) => router.navigate(url)})
|
|
131
|
+
* // Redirect calls onRedirect with the log-out url for TID
|
|
132
|
+
* // So it can be handled by the developer
|
|
133
|
+
*/
|
|
134
|
+
loginWithRedirect(options?: LoginWithRedirectOptions): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Authenticated the user using the url callback params
|
|
137
|
+
* @param {string} url - Custom configuration for the redirection
|
|
138
|
+
* @return {Promise<AuthState>} Object contain the state returned from TID
|
|
139
|
+
* @throws {CodeVerifierNotFoundException} Will throw an exception if the session doesn't contain the code verifier
|
|
140
|
+
* @example No configuration
|
|
141
|
+
* handleCallback()
|
|
142
|
+
* // Will automatically take the url from the browser and try to log in the user
|
|
143
|
+
* @example Custom url
|
|
144
|
+
* handleCallback('https://example.com?code=code....')
|
|
145
|
+
* // Will try to log in the user with the url assign by the developer
|
|
146
|
+
*/
|
|
147
|
+
handleCallback(url?: string): Promise<AuthState>;
|
|
148
|
+
/**
|
|
149
|
+
* Function to generate and store the access token
|
|
150
|
+
* @param {string} identityProvider - Type of identity provider used
|
|
151
|
+
* @return {Promise<void>} Empty promise
|
|
152
|
+
*/
|
|
153
|
+
private generateToken;
|
|
154
|
+
private reloadCodeVerifier;
|
|
155
|
+
/**
|
|
156
|
+
* Return the user stored in cache
|
|
157
|
+
* @return {Promise<TIDUser | undefined>} User in cache
|
|
158
|
+
*/
|
|
159
|
+
getUser(): Promise<TIDUser | undefined>;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the access token from cache. If the token already expired,
|
|
162
|
+
* will try to refresh it using the refresh token
|
|
163
|
+
* @return {Promise<string>} Access token
|
|
164
|
+
* @throws {TokenNotFoundException} Will throw an exception if the access token is not in cache
|
|
165
|
+
* @throws {TokenExpiredException} Will throw an exception if the user token expired
|
|
166
|
+
*/
|
|
167
|
+
getAccessTokenSilently(): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Redirect the user to TID using the browser
|
|
170
|
+
* @param {LogoutOptions} options - Custom configuration for teh redirection
|
|
171
|
+
* @return {Promise<void>} Empty promise
|
|
172
|
+
* @example No configuration
|
|
173
|
+
* logout()
|
|
174
|
+
* // Automatically redirects the user to TID to log out
|
|
175
|
+
* @example Custom redirect
|
|
176
|
+
* logout({onRedirect: (url) => router.navigate(url)})
|
|
177
|
+
* // Redirect calls onRedirect with the log-out url for TID
|
|
178
|
+
* // So it can be handled by the developer
|
|
179
|
+
*/
|
|
180
|
+
logout(options?: LogoutOptions): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Check if the user still has a valid session
|
|
183
|
+
* @return {Promise<boolean>} True or false depending on if the user is session is valid or not
|
|
184
|
+
*/
|
|
185
|
+
checkSession(): Promise<boolean>;
|
|
186
|
+
/**
|
|
187
|
+
* Check if the user has a session valid after a refresh
|
|
188
|
+
* @return {Promise<void>} Empty promise
|
|
189
|
+
*/
|
|
190
|
+
loadUserSession(): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Load the user session from cache into the SDK
|
|
193
|
+
* @return {Promise<void>} Empty promise
|
|
194
|
+
*/
|
|
195
|
+
private loadCacheSessionIntoSDK;
|
|
196
|
+
/**
|
|
197
|
+
* Get a http bearer token client to use it for another SDK (Ex: Processing framework)
|
|
198
|
+
* @return {any} - BearerTokenHttpClientProvider
|
|
199
|
+
*/
|
|
200
|
+
getBearerTokenHttpClient(apiURL: string): typeof BearerTokenHttpClientProvider;
|
|
201
|
+
/**
|
|
202
|
+
* Get the redirect url to TID
|
|
203
|
+
* @return {string} - Callback redirect url
|
|
204
|
+
*/
|
|
205
|
+
getRedirectUrl(): string;
|
|
206
|
+
}
|
|
207
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default time skew time to check if the token has expired
|
|
3
|
+
* @type {number}
|
|
4
|
+
*/
|
|
5
|
+
export declare const CLOCK_SKEW_TIME: number;
|
|
6
|
+
/**
|
|
7
|
+
* List of parameters required in the redirect callback that you get from TID
|
|
8
|
+
* @type {Array<string>}
|
|
9
|
+
*/
|
|
10
|
+
export declare const LIST_PARAMS_REQUIRED: Array<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Class representing a token expiration exception */
|
|
2
|
+
export declare class TokenExpiredException extends Error {
|
|
3
|
+
}
|
|
4
|
+
/** Class representing a token expiration exception */
|
|
5
|
+
export declare class TokenNotFoundException extends Error {
|
|
6
|
+
}
|
|
7
|
+
export declare class CodeVerifierNotFoundException extends Error {
|
|
8
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
export interface CacheStorage {
|
|
2
|
+
getToken: () => Promise<TIDAuthToken | undefined>;
|
|
3
|
+
storeToken: (authToken: TIDAuthToken) => Promise<void>;
|
|
4
|
+
getUser: () => Promise<TIDUser | undefined>;
|
|
5
|
+
storeUser: (user: TIDUser) => Promise<void>;
|
|
6
|
+
clear: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface TIDAuthToken {
|
|
9
|
+
/** The id_token returned from the OIDC provider */
|
|
10
|
+
id_token: string;
|
|
11
|
+
/** The session state value returned from the OIDC provider (opaque) */
|
|
12
|
+
session_state?: string;
|
|
13
|
+
/** The identity provider value returned the provider used for the authentication (okta, email, google, etc..) */
|
|
14
|
+
identity_provider?: string;
|
|
15
|
+
/** The access token returned from the OIDC provider. */
|
|
16
|
+
access_token: string;
|
|
17
|
+
/** Refresh token returned from the OIDC provider (if requested) */
|
|
18
|
+
refresh_token?: string;
|
|
19
|
+
/** The token_type returned from the OIDC provider */
|
|
20
|
+
token_type: string;
|
|
21
|
+
/** The scope returned from the OIDC provider */
|
|
22
|
+
scope: string;
|
|
23
|
+
/** The expires at returned from the OIDC provider */
|
|
24
|
+
expires_at: number;
|
|
25
|
+
/** The custom state transferred in the last signin */
|
|
26
|
+
state: any;
|
|
27
|
+
}
|
|
28
|
+
export interface TIDUser {
|
|
29
|
+
/** End-User's full name */
|
|
30
|
+
name?: string;
|
|
31
|
+
/** Given name(s) or first name(s) of the End-User */
|
|
32
|
+
given_name?: string;
|
|
33
|
+
/** Surname(s) or last name(s) of the End-User */
|
|
34
|
+
family_name?: string;
|
|
35
|
+
/** Middle name(s) of the End-User */
|
|
36
|
+
middle_name?: string;
|
|
37
|
+
/** Casual name of the End-User that may or may not be the same as the given_name. */
|
|
38
|
+
nickname?: string;
|
|
39
|
+
/** Shorthand name that the End-User wishes to be referred to at the RP, such as janedoe or j.doe. */
|
|
40
|
+
preferred_username?: string;
|
|
41
|
+
/** URL of the End-User's profile page */
|
|
42
|
+
profile?: string;
|
|
43
|
+
/** URL of the End-User's profile picture */
|
|
44
|
+
picture?: string;
|
|
45
|
+
/** URL of the End-User's Web page or blog */
|
|
46
|
+
website?: string;
|
|
47
|
+
/** End-User's preferred e-mail address */
|
|
48
|
+
email?: string;
|
|
49
|
+
/** True if the End-User's e-mail address has been verified; otherwise false. */
|
|
50
|
+
email_verified?: boolean;
|
|
51
|
+
/** End-User's gender. Values defined by this specification are female and male. */
|
|
52
|
+
gender?: string;
|
|
53
|
+
/** End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format */
|
|
54
|
+
birthdate?: string;
|
|
55
|
+
/** String from zoneinfo [zoneinfo] time zone database representing the End-User's time zone. */
|
|
56
|
+
zoneinfo?: string;
|
|
57
|
+
/** End-User's locale, represented as a BCP47 [RFC5646] language tag. */
|
|
58
|
+
locale?: string;
|
|
59
|
+
/** End-User's preferred telephone number. */
|
|
60
|
+
phone_number?: string;
|
|
61
|
+
/** True if the End-User's phone number has been verified; otherwise false. */
|
|
62
|
+
phone_number_verified?: boolean;
|
|
63
|
+
/** object End-User's preferred address in JSON [RFC4627] */
|
|
64
|
+
address?: OidcAddress;
|
|
65
|
+
/** Time the End-User's information was last updated. */
|
|
66
|
+
updated_at?: number;
|
|
67
|
+
}
|
|
68
|
+
interface OidcAddress {
|
|
69
|
+
/** Full mailing address, formatted for display or use on a mailing label */
|
|
70
|
+
formatted?: string;
|
|
71
|
+
/** Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information */
|
|
72
|
+
street_address?: string;
|
|
73
|
+
/** City or locality component */
|
|
74
|
+
locality?: string;
|
|
75
|
+
/** State, province, prefecture, or region component */
|
|
76
|
+
region?: string;
|
|
77
|
+
/** Zip code or postal code component */
|
|
78
|
+
postal_code?: string;
|
|
79
|
+
/** Country name component */
|
|
80
|
+
country?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface TIDJWTUser {
|
|
83
|
+
/**
|
|
84
|
+
* The issuer of a token
|
|
85
|
+
* Prod: https://id.trimble.com
|
|
86
|
+
* Stage: https://state.id.trimblecloud.com
|
|
87
|
+
* @type {string}
|
|
88
|
+
*/
|
|
89
|
+
iss: string;
|
|
90
|
+
/**
|
|
91
|
+
* Time on or after which the JWT MUST NOT be accepted for processing
|
|
92
|
+
* integer, (Seconds since midnight Jan 1, 1970)
|
|
93
|
+
* @type {number}
|
|
94
|
+
*/
|
|
95
|
+
exp: number;
|
|
96
|
+
/**
|
|
97
|
+
* Not Before Time. Used to determine the age of a JWT
|
|
98
|
+
* integer, (Seconds since midnight Jan 1, 1970)
|
|
99
|
+
* @type {number}
|
|
100
|
+
*/
|
|
101
|
+
nbf: number;
|
|
102
|
+
/**
|
|
103
|
+
* Issued At Time. The time the token was issued
|
|
104
|
+
* integer, (Seconds sing midnight Jan 1, 1970)
|
|
105
|
+
* @type {number}
|
|
106
|
+
*/
|
|
107
|
+
iat: number;
|
|
108
|
+
/**
|
|
109
|
+
* A unique identifier for the token
|
|
110
|
+
* @type {string}
|
|
111
|
+
*/
|
|
112
|
+
jti: string;
|
|
113
|
+
/**
|
|
114
|
+
* The version of this Trimble Identity Token
|
|
115
|
+
* @type {number}
|
|
116
|
+
*/
|
|
117
|
+
jwt_ver: number;
|
|
118
|
+
/**
|
|
119
|
+
* The subject of the JWT
|
|
120
|
+
* user or application UUID
|
|
121
|
+
* @type {string}
|
|
122
|
+
*/
|
|
123
|
+
sub: string;
|
|
124
|
+
/**
|
|
125
|
+
* Audience an array of relying parties (client ID tokens) user or application UUID
|
|
126
|
+
* For access tokens: an array of unique IDs for applications/APIs intended to consume this token
|
|
127
|
+
* For ID token tokens: this is a single string ID in the application that made the authentication request
|
|
128
|
+
* @type {string}
|
|
129
|
+
*/
|
|
130
|
+
aud: string;
|
|
131
|
+
/**
|
|
132
|
+
* Logged user type (user or application)
|
|
133
|
+
* @type {string}
|
|
134
|
+
*/
|
|
135
|
+
identity_type: string;
|
|
136
|
+
/**
|
|
137
|
+
* The time when the authentication occurred
|
|
138
|
+
* integer, (Seconds since midnight Jan 1, 1970)
|
|
139
|
+
* @type {number}
|
|
140
|
+
*/
|
|
141
|
+
auth_time: number;
|
|
142
|
+
/**
|
|
143
|
+
* Authentication Methods References
|
|
144
|
+
* An array of strings giving information about how the user is authenticated
|
|
145
|
+
*
|
|
146
|
+
* Examples: password
|
|
147
|
+
* mfa
|
|
148
|
+
* sms_mfa
|
|
149
|
+
* software_token_mfa
|
|
150
|
+
* federated
|
|
151
|
+
* trimble_okta
|
|
152
|
+
* client_credentials
|
|
153
|
+
* @type {Array<string>}
|
|
154
|
+
*/
|
|
155
|
+
amr: Array<string>;
|
|
156
|
+
/**
|
|
157
|
+
* Authorizing Party. Relying party’s client ID token
|
|
158
|
+
* @type {string}
|
|
159
|
+
*/
|
|
160
|
+
azp: string;
|
|
161
|
+
/**
|
|
162
|
+
* Hash of the accompanying access token
|
|
163
|
+
* @type {string}
|
|
164
|
+
*/
|
|
165
|
+
at_hash: string;
|
|
166
|
+
/**
|
|
167
|
+
* The federated system the user is signed in to
|
|
168
|
+
* e.g., trimble_okta
|
|
169
|
+
* @type {string}
|
|
170
|
+
*/
|
|
171
|
+
federation_origin: string;
|
|
172
|
+
/**
|
|
173
|
+
* Firstname or full name of this user
|
|
174
|
+
* @type {string}
|
|
175
|
+
*/
|
|
176
|
+
given_name: string;
|
|
177
|
+
/**
|
|
178
|
+
* Family name or surname of the user
|
|
179
|
+
* @type {string}
|
|
180
|
+
*/
|
|
181
|
+
family_name: string;
|
|
182
|
+
/**
|
|
183
|
+
* Email address of the user
|
|
184
|
+
* @type {string}
|
|
185
|
+
*/
|
|
186
|
+
email: string;
|
|
187
|
+
/**
|
|
188
|
+
* Whether the user’s email is verified or not
|
|
189
|
+
* @type {string}
|
|
190
|
+
*/
|
|
191
|
+
email_verified: true;
|
|
192
|
+
/**
|
|
193
|
+
* URL of user’s profile picture
|
|
194
|
+
* @type {string}
|
|
195
|
+
*/
|
|
196
|
+
picture: string;
|
|
197
|
+
/**
|
|
198
|
+
* Geographic region that user data is stored in (us/eu)
|
|
199
|
+
* @type {string}
|
|
200
|
+
*/
|
|
201
|
+
data_region: string;
|
|
202
|
+
}
|
|
203
|
+
export interface AuthState {
|
|
204
|
+
authState: any;
|
|
205
|
+
}
|
|
206
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
interface CacheKeyOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Client id of the application created in trimble developer console
|
|
4
|
+
* @type {string}
|
|
5
|
+
*/
|
|
6
|
+
client_id: string;
|
|
7
|
+
}
|
|
8
|
+
/** Class representing the caching keys for storing and retrieving user and token from auth */
|
|
9
|
+
export declare class CacheKey {
|
|
10
|
+
/**
|
|
11
|
+
* Client id of the application created in trimble developer console
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
private readonly clientId;
|
|
15
|
+
/**
|
|
16
|
+
* Prefix value of the key, by default the prefix is based on the constant PREFIX_KEY
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
private readonly prefix;
|
|
20
|
+
/**
|
|
21
|
+
* Suffix value use it to generate the key to store and retrieve the token, by default the prefix is based on the constant AUTH_KEY
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
private readonly authSuffix;
|
|
25
|
+
/**
|
|
26
|
+
* Suffix value use it to generate the key to store and retrieve the user, by default the prefix is based on the constant USER_KEY
|
|
27
|
+
* @type {string}
|
|
28
|
+
*/
|
|
29
|
+
private readonly userSuffix;
|
|
30
|
+
/**
|
|
31
|
+
* Initialized the cache key
|
|
32
|
+
* @param {CacheKeyOptions} cacheKeyOptions - Cache key options to edit the default values
|
|
33
|
+
*/
|
|
34
|
+
constructor(cacheKeyOptions: CacheKeyOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Get key to store/retrieve user
|
|
37
|
+
* @return {string} Key for the user
|
|
38
|
+
*/
|
|
39
|
+
getUserKey(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get key to store/retrieve token
|
|
42
|
+
* @return {string} Key for the token
|
|
43
|
+
*/
|
|
44
|
+
getAuthKey(): string;
|
|
45
|
+
}
|
|
46
|
+
export {};
|