Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@obelisk/client

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@obelisk/client - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

13

lib/obelisk-client.d.ts

@@ -21,2 +21,3 @@ import { Observable, Observer } from 'rxjs';

private _config$;
private CRED_KEY;
private readonly defaultOptions;

@@ -45,3 +46,9 @@ /**

}): string;
private storeClientCredentials;
private loadClientCredentials;
/**
* Client credentials will be cleared from Session storage, if they were present
*/
clearClientCredentials(): void;
/**
* @inheritdoc

@@ -90,3 +97,3 @@ */

/**
* Clears all tokens
* Clears all tokens. Including session storage client credentials.
*/

@@ -120,4 +127,6 @@ private clearTokens;

* Only for refreshing the RPT token. **Only meant for some specific cases**
* @param useClientCredentials Optional parameter: if true it will refresh using the session client credentials,
* instead of the credenitals set at client init time.
*/
refreshRptToken(): Observable<boolean>;
refreshRptToken(useClientCredentials?: boolean): Observable<boolean>;
/**

@@ -124,0 +133,0 @@ * @inheritdoc

@@ -40,2 +40,3 @@ "use strict";

this.authOver$ = new rxjs_1.ReplaySubject(1);
this.CRED_KEY = window.origin + '/cr';
}

@@ -98,3 +99,20 @@ getConfig() {

}
storeClientCredentials(clientId, clientSecret) {
const cred = { clientId, clientSecret };
sessionStorage.setItem(this.CRED_KEY, btoa(JSON.stringify(cred)));
}
loadClientCredentials() {
const cred = sessionStorage.getItem(this.CRED_KEY);
if (!cred) {
throw 'No credentials in session';
}
return JSON.parse(atob(cred));
}
/**
* Client credentials will be cleared from Session storage, if they were present
*/
clearClientCredentials() {
sessionStorage.removeItem(this.CRED_KEY);
}
/**
* @inheritdoc

@@ -105,2 +123,4 @@ */

// this.options.clientId = clientId;
// Store in session storage
this.storeClientCredentials(clientId, clientSecret);
const tokenUrl = this._uma2Config.token_endpoint;

@@ -141,2 +161,3 @@ const headers = { 'Content-type': 'application/x-www-form-urlencoded' };

this.clearTokens();
this.clearClientCredentials();
window.location.href = this.createLogoutUrl(redirectUri);

@@ -218,9 +239,24 @@ }

try {
const ok = this.isLoggedIn();
if (this._tokens.pat === undefined && ok) {
util_1.Logger.debug('No PAT and loggedIn in storatge: Try to log in silently', 'AUTHN');
const recentlyLoggedIn = this.isLoggedIn();
if (this._tokens.pat === undefined && recentlyLoggedIn) {
util_1.Logger.debug('No PAT and loggedIn in storage: Try to log in silently', 'AUTHN');
this.login({ prompt: 'none' });
}
this.authOver$.next();
return ok;
if (!recentlyLoggedIn) {
// Check if there are clientCredentials present
try {
const cred = this.loadClientCredentials();
// Client credentials present, lets login with them
return this.loginAsClient(cred.clientId, cred.clientSecret).pipe(operators_1.map(token => !!token), operators_1.tap(_ => this.authOver$.next()));
}
catch (err) {
// No client credentials, just proceed as normal
this.authOver$.next();
return rxjs_1.of(recentlyLoggedIn);
}
}
else {
this.authOver$.next();
return rxjs_1.of(recentlyLoggedIn);
}
}

@@ -230,7 +266,7 @@ catch (err) {

this.authOver$.next();
return false;
return rxjs_1.of(false);
}
}
/**
* Clears all tokens
* Clears all tokens. Including session storage client credentials.
*/

@@ -266,3 +302,3 @@ clearTokens() {

this.authOver$.next();
return rxjs_1.of(false);
return this.isAuthenticated(); //of(false);
}

@@ -353,3 +389,3 @@ try {

// No fragment error: means it is a regular page load => check auth status in storage via is Authenticated
return rxjs_1.of(this.isAuthenticated());
return this.isAuthenticated();
}

@@ -405,6 +441,7 @@ ;

* Only for refreshing the RPT token. **Only meant for some specific cases**
* @param useClientCredentials Optional parameter: if true it will refresh using the session client credentials,
* instead of the credenitals set at client init time.
*/
refreshRptToken() {
refreshRptToken(useClientCredentials) {
const url = this._uma2Config.token_endpoint;
const clientId = this._options.clientId;
if (this._tokens && this._tokens.rptRefresh) {

@@ -415,3 +452,18 @@ const tok = this._tokens.rptRefresh;

};
const params = `client_id=${clientId}&grant_type=refresh_token&refresh_token=${tok.getToken()}`;
let params = `grant_type=refresh_token&refresh_token=${tok.getToken()}`;
if (useClientCredentials) {
try {
const cred = this.loadClientCredentials();
params += `&client_id=${cred.clientId}&client_secret=${cred.clientSecret}`;
}
catch (_a) {
// Credentials are not present, log out.
this.logout();
return rxjs_1.of(false);
}
}
else {
const clientId = this._options.clientId;
params += `&client_id=${clientId}`;
}
return ajax_1.ajax.post(url, params, headers).pipe(operators_1.flatMap(resp => {

@@ -418,0 +470,0 @@ if (resp.status === 200) {

2

package.json
{
"name": "@obelisk/client",
"version": "2.2.0",
"version": "2.3.0",
"description": "Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc