@trimble-oss/trimble-id-react 0.0.1-rc.1 → 0.0.1-rc.3

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 CHANGED
@@ -18,9 +18,9 @@ npm install @trimble-oss/trimble-id-react
18
18
 
19
19
  Create a new application in the [Trimble Developer Console](https://developer.console.trimble.com) portal and configure the following settings:
20
20
 
21
- To register your service application in Trimble Developer Console:
21
+ To register your application in Trimble Developer Console:
22
22
 
23
- 1. On the left pane select Identity Management > Applications.
23
+ 1. On the left pane select "Applications".
24
24
 
25
25
  2. On the Applications home page, in the top right corner select + NEW APPLICATION. The Create Application page displays.
26
26
 
@@ -34,10 +34,16 @@ To register your service application in Trimble Developer Console:
34
34
 
35
35
  4. Configure OAuth application grant types as `Authorization Code Grant` and `Use Refresh tokens` in order to use this SDK.
36
36
 
37
- 5. Select "Create Application" to save changes.
37
+ 5. Configure the desired `callback URL` and `logout URL` for your application. These URLs are used by the SDK to redirect the user after authentication.
38
+
39
+ 6. Select "Create Application" to save changes.
38
40
 
39
41
  Take note of the Client ID and URLs under the "Basic Information" section. You'll need these values to configure the SDK.
40
42
 
43
+ **Scopes**
44
+
45
+ Trimble Identity uses scopes to determine the aud claim in the returned access token. Scope is mandatory for the application to work. You can use the scope as the application name registered in the Trimble Developer Console. For example, if you have registered an application with the name "test", then it must be registered in the format {some_uuid}-"test". For eg., 12345678-1234-1234-1234-123456789012-test.
46
+
41
47
  For more information, see [Authentication documentation](https://developer.trimble.com/docs/authentication).
42
48
 
43
49
  ## <a name="usage-reference">Usage Reference</a>
@@ -71,7 +77,7 @@ After wrapping your app with the TIDProvider, you have to configure the TID cred
71
77
  scopes: ['test']
72
78
  },
73
79
  persistentOptions: {
74
- persistentStore: ('localStorage' as PersistentStore),
80
+ persistentStore: "localStorage"
75
81
  }
76
82
  })} onRedirectCallback={handleRedirect}>
77
83
  <Component/>
@@ -86,6 +92,7 @@ After wrapping your app with the TIDProvider, you have to configure the TID cred
86
92
  redirectUrl={"http://localhost:3000/callback"}
87
93
  logoutRedirectUrl={"http://localhost:3000/logout-callback"}
88
94
  scopes={['test']}
95
+ persistentStore ={"localStorage"}
89
96
  onRedirectCallback={handleRedirect}>
90
97
  <Component/>
91
98
  </TIDProvider>
@@ -103,10 +110,13 @@ Production: https://id.trimble.com/.well-known/openid-configuration <br />
103
110
 
104
111
  ### 2. PersistentOptions configuration
105
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.
106
114
  * **localStorage** - This persistent doesn't have expiration date
107
115
  * **sessionStorage** - This one is cleared when the page session ends
108
116
 
109
- Use the `useAuth` hook in your components to access authentication state (`isLoading`, `isAuthenticated` and `user`) and authentication methods (`loginWithRedirect` and `logout`):
117
+
118
+ ### useAuth
119
+ Use the `useAuth` hook in your components to access authentication state (`isLoading`, `isAuthenticated`, `user`, `error`) and authentication methods (`loginWithRedirect` and `logout`):
110
120
 
111
121
  ### loginWithRedirect
112
122
 
@@ -147,7 +157,7 @@ Gets the access token from cache. SDK handles token refresh when token expires.
147
157
 
148
158
  ```tsx
149
159
  const {getAccessTokenSilently}= useAuth()
150
- var access_token = await useAuth().getAccessTokenSilently()
160
+ var access_token = await getAccessTokenSilently()
151
161
  ```
152
162
 
153
163
  ### user
@@ -159,6 +169,15 @@ const {user}= useAuth()
159
169
  var name = user?.name
