@obelisk/client
Advanced tools
Comparing version
import { Observable } from 'rxjs'; | ||
import { TPage } from '.'; | ||
import { ObeliskClient } from '../obelisk-client'; | ||
@@ -27,3 +26,3 @@ /** | ||
*/ | ||
connect(options?: StreamOptions): Observable<TPage>; | ||
connect(options?: StreamOptions): Observable<any>; | ||
/** | ||
@@ -30,0 +29,0 @@ * Wraps the EventSourcePolyfill in an Observable. |
@@ -40,2 +40,9 @@ import { Observable } from "rxjs"; | ||
/** | ||
* Login as client. This can be used to login as the client itself. | ||
* It will immediatly request an RPT token and return that. | ||
* @param clientId | ||
* @param clientSecret | ||
*/ | ||
loginAsClient(clientId: string, clientSecret: string): Observable<Token>; | ||
/** | ||
* Construct an TPageEndpoint instance that you can query to get data. | ||
@@ -42,0 +49,0 @@ * This should be an endpoint that returns a Temporal Page. |
@@ -47,2 +47,6 @@ import { Observable, Observer } from 'rxjs'; | ||
*/ | ||
loginAsClient(clientId: string, clientSecret: string): Observable<Token>; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
login(loginOptions?: { | ||
@@ -103,3 +107,3 @@ redirectUri?: string; | ||
* @hidden | ||
* TODO: Schedules a token refresh WITHIN the expiry data timefrime. Useful for implicit token refreshes. | ||
* TODO: Schedules a token refresh WITHIN the expiry date timeframe. Useful for implicit token refreshes. | ||
* @param pat | ||
@@ -106,0 +110,0 @@ * @param patRefresh |
@@ -100,2 +100,32 @@ "use strict"; | ||
*/ | ||
loginAsClient(clientId, clientSecret) { | ||
this.checkInit(); | ||
// this.options.clientId = clientId; | ||
const tokenUrl = this._uma2Config.token_endpoint; | ||
const headers = { 'Content-type': 'application/x-www-form-urlencoded' }; | ||
let params = `grant_type=client_credentials`; | ||
// const redUri = window.location.origin + window.location.pathname; | ||
params += '&client_id=' + encodeURIComponent(clientId); | ||
params += '&client_secret=' + encodeURIComponent(clientSecret); | ||
params += '&scope=openid'; | ||
// params += '&redirect_uri=' + redUri; | ||
return ajax_1.ajax.post(tokenUrl, params, headers).pipe(operators_1.flatMap(resp => { | ||
const authResponse = resp.response; | ||
const pat = new auth_1.Token(authResponse.access_token); | ||
const patRefresh = new auth_1.Token(authResponse.refresh_token); | ||
const idtok = new auth_1.Token(authResponse.id_token); | ||
// store in memory | ||
this._tokens.pat = pat; | ||
this._tokens.patRefresh = patRefresh; | ||
this._tokens.idtoken = idtok; | ||
// store logged in + expiration | ||
this._storage.add('logInfo', { authenticated: true, expires: pat.getExpiresAt() }); | ||
// this.scheduleTokenRefresh(pat, patRefresh); | ||
this.authOver$.next(); | ||
return rxjs_1.of(true); | ||
}), operators_1.switchMap(() => this.getNewRpt())); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
login(loginOptions) { | ||
@@ -305,3 +335,3 @@ window.location.href = this.createLoginUrl(loginOptions); | ||
this._storage.add('logInfo', { authenticated: true, expires: pat.getExpiresAt() }); | ||
this.scheduleTokenRefresh(pat, patRefresh); | ||
// this.scheduleTokenRefresh(pat, patRefresh); | ||
this.authOver$.next(); | ||
@@ -324,3 +354,3 @@ return rxjs_1.of(true); | ||
* @hidden | ||
* TODO: Schedules a token refresh WITHIN the expiry data timefrime. Useful for implicit token refreshes. | ||
* TODO: Schedules a token refresh WITHIN the expiry date timeframe. Useful for implicit token refreshes. | ||
* @param pat | ||
@@ -332,4 +362,4 @@ * @param patRefresh | ||
const expiry = pat.getExpiresAt(); | ||
// Refresh 2 minutes before expiry | ||
const refreshTime = expiry - (2 * 60 * 1000); | ||
// Refresh 30 seconds before expiry | ||
const refreshTime = expiry - (30 * 1000); | ||
// Use patRefresh to refresh | ||
@@ -336,0 +366,0 @@ setTimeout(() => { |
{ | ||
"name": "@obelisk/client", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
99805
1.89%2652
1.53%