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

@pnp/adaljsclient

Package Overview
Dependencies
Maintainers
13
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnp/adaljsclient - npm Package Compare versions

Comparing version 2.1.0-beta1 to 2.1.0-beta10

154

index.js

@@ -1,4 +0,3 @@

import { __awaiter, __extends, __generator } from "tslib";
import { __awaiter } from "tslib";
import { BearerTokenFetchClient, isUrlAbsolute, SPFxAdalClient, getADALResource } from "@pnp/common";
// @ts-ignore
import * as adal from "adal-angular/dist/adal.min.js";

@@ -8,4 +7,3 @@ /**

*/
var AdalClient = /** @class */ (function (_super) {
__extends(AdalClient, _super);
export class AdalClient extends BearerTokenFetchClient {
/**

@@ -17,10 +15,9 @@ * Creates a new instance of AdalClient

*/
function AdalClient(clientId, tenant, redirectUri) {
var _this = _super.call(this, null) || this;
_this.clientId = clientId;
_this.tenant = tenant;
_this.redirectUri = redirectUri;
_this._displayCallback = null;
_this._loginPromise = null;
return _this;
constructor(clientId, tenant, redirectUri) {
super(null);
this.clientId = clientId;
this.tenant = tenant;
this.redirectUri = redirectUri;
this._displayCallback = null;
this._loginPromise = null;
}

@@ -34,5 +31,5 @@ /**

*/
AdalClient.fromSPFxContext = function (spfxContext) {
static fromSPFxContext(spfxContext) {
return new SPFxAdalClient(spfxContext);
};
}
/**

@@ -44,20 +41,16 @@ * Conducts the fetch opertation against the AAD secured resource

*/
AdalClient.prototype.fetch = function (url, options) {
return __awaiter(this, void 0, void 0, function () {
var token;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!isUrlAbsolute(url)) {
throw Error("You must supply absolute urls to AdalClient.fetch.");
}
return [4 /*yield*/, this.getToken(getADALResource(url))];
case 1:
token = _a.sent();
this.token = token;
return [2 /*return*/, _super.prototype.fetch.call(this, url, options)];
}
});
fetch(url, options) {
const _super = Object.create(null, {
fetch: { get: () => super.fetch }
});
};
return __awaiter(this, void 0, void 0, function* () {
if (!isUrlAbsolute(url)) {
throw Error("You must supply absolute urls to AdalClient.fetch.");
}
// the url we are calling is the resource
const token = yield this.getToken(getADALResource(url));
this.token = token;
return _super.fetch.call(this, url, options);
});
}
/**

@@ -68,63 +61,52 @@ * Gets a token based on the current user

*/
AdalClient.prototype.getToken = function (resource) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.login()];
case 1:
_a.sent();
return [2 /*return*/, new Promise(function (resolve, reject) {
AdalClient._authContext.acquireToken(resource, function (message, token) {
if (message) {
reject(Error(message));
}
else {
resolve(token);
}
});
})];
}
getToken(resource) {
return __awaiter(this, void 0, void 0, function* () {
yield this.login();
return new Promise((resolve, reject) => {
AdalClient._authContext.acquireToken(resource, (message, token) => {
if (message) {
reject(Error(message));
}
else {
resolve(token);
}
});
});
});
};
}
/**
* Ensures we have created and setup the adal AuthenticationContext instance
*/
AdalClient.prototype.ensureAuthContext = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (AdalClient._authContext === null) {
AdalClient._authContext = adal.inject({
clientId: this.clientId,
displayCall: function (url) {
if (_this._displayCallback) {
_this._displayCallback(url);
}
},
navigateToLoginRequestUrl: false,
redirectUri: this.redirectUri,
tenant: this.tenant,
});
}
return [2 /*return*/];
});
ensureAuthContext() {
return __awaiter(this, void 0, void 0, function* () {
if (AdalClient._authContext === null) {
AdalClient._authContext = adal.inject({
clientId: this.clientId,
displayCall: (url) => {
if (this._displayCallback) {
this._displayCallback(url);
}
},
navigateToLoginRequestUrl: false,
redirectUri: this.redirectUri,
tenant: this.tenant,
});
}
});
};
}
/**
* Ensures the current user is logged in
*/
AdalClient.prototype.login = function () {
var _this = this;
login() {
if (this._loginPromise) {
return this._loginPromise;
}
this._loginPromise = new Promise(function (resolve, reject) {
this._loginPromise = new Promise((resolve, reject) => {
// this triggers the login process
_this.ensureAuthContext().then(function (_) {
this.ensureAuthContext().then(() => {
if (AdalClient._authContext.getCachedUser()) {
return resolve();
}
_this._displayCallback = function (url) {
var popupWindow = window.open(url, "login", "width=483, height=600");
this._displayCallback = (url) => {
const popupWindow = window.open(url, "login", "width=483, height=600");
if (!popupWindow) {

@@ -136,3 +118,3 @@ return reject(Error("Could not open pop-up window for auth. Likely pop-ups are blocked by the browser."));

}
var pollTimer = window.setInterval(function () {
const pollTimer = window.setInterval(() => {
try {

@@ -142,3 +124,3 @@ if (!popupWindow || popupWindow.closed || popupWindow.closed === undefined) {

}
if (popupWindow.document.URL.indexOf(_this.redirectUri) !== -1) {
if (popupWindow.document.URL.indexOf(this.redirectUri) !== -1) {
AdalClient._authContext.handleWindowCallback(popupWindow.location.hash);

@@ -159,14 +141,12 @@ popupWindow.close();

AdalClient._authContext.login();
_this._displayCallback = null;
this._displayCallback = null;
});
});
return this._loginPromise;
};
/**
* Our auth context
*/
AdalClient._authContext = null;
return AdalClient;
}(BearerTokenFetchClient));
export { AdalClient };
}
}
/**
* Our auth context
*/
AdalClient._authContext = null;
//# sourceMappingURL=index.js.map
{
"name": "@pnp/adaljsclient",
"version": "2.1.0-beta1",
"version": "2.1.0-beta10",
"description": "pnp - provides an ADAL client for use with PnPjs",

@@ -8,5 +8,5 @@ "main": "./index.js",

"dependencies": {
"adal-angular": "1.0.17",
"tslib": "2.0.0",
"@pnp/common": "2.1.0-beta1"
"adal-angular": "1.0.18",
"tslib": "2.0.3",
"@pnp/common": "2.1.0-beta10"
},

@@ -13,0 +13,0 @@ "devDependencies": {

@@ -0,0 +0,0 @@ ![SharePoint Patterns and Practices](https://devofficecdn.azureedge.net/media/Default/PnP/sppnp.png)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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