@@ -47,6 +47,30 @@ async function refresh({ tokenEndpointParams } = {}) {
4747 return this . accessToken ;
4848}
4949
50+ async function replace ( refreshToken ) {
51+ let { config, req } = weakRef ( this ) ;
52+
53+ const client = await getClient ( config ) ;
54+ const newTokenSet = await client . refresh ( refreshToken ) ;
55+
56+ // Update the session
57+ const session = req [ config . session . name ] ;
58+ Object . assign ( session , {
59+ id_token : newTokenSet . id_token ,
60+ access_token : newTokenSet . access_token ,
61+ refresh_token : newTokenSet . refresh_token || refreshToken ,
62+ token_type : newTokenSet . token_type ,
63+ expires_at : newTokenSet . expires_at ,
64+ } ) ;
65+
66+ // Delete the old token set
67+ const cachedTokenSet = weakRef ( session ) ;
68+
69+ delete cachedTokenSet . value ;
70+
71+ return this . accessToken ;
72+ }
73+
5074function tokenSet ( ) {
5175 const contextCache = weakRef ( this ) ;
5276 const session = contextCache . req [ contextCache . config . session . name ] ;
@@ -111,6 +135,7 @@ class RequestContext {
111135 expires_in,
112136 isExpired : isExpired . bind ( this ) ,
113137 refresh : refresh . bind ( this ) ,
138+ replace : replace . bind ( this ) ,
114139 } ;
115140 } catch ( err ) {
116141 return undefined ;
0 commit comments