66 */
77import './style.css' ;
88
9- import { Config , FRUser , TokenManager } from '@forgerock/javascript-sdk' ;
109import { davinci } from '@forgerock/davinci-client' ;
10+ import { oidc } from '@forgerock/oidc-client' ;
11+ import type { OidcConfig } from '@forgerock/oidc-client/types' ;
1112import type {
1213 CustomLogger ,
1314 DaVinciConfig ,
@@ -86,6 +87,11 @@ const urlParams = new URLSearchParams(window.location.search);
8687
8788( async ( ) => {
8889 const davinciClient : DavinciClient = await davinci ( { config, logger, requestMiddleware } ) ;
90+ const oidcResult = await oidc ( { config : config as OidcConfig } ) ;
91+ if ( 'error' in oidcResult ) {
92+ throw new Error ( `Failed to initialize oidc client: ${ oidcResult . error } ` ) ;
93+ }
94+ const oidcClient = oidcResult ;
8995 const protectApi = protect ( { envId : '02fb4743-189a-4bc7-9d6c-a919edfe6447' } ) ;
9096 const continueToken = urlParams . get ( 'continueToken' ) ;
9197 const formEl = document . getElementById ( 'form' ) as HTMLFormElement ;
@@ -99,10 +105,6 @@ const urlParams = new URLSearchParams(window.location.search);
99105
100106 if ( continueToken ) {
101107 resumed = await davinciClient . resume ( { continueToken } ) ;
102- } else {
103- // the current davinci-config has a slightly
104- // different middleware type than the old legacy config
105- await Config . setAsync ( config as any ) ;
106108 }
107109
108110 function renderComplete ( ) {
@@ -141,25 +143,26 @@ const urlParams = new URLSearchParams(window.location.search);
141143
142144 const tokenBtn = document . getElementById ( 'tokensButton' ) as HTMLButtonElement ;
143145 tokenBtn . addEventListener ( 'click' , async ( ) => {
144- tokens = await TokenManager . getTokens ( { query : { code, state } } ) ;
146+ tokens = await oidcClient . token . exchange ( code , state ) ;
145147
146148 console . log ( tokens ) ;
147149
150+ const accessTokenValue = tokens && 'accessToken' in tokens ? tokens . accessToken : '' ;
148151 const tokenPreEl = document . getElementById ( 'accessTokenContainer' ) as HTMLPreElement ;
149152 tokenPreEl . innerHTML = `
150153 <pre
151154 data-testid="access-token"
152155 id="accessTokenValue"
153156 style="display: block; max-width: 400px; text-wrap: wrap; overflow-wrap: anywhere;"
154- >${ tokens ?. accessToken } </pre>
157+ >${ accessTokenValue } </pre>
155158 ` ;
156159 } ) ;
157160
158161 const loginBtn = document . getElementById ( 'logoutButton' ) as HTMLButtonElement ;
159162 loginBtn . addEventListener ( 'click' , async ( ) => {
160- await FRUser . logout ( { logoutRedirectUri : ` ${ window . location . origin } /` } ) ;
163+ await oidcClient . user . logout ( ) ;
161164
162- // window.location.reload();
165+ window . location . reload ( ) ;
163166 } ) ;
164167 }
165168
0 commit comments