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 ,
@@ -85,6 +86,11 @@ const urlParams = new URLSearchParams(window.location.search);
8586
8687( async ( ) => {
8788 const davinciClient : DavinciClient = await davinci ( { config, logger, requestMiddleware } ) ;
89+ const oidcResult = await oidc ( { config : config as OidcConfig } ) ;
90+ if ( 'error' in oidcResult ) {
91+ throw new Error ( `Failed to initialize oidc client: ${ oidcResult . error } ` ) ;
92+ }
93+ const oidcClient = oidcResult ;
8894 const protectApi = protect ( { envId : '02fb4743-189a-4bc7-9d6c-a919edfe6447' } ) ;
8995 const continueToken = urlParams . get ( 'continueToken' ) ;
9096 const formEl = document . getElementById ( 'form' ) as HTMLFormElement ;
@@ -98,10 +104,6 @@ const urlParams = new URLSearchParams(window.location.search);
98104
99105 if ( continueToken ) {
100106 resumed = await davinciClient . resume ( { continueToken } ) ;
101- } else {
102- // the current davinci-config has a slightly
103- // different middleware type than the old legacy config
104- await Config . setAsync ( config as any ) ;
105107 }
106108
107109 function renderComplete ( ) {
@@ -140,25 +142,26 @@ const urlParams = new URLSearchParams(window.location.search);
140142
141143 const tokenBtn = document . getElementById ( 'tokensButton' ) as HTMLButtonElement ;
142144 tokenBtn . addEventListener ( 'click' , async ( ) => {
143- tokens = await TokenManager . getTokens ( { query : { code, state } } ) ;
145+ tokens = await oidcClient . token . exchange ( code , state ) ;
144146
145147 console . log ( tokens ) ;
146148
149+ const accessTokenValue = tokens && 'accessToken' in tokens ? tokens . accessToken : '' ;
147150 const tokenPreEl = document . getElementById ( 'accessTokenContainer' ) as HTMLPreElement ;
148151 tokenPreEl . innerHTML = `
149152 <pre
150153 data-testid="access-token"
151154 id="accessTokenValue"
152155 style="display: block; max-width: 400px; text-wrap: wrap; overflow-wrap: anywhere;"
153- >${ tokens ?. accessToken } </pre>
156+ >${ accessTokenValue } </pre>
154157 ` ;
155158 } ) ;
156159
157160 const loginBtn = document . getElementById ( 'logoutButton' ) as HTMLButtonElement ;
158161 loginBtn . addEventListener ( 'click' , async ( ) => {
159- await FRUser . logout ( { logoutRedirectUri : ` ${ window . location . origin } /` } ) ;
162+ await oidcClient . user . logout ( ) ;
160163
161- // window.location.reload();
164+ window . location . reload ( ) ;
162165 } ) ;
163166 }
164167
0 commit comments