160
170
  ```
161
171
 
172
+ ### error
173
+
174
+ Property that let the developer know if an error happen during the authentication
175
+
176
+ ```tsx
177
+ const {error}= useAuth()
178
+ var error = error.message
179
+ ```
180
+
162
181
 
163
182
  ### AuthenticationGuard
164
183
  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.
@@ -179,8 +198,9 @@ See here for [releases](https://github.com/trimble-oss/trimble-id-sdk-docs-for-r
179
198
 
180
199
  ## Raise an issue
181
200
 
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).
201
+ To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/trimble-oss/trimble-id-sdk-docs-for-react/issues).
183
202
 
184
203
  ## <a name="support">Support</a>
185
204
 
186
- Send email to [cloudplatform_support@trimble.com](mailto:cloudplatform_support@trimble.com)
205
+ Send email to [support@trimble.com](mailto:support@trimble.com)
206
+
@@ -444,7 +444,7 @@ class zt extends Error {
444
444
  }
445
445
  class Ht extends Error {
446
446
  }
447
- const D = "@trimble-oss/trimble-id-react", M = "0.0.1-rc.1", qt = {
447
+ const D = "@trimble-oss/trimble-id-react", M = "0.0.1-rc.2", qt = {
448
448
  configurationEndpoint: "",
449
449
  clientId: "",
450
450
  redirectUrl: "",
@@ -1,4 +1,4 @@
1
- (function(m,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("@trimble-oss/trimble-id"),require("es-cookie"),require("jwt-decode"),require("react")):typeof define=="function"&&define.amd?define(["exports","@trimble-oss/trimble-id","es-cookie","jwt-decode","react"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m.ReactTID={},m.trimbleId,m.esCookie,m.jwt_decode,m.require$$0))})(this,function(m,S,j,He,T){"use strict";var Zt=Object.defineProperty;var qt=(m,S,j)=>S in m?Zt(m,S,{enumerable:!0,configurable:!0,writable:!0,value:j}):m[S]=j;var p=(m,S,j)=>(qt(m,typeof S!="symbol"?S+"":S,j),j);function $e(a){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const n in a)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(a,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>a[n]})}}return t.default=a,Object.freeze(t)}const re=$e(j);class Xe{constructor(){p(this,"generateCache",function(){const t={token:void 0,user:void 0};return{async getToken(){return t.token},async getUser(){return t.user},async storeToken(n){t.token=n},async storeUser(n){t.user=n},clear(){return t.token=void 0,t.user=void 0,Promise.resolve(void 0)}}}())}}class Qe{constructor(t){p(this,"localStorage");p(this,"cacheKey");this.localStorage=window.localStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.localStorage.removeItem(this.getAuthKey()),this.localStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}const ne="@TID",Ze=`${ne}_AUTH_KEY`,qe=`${ne}_USER_KEY`;class et{constructor(t){p(this,"clientId");p(this,"prefix",ne);p(this,"authSuffix",Ze);p(this,"userSuffix",qe);this.clientId=t.client_id}getUserKey(){return`${this.prefix}_${this.userSuffix}_${this.clientId}`}getAuthKey(){return`${this.prefix}_${this.authSuffix}_${this.clientId}`}}class tt{constructor(t){p(this,"sessionStorage");p(this,"cacheKey");this.sessionStorage=window.sessionStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.sessionStorage.removeItem(this.getAuthKey()),this.sessionStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}class rt{constructor(t){p(this,"persistentStore");p(this,"cacheStorage");p(this,"cacheKey");this.persistentStore=t.persistentStore,this.cacheKey=new et({client_id:t.clientId}),this.persistentStore==="localStorage"?this.cacheStorage=new Qe({cacheKey:this.cacheKey}):this.persistentStore==="sessionStorage"?this.cacheStorage=new tt({cacheKey:this.cacheKey}):this.cacheStorage=new Xe().generateCache}async setToken(t){await this.cacheStorage.storeToken(t)}async setUser(t){await this.cacheStorage.storeUser(t)}async getUser(){return this.cacheStorage.getUser()}async getToken(){return this.cacheStorage.getToken()}async clear(){await this.cacheStorage.clear()}}const nt=5*6e4,it=["code","state"],pe=a=>a.split("?")[0],at=a=>a.split("?")[1],me=a=>{let t=a;if(!a.startsWith("?"))try{t=new URL(a).search}catch{}return new URLSearchParams(t)},ot=(a=window.location.href,t)=>{if(t!=null){const o=pe(t),c=pe(a??"");if(o!==c)return!1}const n=me(a);for(const o of it)if(!n.has(o))return!1;return!0},st=a=>({name:`${a.given_name} ${a.family_name}`,given_name:a.given_name,family_name:a.family_name,picture:a.picture,email:a.email,email_verified:a.email_verified,phone_number_verified:!1}),ct="@TID_COOKIE";class lt{get(t){const n=re.get(t);if(n==null)throw new Error("Cookie not found");return JSON.parse(n)}set(t,n,o){let c={};window.location.protocol==="https:"&&(c={secure:!0,sameSite:"none"}),o!=null&&o.expires&&(c.expires=o.expires),o!=null&&o.domain&&(c.domain=o.domain),re.set(t,JSON.stringify(n),c)}remove(t,n){const o={};n!=null&&n.domain&&(o.domain=n.domain),re.remove(t,o)}}class ut{constructor(t){p(this,"cookieKey");p(this,"cookiesStorage");this.cookieKey=`${ct}.${t.clientId}`,this.cookiesStorage=new lt}save(t){this.cookiesStorage.set(this.cookieKey,t,{expires:1})}get(){try{return this.cookiesStorage.get(this.cookieKey)}catch{return}}clear(){this.cookiesStorage.remove(this.cookieKey)}}class ft extends Error{}class dt extends Error{}class ht extends Error{}const M="@trimble-oss/trimble-id-react",F="0.0.1-rc.1",gt={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]},vt={persistentStore:"in-memory"};class Ee{constructor(t){p(this,"tokenProvider");p(this,"cacheManager");p(this,"cookiesManager");p(this,"clientId");p(this,"redirectUrl");p(this,"analyticshttpclient");const{config:n=gt,persistentOptions:o=vt}=t;if(this.redirectUrl=n.redirectUrl,n.configurationEndpoint==null||n.configurationEndpoint=="")throw new Error("Configuration endpoint not defined");if(n.clientId==null||n.clientId=="")throw new Error("Consumer key is not defined");this.cookiesManager=new ut({clientId:n.clientId});const c=this.cookiesManager.get(),w=new S.OpenIdEndpointProvider(n.configurationEndpoint);let k=new S.AuthorizationCodeGrantTokenProvider(w,n.clientId,n.redirectUrl).WithScopes(n.scopes);n.logoutRedirectUrl&&(k=k.WithLogoutRedirect(n.logoutRedirectUrl)),(c==null?void 0:c.code_verifier)!=null&&(k=k.WithProofKeyForCodeExchange(c.code_verifier)),this.tokenProvider=k,this.cacheManager=new rt({clientId:n.clientId,persistentStore:o.persistentStore}),this.clientId=n.clientId,this.analyticshttpclient=new S.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",M,F,this.clientId)}async loginWithRedirect(t){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,M,F,this.clientId);const{onRedirect:n}=t||{},o=S.AuthorizationCodeGrantTokenProvider.GenerateCodeVerifier();this.cookiesManager.save({code_verifier:o}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(o);const c=await this.tokenProvider.GetOAuthRedirect("state");n!=null?n(c):window.location.assign(c)}async handleCallback(t=window.location.href){const n=this.cookiesManager.get();if(n==null||(n==null?void 0:n.code_verifier)==null)throw new ht("Code verifier not available");const o=at(t),c=me(t),w=c.get("identity_provider")??"",k=c.get("state")??"";return await this.tokenProvider.ValidateQuery(o),await this.generateToken(w),{authState:k}}async generateToken(t){var C,d;const n=await this.tokenProvider.RetrieveToken(),o=await this.tokenProvider.RetrieveRefreshToken(),c=await this.tokenProvider.RetrieveIdToken(),w=await this.tokenProvider.RetrieveTokenExpiry(),P=new Date(w).getTime(),g=(d=(C=this.tokenProvider)==null?void 0:C._scopes)==null?void 0:d.join(" ");await this.cacheManager.setToken({scope:g,state:"",session_state:"",identity_provider:t,token_type:"bearer",access_token:n,refresh_token:o,id_token:c,expires_at:P});const I=He(c),R=st(I);await this.cacheManager.setUser(R),await this.reloadCodeVerifier()}async reloadCodeVerifier(){const t=await this.tokenProvider.RetrieveCodeVerifier();this.cookiesManager.save({code_verifier:t}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(t)}async getUser(){return this.analyticshttpclient.sendMethodEvent(this.getUser.name,M,F,this.clientId),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,M,F,this.clientId);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,M,F,"No token available",this.clientId),new dt("No token available");const n=new Date(new Date().getTime()+nt);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<n.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,M,F,o.message,this.clientId),new ft(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return(t==null?void 0:t.access_token)||""}async logout(t){this.analyticshttpclient.sendMethodEvent(this.logout.name,M,F,this.clientId);const{onRedirect:n,disabledAutoRedirect:o}=t||{};this.cacheManager&&await this.cacheManager.clear(),this.cookiesManager&&this.cookiesManager.clear();const c=await this.tokenProvider.GetOAuthLogoutRedirect("state");if(n!=null)return n(c);o||window.location.assign(c)}async checkSession(){try{await this.getAccessTokenSilently()}catch{return!1}return!0}async loadUserSession(){await this.loadCacheSessionIntoSDK(),await this.checkSession()||await this.cacheManager.clear()}async loadCacheSessionIntoSDK(){const t=await this.cacheManager.getToken();if(t==null)return;const n=t.access_token,o=t.refresh_token||"",c=t.id_token,w=t.expires_at;this.tokenProvider=this.tokenProvider.WithAccessToken(n,w).WithRefreshToken(o).WithIdToken(c)}getBearerTokenHttpClient(t){return new S.BearerTokenHttpClientProvider(this.tokenProvider,t)}getRedirectUrl(){return this.redirectUrl}}const z=T.createContext(null),_e=()=>T.useContext(z)??{};var ie={exports:{}},Y={};/**
1
+ (function(m,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("@trimble-oss/trimble-id"),require("es-cookie"),require("jwt-decode"),require("react")):typeof define=="function"&&define.amd?define(["exports","@trimble-oss/trimble-id","es-cookie","jwt-decode","react"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m.ReactTID={},m.trimbleId,m.esCookie,m.jwt_decode,m.require$$0))})(this,function(m,S,j,He,T){"use strict";var Zt=Object.defineProperty;var qt=(m,S,j)=>S in m?Zt(m,S,{enumerable:!0,configurable:!0,writable:!0,value:j}):m[S]=j;var p=(m,S,j)=>(qt(m,typeof S!="symbol"?S+"":S,j),j);function $e(a){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const n in a)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(a,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>a[n]})}}return t.default=a,Object.freeze(t)}const re=$e(j);class Xe{constructor(){p(this,"generateCache",function(){const t={token:void 0,user:void 0};return{async getToken(){return t.token},async getUser(){return t.user},async storeToken(n){t.token=n},async storeUser(n){t.user=n},clear(){return t.token=void 0,t.user=void 0,Promise.resolve(void 0)}}}())}}class Qe{constructor(t){p(this,"localStorage");p(this,"cacheKey");this.localStorage=window.localStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=localStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);localStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.localStorage.removeItem(this.getAuthKey()),this.localStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}const ne="@TID",Ze=`${ne}_AUTH_KEY`,qe=`${ne}_USER_KEY`;class et{constructor(t){p(this,"clientId");p(this,"prefix",ne);p(this,"authSuffix",Ze);p(this,"userSuffix",qe);this.clientId=t.client_id}getUserKey(){return`${this.prefix}_${this.userSuffix}_${this.clientId}`}getAuthKey(){return`${this.prefix}_${this.authSuffix}_${this.clientId}`}}class tt{constructor(t){p(this,"sessionStorage");p(this,"cacheKey");this.sessionStorage=window.sessionStorage,this.cacheKey=t.cacheKey}async getToken(){const t=this.getAuthKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async getUser(){const t=this.getUserKey(),n=sessionStorage.getItem(t);return n?JSON.parse(n):void 0}async storeToken(t){const n=this.getAuthKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}async storeUser(t){const n=this.getUserKey(),o=JSON.stringify(t);sessionStorage.setItem(n,o)}getUserKey(){return this.cacheKey.getUserKey()}getAuthKey(){return this.cacheKey.getAuthKey()}clear(){return this.sessionStorage.removeItem(this.getAuthKey()),this.sessionStorage.removeItem(this.getUserKey()),Promise.resolve(void 0)}}class rt{constructor(t){p(this,"persistentStore");p(this,"cacheStorage");p(this,"cacheKey");this.persistentStore=t.persistentStore,this.cacheKey=new et({client_id:t.clientId}),this.persistentStore==="localStorage"?this.cacheStorage=new Qe({cacheKey:this.cacheKey}):this.persistentStore==="sessionStorage"?this.cacheStorage=new tt({cacheKey:this.cacheKey}):this.cacheStorage=new Xe().generateCache}async setToken(t){await this.cacheStorage.storeToken(t)}async setUser(t){await this.cacheStorage.storeUser(t)}async getUser(){return this.cacheStorage.getUser()}async getToken(){return this.cacheStorage.getToken()}async clear(){await this.cacheStorage.clear()}}const nt=5*6e4,it=["code","state"],pe=a=>a.split("?")[0],at=a=>a.split("?")[1],me=a=>{let t=a;if(!a.startsWith("?"))try{t=new URL(a).search}catch{}return new URLSearchParams(t)},ot=(a=window.location.href,t)=>{if(t!=null){const o=pe(t),c=pe(a??"");if(o!==c)return!1}const n=me(a);for(const o of it)if(!n.has(o))return!1;return!0},st=a=>({name:`${a.given_name} ${a.family_name}`,given_name:a.given_name,family_name:a.family_name,picture:a.picture,email:a.email,email_verified:a.email_verified,phone_number_verified:!1}),ct="@TID_COOKIE";class lt{get(t){const n=re.get(t);if(n==null)throw new Error("Cookie not found");return JSON.parse(n)}set(t,n,o){let c={};window.location.protocol==="https:"&&(c={secure:!0,sameSite:"none"}),o!=null&&o.expires&&(c.expires=o.expires),o!=null&&o.domain&&(c.domain=o.domain),re.set(t,JSON.stringify(n),c)}remove(t,n){const o={};n!=null&&n.domain&&(o.domain=n.domain),re.remove(t,o)}}class ut{constructor(t){p(this,"cookieKey");p(this,"cookiesStorage");this.cookieKey=`${ct}.${t.clientId}`,this.cookiesStorage=new lt}save(t){this.cookiesStorage.set(this.cookieKey,t,{expires:1})}get(){try{return this.cookiesStorage.get(this.cookieKey)}catch{return}}clear(){this.cookiesStorage.remove(this.cookieKey)}}class ft extends Error{}class dt extends Error{}class ht extends Error{}const M="@trimble-oss/trimble-id-react",F="0.0.1-rc.2",gt={configurationEndpoint:"",clientId:"",redirectUrl:"",logoutRedirectUrl:"",scopes:[]},vt={persistentStore:"in-memory"};class Ee{constructor(t){p(this,"tokenProvider");p(this,"cacheManager");p(this,"cookiesManager");p(this,"clientId");p(this,"redirectUrl");p(this,"analyticshttpclient");const{config:n=gt,persistentOptions:o=vt}=t;if(this.redirectUrl=n.redirectUrl,n.configurationEndpoint==null||n.configurationEndpoint=="")throw new Error("Configuration endpoint not defined");if(n.clientId==null||n.clientId=="")throw new Error("Consumer key is not defined");this.cookiesManager=new ut({clientId:n.clientId});const c=this.cookiesManager.get(),w=new S.OpenIdEndpointProvider(n.configurationEndpoint);let k=new S.AuthorizationCodeGrantTokenProvider(w,n.clientId,n.redirectUrl).WithScopes(n.scopes);n.logoutRedirectUrl&&(k=k.WithLogoutRedirect(n.logoutRedirectUrl)),(c==null?void 0:c.code_verifier)!=null&&(k=k.WithProofKeyForCodeExchange(c.code_verifier)),this.tokenProvider=k,this.cacheManager=new rt({clientId:n.clientId,persistentStore:o.persistentStore}),this.clientId=n.clientId,this.analyticshttpclient=new S.AnalyticsHttpClient,this.analyticshttpclient.sendInitEvent("TIDClient",M,F,this.clientId)}async loginWithRedirect(t){this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name,M,F,this.clientId);const{onRedirect:n}=t||{},o=S.AuthorizationCodeGrantTokenProvider.GenerateCodeVerifier();this.cookiesManager.save({code_verifier:o}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(o);const c=await this.tokenProvider.GetOAuthRedirect("state");n!=null?n(c):window.location.assign(c)}async handleCallback(t=window.location.href){const n=this.cookiesManager.get();if(n==null||(n==null?void 0:n.code_verifier)==null)throw new ht("Code verifier not available");const o=at(t),c=me(t),w=c.get("identity_provider")??"",k=c.get("state")??"";return await this.tokenProvider.ValidateQuery(o),await this.generateToken(w),{authState:k}}async generateToken(t){var C,d;const n=await this.tokenProvider.RetrieveToken(),o=await this.tokenProvider.RetrieveRefreshToken(),c=await this.tokenProvider.RetrieveIdToken(),w=await this.tokenProvider.RetrieveTokenExpiry(),P=new Date(w).getTime(),g=(d=(C=this.tokenProvider)==null?void 0:C._scopes)==null?void 0:d.join(" ");await this.cacheManager.setToken({scope:g,state:"",session_state:"",identity_provider:t,token_type:"bearer",access_token:n,refresh_token:o,id_token:c,expires_at:P});const I=He(c),R=st(I);await this.cacheManager.setUser(R),await this.reloadCodeVerifier()}async reloadCodeVerifier(){const t=await this.tokenProvider.RetrieveCodeVerifier();this.cookiesManager.save({code_verifier:t}),this.tokenProvider=this.tokenProvider.WithProofKeyForCodeExchange(t)}async getUser(){return this.analyticshttpclient.sendMethodEvent(this.getUser.name,M,F,this.clientId),await this.cacheManager.getUser()}async getAccessTokenSilently(){this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name,M,F,this.clientId);let t=await this.cacheManager.getToken();if(t==null)throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,M,F,"No token available",this.clientId),new dt("No token available");const n=new Date(new Date().getTime()+nt);if((t==null?void 0:t.expires_at)==null||(t==null?void 0:t.expires_at)<n.getTime()){try{await this.tokenProvider.RetrieveToken()}catch(o){throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,M,F,o.message,this.clientId),new ft(o.message)}await this.generateToken((t==null?void 0:t.identity_provider)??""),t=await this.cacheManager.getToken()}return(t==null?void 0:t.access_token)||""}async logout(t){this.analyticshttpclient.sendMethodEvent(this.logout.name,M,F,this.clientId);const{onRedirect:n,disabledAutoRedirect:o}=t||{};this.cacheManager&&await this.cacheManager.clear(),this.cookiesManager&&this.cookiesManager.clear();const c=await this.tokenProvider.GetOAuthLogoutRedirect("state");if(n!=null)return n(c);o||window.location.assign(c)}async checkSession(){try{await this.getAccessTokenSilently()}catch{return!1}return!0}async loadUserSession(){await this.loadCacheSessionIntoSDK(),await this.checkSession()||await this.cacheManager.clear()}async loadCacheSessionIntoSDK(){const t=await this.cacheManager.getToken();if(t==null)return;const n=t.access_token,o=t.refresh_token||"",c=t.id_token,w=t.expires_at;this.tokenProvider=this.tokenProvider.WithAccessToken(n,w).WithRefreshToken(o).WithIdToken(c)}getBearerTokenHttpClient(t){return new S.BearerTokenHttpClientProvider(this.tokenProvider,t)}getRedirectUrl(){return this.redirectUrl}}const z=T.createContext(null),_e=()=>T.useContext(z)??{};var ie={exports:{}},Y={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
+
1
2
  {
2
3
  "name": "@trimble-oss/trimble-id-react",
3
4
  "private": false,
4
- "version": "0.0.1-rc.1",
5
+ "version": "0.0.1-rc.3",
5
6
  "homepage": "https://github.com/trimble-oss/trimble-id-sdk-docs-for-react",
6
7
  "author": "Trimble developers <developers@trimble.com>",
7
8
  "license": "MIT",
9
+ "keywords": [
10
+ "Trimble",
11
+ "TrimbleID"
12
+ ],
8
13
  "type": "module",
9
14
  "scripts": {
10
15
  "build": "tsc && vite build",
@@ -27,7 +32,7 @@
27
32
  "module": "./dist/trimble-id-react.es.js",
28
33
  "types": "./dist/index.d.ts",
29
34
  "dependencies": {
30
- "@trimble-oss/trimble-id": "0.0.1-rc.3",
35
+ "@trimble-oss/trimble-id": "0.0.2-rc.3",
31
36
  "es-cookie": "^1.4.0",
32
37
  "husky": "^8.0.3",
33
38
  "jwt-decode": "^3.1.2"