@obelisk/client
Advanced tools
Comparing version 2.0.15 to 2.1.0
@@ -101,2 +101,17 @@ import { Observable, Observer } from 'rxjs'; | ||
/** | ||
* @hidden | ||
* TODO: Schedules a token refresh WITHIN the expiry data timefrime. Useful for implicit token refreshes. | ||
* @param pat | ||
* @param patRefresh | ||
*/ | ||
private scheduleTokenRefresh; | ||
/** | ||
* Only for refreshing the PAT token. **Only meant for some specific cases** | ||
*/ | ||
refreshPatToken(): Observable<boolean>; | ||
/** | ||
* Only for refreshing the RPT token. **Only meant for some specific cases** | ||
*/ | ||
refreshRptToken(): Observable<boolean>; | ||
/** | ||
* @inheritdoc | ||
@@ -103,0 +118,0 @@ **/ |
@@ -321,3 +321,3 @@ "use strict"; | ||
/** | ||
* @internal | ||
* @hidden | ||
* TODO: Schedules a token refresh WITHIN the expiry data timefrime. Useful for implicit token refreshes. | ||
@@ -339,5 +339,4 @@ * @param pat | ||
* Only for refreshing the PAT token. **Only meant for some specific cases** | ||
* @internal | ||
*/ | ||
refreshToken() { | ||
refreshPatToken() { | ||
const url = this._uma2Config.token_endpoint; | ||
@@ -369,2 +368,33 @@ const clientId = this._options.clientId; | ||
/** | ||
* Only for refreshing the RPT token. **Only meant for some specific cases** | ||
*/ | ||
refreshRptToken() { | ||
const url = this._uma2Config.token_endpoint; | ||
const clientId = this._options.clientId; | ||
if (this._tokens && this._tokens.rptRefresh) { | ||
const tok = this._tokens.rptRefresh; | ||
const headers = { | ||
'Content-type': 'application/x-www-form-urlencoded', | ||
}; | ||
const params = `client_id=${clientId}&grant_type=refresh_token&refresh_token=${tok.getToken()}`; | ||
return ajax_1.ajax.post(url, params, headers).pipe(operators_1.flatMap(resp => { | ||
if (resp.status === 200) { | ||
const body = resp.response; | ||
this._tokens.rpt = new auth_1.Token(body.access_token); | ||
this._tokens.rptRefresh = new auth_1.Token(body.refresh_token); | ||
this._tokens.idtoken = new auth_1.Token(body.id_token); | ||
this._events$.next({ type: interfaces_1.ClientEventType.OnRptChanged }); | ||
this._events$.next({ type: interfaces_1.ClientEventType.OnRolesChanged }); | ||
return rxjs_1.of(true); | ||
} | ||
else { | ||
return rxjs_1.throwError(resp.status + ' ' + resp.responseText); | ||
} | ||
})); | ||
} | ||
else { | ||
return rxjs_1.of(false); | ||
} | ||
} | ||
/** | ||
* @inheritdoc | ||
@@ -371,0 +401,0 @@ **/ |
@@ -189,3 +189,3 @@ "use strict"; | ||
logger_1.Logger.debug('Refreshing token', 'AUTH'); | ||
return client.refreshToken().pipe(operators_1.flatMap(ok => { | ||
return client.refreshPatToken().pipe(operators_1.flatMap(ok => { | ||
let ticket = undefined; | ||
@@ -192,0 +192,0 @@ if (client.options.authMode === 'uma') { |
{ | ||
"name": "@obelisk/client", | ||
"version": "2.0.15", | ||
"version": "2.1.0", | ||
"description": "Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
98095
2616