@pnp/msaljsclient 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ SharePoint Patterns and Practices (PnP)
2
+
3
+ The MIT License (MIT)
4
+
5
+ Copyright (c) Microsoft Corporation
6
+
7
+ All rights reserved.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
package/index.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Configuration, UserAgentApplication } from "msal";
2
+ import { BearerTokenFetchClient, IFetchOptions } from "@pnp/common";
3
+ /**
4
+ * Modifies the msal libray type Configuration, omitting the "framework" property
5
+ */
6
+ export declare type MsalConfiguration = Omit<Configuration, "framework">;
7
+ /**
8
+ * Function Binder suitable for creating a factory function used in setup to create MsalClient instances
9
+ *
10
+ * @param config The MSAL configuration object
11
+ * @param scopes The scope this client should request
12
+ */
13
+ export declare function MsalClientSetup(config: MsalConfiguration, scopes: string[]): () => MsalClient;
14
+ /**
15
+ * Wrapper for MSAL authentication for use in the browser
16
+ */
17
+ export declare class MsalClient extends BearerTokenFetchClient {
18
+ scopes: string[];
19
+ app: UserAgentApplication;
20
+ /**
21
+ * Creates a new instance of the MsalClient
22
+ *
23
+ * @param config the MSAL configuration used to create the client. see: https://github.com/AzureAD/microsoft-authentication-library-for-js
24
+ * @param scopes [optional] The AAD Permission scope names this client should request
25
+ * @param app [optional] If supplied will be used instead of creating a new UserAgentApplication specific to this client
26
+ */
27
+ constructor(config: MsalConfiguration, scopes?: string[], app?: UserAgentApplication);
28
+ /**
29
+ * Conducts the fetch opertation against the AAD secured resource
30
+ *
31
+ * @param url Absolute URL for the request
32
+ * @param options Any fetch options passed to the underlying fetch implementation
33
+ */
34
+ fetch(url: string, options: IFetchOptions): Promise<Response>;
35
+ /**
36
+ * Gets an authentication token from the UserAgentApplication
37
+ *
38
+ * @param scopes [optional] The AAD Permission scope names this client should request
39
+ * @description You must define scopes when calling this method, or when constructing the MsalClient instance, or both
40
+ * @todo a way to control the fall back behavior
41
+ */
42
+ getToken(scopes?: string[]): Promise<string>;
43
+ }
44
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/msaljsclient/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,aAAa,EAAE,oBAAoB,EAAE,MAAM,MAAM,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAiB,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnF;;GAEG;AACH,oBAAY,iBAAiB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAK7F;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,sBAAsB;IASJ,MAAM,EAAE,MAAM,EAAE;IAAc,GAAG,EAAE,oBAAoB;IAPrG;;;;;;OAMG;gBACS,MAAM,EAAE,iBAAiB,EAAS,MAAM,GAAE,MAAM,EAAO,EAAS,GAAG,GAAE,oBAA2B;IAO5G;;;;;OAKG;IACU,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;IAW1E;;;;;;OAMG;IACU,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAyB5D"}
package/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import { __awaiter, __extends, __generator } from "tslib";
2
+ import { UserAgentApplication } from "msal";
3
+ import { BearerTokenFetchClient, isUrlAbsolute } from "@pnp/common";
4
+ /**
5
+ * Function Binder suitable for creating a factory function used in setup to create MsalClient instances
6
+ *
7
+ * @param config The MSAL configuration object
8
+ * @param scopes The scope this client should request
9
+ */
10
+ export function MsalClientSetup(config, scopes) {
11
+ // optimized to share an app per configuration (hopefully)
12
+ var app = new UserAgentApplication(config);
13
+ return function () { return new MsalClient(config, scopes, app); };
14
+ }
15
+ /**
16
+ * Wrapper for MSAL authentication for use in the browser
17
+ */
18
+ var MsalClient = /** @class */ (function (_super) {
19
+ __extends(MsalClient, _super);
20
+ /**
21
+ * Creates a new instance of the MsalClient
22
+ *
23
+ * @param config the MSAL configuration used to create the client. see: https://github.com/AzureAD/microsoft-authentication-library-for-js
24
+ * @param scopes [optional] The AAD Permission scope names this client should request
25
+ * @param app [optional] If supplied will be used instead of creating a new UserAgentApplication specific to this client
26
+ */
27
+ function MsalClient(config, scopes, app) {
28
+ if (scopes === void 0) { scopes = []; }
29
+ if (app === void 0) { app = null; }
30
+ var _this = _super.call(this, null) || this;
31
+ _this.scopes = scopes;
32
+ _this.app = app;
33
+ if (app === null) {
34
+ _this.app = new UserAgentApplication(config);
35
+ }
36
+ return _this;
37
+ }
38
+ /**
39
+ * Conducts the fetch opertation against the AAD secured resource
40
+ *
41
+ * @param url Absolute URL for the request
42
+ * @param options Any fetch options passed to the underlying fetch implementation
43
+ */
44
+ MsalClient.prototype.fetch = function (url, options) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var _a;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ if (!isUrlAbsolute(url)) {
51
+ throw Error("You must supply absolute urls to MsalClient.fetch.");
52
+ }
53
+ // the url we are calling is the resource
54
+ _a = this;
55
+ return [4 /*yield*/, this.getToken()];
56
+ case 1:
57
+ // the url we are calling is the resource
58
+ _a.token = _b.sent();
59
+ return [2 /*return*/, _super.prototype.fetch.call(this, url, options)];
60
+ }
61
+ });
62
+ });
63
+ };
64
+ /**
65
+ * Gets an authentication token from the UserAgentApplication
66
+ *
67
+ * @param scopes [optional] The AAD Permission scope names this client should request
68
+ * @description You must define scopes when calling this method, or when constructing the MsalClient instance, or both
69
+ * @todo a way to control the fall back behavior
70
+ */
71
+ MsalClient.prototype.getToken = function (scopes) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var authParams, resp, e_1, resp, resp2;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ authParams = {
78
+ scopes: scopes || this.scopes,
79
+ };
80
+ _a.label = 1;
81
+ case 1:
82
+ _a.trys.push([1, 3, , 7]);
83
+ return [4 /*yield*/, this.app.acquireTokenSilent(authParams)];
84
+ case 2:
85
+ resp = _a.sent();
86
+ return [2 /*return*/, resp.accessToken];
87
+ case 3:
88
+ e_1 = _a.sent();
89
+ return [4 /*yield*/, this.app.loginPopup(authParams)];
90
+ case 4:
91
+ resp = _a.sent();
92
+ if (!resp.idToken) return [3 /*break*/, 6];
93
+ return [4 /*yield*/, this.app.acquireTokenSilent(authParams)];
94
+ case 5:
95
+ resp2 = _a.sent();
96
+ return [2 /*return*/, resp2.accessToken];
97
+ case 6:
98
+ // throw the error that brought us here
99
+ throw e_1;
100
+ case 7: return [2 /*return*/];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ return MsalClient;
106
+ }(BearerTokenFetchClient));
107
+ export { MsalClient };
108
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/msaljsclient/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAA2C,oBAAoB,EAAE,MAAM,MAAM,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAC;AAOnF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAyB,EAAE,MAAgB;IAEvE,0DAA0D;IAC1D,IAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,cAAM,OAAA,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAnC,CAAmC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH;IAAgC,8BAAsB;IAElD;;;;;;OAMG;IACH,oBAAY,MAAyB,EAAS,MAAqB,EAAS,GAAgC;QAA9D,uBAAA,EAAA,WAAqB;QAAS,oBAAA,EAAA,UAAgC;QAA5G,YACI,kBAAM,IAAI,CAAC,SAId;QAL6C,YAAM,GAAN,MAAM,CAAe;QAAS,SAAG,GAAH,GAAG,CAA6B;QAExG,IAAI,GAAG,KAAK,IAAI,EAAE;YACd,KAAI,CAAC,GAAG,GAAG,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;SAC/C;;IACL,CAAC;IAED;;;;;OAKG;IACU,0BAAK,GAAlB,UAAmB,GAAW,EAAE,OAAsB;;;;;;wBAElD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE;4BACrB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAC;yBACrE;wBAED,yCAAyC;wBACzC,KAAA,IAAI,CAAA;wBAAS,qBAAM,IAAI,CAAC,QAAQ,EAAE,EAAA;;wBADlC,yCAAyC;wBACzC,GAAK,KAAK,GAAG,SAAqB,CAAC;wBACnC,sBAAO,iBAAM,KAAK,YAAC,GAAG,EAAE,OAAO,CAAC,EAAC;;;;KACpC;IAED;;;;;;OAMG;IACU,6BAAQ,GAArB,UAAsB,MAAiB;;;;;;wBAG7B,UAAU,GAA6B;4BACzC,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM;yBAChC,CAAC;;;;wBAKe,qBAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAA;;wBAApD,IAAI,GAAG,SAA6C;wBAC1D,sBAAO,IAAI,CAAC,WAAW,EAAC;;;wBAKX,qBAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAA;;wBAA5C,IAAI,GAAG,SAAqC;6BAC9C,IAAI,CAAC,OAAO,EAAZ,wBAAY;wBACE,qBAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAA;;wBAArD,KAAK,GAAG,SAA6C;wBAC3D,sBAAO,KAAK,CAAC,WAAW,EAAC;;oBAE7B,uCAAuC;oBACvC,MAAM,GAAC,CAAC;;;;;KAEf;IACL,iBAAC;AAAD,CAAC,AAjED,CAAgC,sBAAsB,GAiErD"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@pnp/msaljsclient",
3
+ "version": "2.9.0",
4
+ "description": "pnp - provides an MSAL wrapper client for use with PnPjs",
5
+ "main": "./index.js",
6
+ "typings": "./index",
7
+ "dependencies": {
8
+ "@pnp/common": "2.9.0",
9
+ "msal": "1.4.11",
10
+ "tslib": "2.3.0"
11
+ },
12
+ "author": {
13
+ "name": "Microsoft and other contributors"
14
+ },
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/pnp/pnpjs/issues"
18
+ },
19
+ "homepage": "https://github.com/pnp/pnpjs",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git:github.com/pnp/pnpjs"
23
+ },
24
+ "funding": {
25
+ "type": "individual",
26
+ "url": "https://github.com/sponsors/patrick-rodgers/"
27
+ },
28
+ "type": "module"
29
+ }
package/readme.md ADDED
@@ -0,0 +1,22 @@
1
+ ![SharePoint Patterns and Practices](https://devofficecdn.azureedge.net/media/Default/PnP/sppnp.png)
2
+
3
+ The SharePoint Patterns and Practices client side libraries were created to help enable developers to do their best work, without worrying about the exact
4
+ REST api details. Built with feedback from the community they represent a way to simplify your day-to-day dev cycle while relying on tested and proven
5
+ patterns.
6
+
7
+ Please use [http://aka.ms/sppnp](http://aka.ms/sppnp) for the latest updates around the whole *SharePoint Patterns and Practices (PnP) initiative*.
8
+
9
+ ## Source & Docs
10
+
11
+ This code is managed within the [main pnp repo](https://github.com/pnp/pnp), please report issues and submit pull requests there.
12
+
13
+ Please see the public site for [package documentation](https://pnp.github.io/pnpjs/).
14
+
15
+ ### Code of Conduct
16
+
17
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
18
+
19
+ ### "Sharing is Caring"
20
+
21
+ ### Disclaimer
22
+ **THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**