@pnp/common
Advanced tools
Comparing version 2.1.0-beta10 to 2.1.0-beta11
36
net.d.ts
@@ -43,12 +43,31 @@ import { ISPFXContext } from "./spfxcontextinterface.js"; | ||
export declare class BearerTokenFetchClient extends FetchClient { | ||
private _token; | ||
constructor(_token: string | null); | ||
get token(): string; | ||
set token(token: string); | ||
token: string | null; | ||
constructor(token: string | null); | ||
fetch(url: string, options?: IFetchOptions): Promise<Response>; | ||
} | ||
export interface ILambdaTokenFactoryParams { | ||
/** | ||
* Url to which the request for which we are requesting a token will be sent | ||
*/ | ||
url: string; | ||
/** | ||
* Any options supplied for the request | ||
*/ | ||
options: IFetchOptions; | ||
} | ||
export declare class LambdaFetchClient extends BearerTokenFetchClient { | ||
private tokenFactory; | ||
constructor(tokenFactory: (parms: ILambdaTokenFactoryParams) => Promise<string>); | ||
/** | ||
* Executes a fetch request using the supplied url and options | ||
* | ||
* @param url Absolute url of the request | ||
* @param options Any options | ||
*/ | ||
fetch(url: string, options: IFetchOptions): Promise<Response>; | ||
} | ||
/** | ||
* Client wrapping the aadTokenProvider available from SPFx >= 1.6 | ||
*/ | ||
export declare class SPFxAdalClient extends BearerTokenFetchClient { | ||
export declare class SPFxAdalClient extends LambdaFetchClient { | ||
private context; | ||
@@ -61,9 +80,2 @@ /** | ||
/** | ||
* Executes a fetch request using the supplied url and options | ||
* | ||
* @param url Absolute url of the request | ||
* @param options Any options | ||
*/ | ||
fetch(url: string, options: IFetchOptions): Promise<Response>; | ||
/** | ||
* Gets an AAD token for the provided resource using the SPFx AADTokenProvider | ||
@@ -70,0 +82,0 @@ * |
44
net.js
@@ -40,16 +40,10 @@ import { __awaiter } from "tslib"; | ||
export class BearerTokenFetchClient extends FetchClient { | ||
constructor(_token) { | ||
constructor(token) { | ||
super(); | ||
this._token = _token; | ||
this.token = token; | ||
} | ||
get token() { | ||
return this._token || ""; | ||
} | ||
set token(token) { | ||
this._token = token; | ||
} | ||
fetch(url, options = {}) { | ||
const headers = new Headers(); | ||
mergeHeaders(headers, options.headers); | ||
headers.set("Authorization", `Bearer ${this._token}`); | ||
headers.set("Authorization", `Bearer ${this.token}`); | ||
options.headers = headers; | ||
@@ -59,13 +53,6 @@ return super.fetch(url, options); | ||
} | ||
/** | ||
* Client wrapping the aadTokenProvider available from SPFx >= 1.6 | ||
*/ | ||
export class SPFxAdalClient extends BearerTokenFetchClient { | ||
/** | ||
* | ||
* @param context provide the appropriate SPFx Context object | ||
*/ | ||
constructor(context) { | ||
export class LambdaFetchClient extends BearerTokenFetchClient { | ||
constructor(tokenFactory) { | ||
super(null); | ||
this.context = context; | ||
this.tokenFactory = tokenFactory; | ||
} | ||
@@ -83,8 +70,23 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const token = yield this.getToken(getADALResource(url)); | ||
this.token = token; | ||
this.token = yield this.tokenFactory({ url, options }); | ||
return _super.fetch.call(this, url, options); | ||
}); | ||
} | ||
} | ||
/** | ||
* Client wrapping the aadTokenProvider available from SPFx >= 1.6 | ||
*/ | ||
export class SPFxAdalClient extends LambdaFetchClient { | ||
/** | ||
* | ||
* @param context provide the appropriate SPFx Context object | ||
*/ | ||
constructor(context) { | ||
super((params) => __awaiter(this, void 0, void 0, function* () { | ||
const provider = yield context.aadTokenProviderFactory.getTokenProvider(); | ||
return provider.getToken(getADALResource(params.url)); | ||
})); | ||
this.context = context; | ||
} | ||
/** | ||
* Gets an AAD token for the provided resource using the SPFx AADTokenProvider | ||
@@ -91,0 +93,0 @@ * |
{ | ||
"name": "@pnp/common", | ||
"version": "2.1.0-beta10", | ||
"version": "2.1.0-beta11", | ||
"description": "pnp - provides shared functionality across all pnp libraries", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63688
1051