Skip to content

Commit c61af2e

Browse files
committed
Adding note and karma file path
1 parent 7da0d9f commit c61af2e

5 files changed

+87
-85
lines changed

docs/ImplicitMSALAuthenticationProvider.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Refer devDependencies in [package.json](../package.json) for the compatible msal version and update that version in below.
44

5-
**Important Note:** MSAL is supported only for frontend applications, for server-side authentication you have to implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
5+
**Important Note:** MSAL is supported only for frontend applications, for server-side authentication you have to can use [TokenCredentialAuthenticationProvider](./TokenCredentialAuthenticationProvider.md) or implement your own AuthenticationProvider. Learn how you can create a [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
66

77
```html
88
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/<version>/js/msal.min.js"></script>

docs/TokenCredentialAuthenticationProvider.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
- [npm - Azure Identity client library for JavaScript](https://www.npmjs.com/package/@azure/identity)
88

9-
- Check the [tokenCredentialSamples folder][../samples/tokencredentialsamples].
9+
- Check the [tokenCredentialSamples folder][../samples/tokencredentialsamples]. The ClientSecretCredentialFlow is an example of using TokenCredential to authenticate a node application. The AuthenticationCodeFlow is an example of using TokenCredential to authenticate a browser application.
10+
11+
**Important Note:** TokenCredentials can be used to authentication browser and node applications.
1012

1113
###### Example of how to create and pass a token credential sample -
1214

1315
```typescript
1416
// Import the TokenCredential class that you wish to use. This examples uses a Client SecretCredential
1517
import { ClientSecretCredential } from "@azure/identity";
16-
18+
import { TokenCredentialAuthenticationProvider, TokenCredentialAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";
1719
// Create an instance of the TokenCredential Class that is imported
1820
const tokenCredential = new ClientSecretCredential("your_tenantId", "your_clientId", "your_clientSecret");
1921

docs/content/Batching.md

+69-69
Original file line numberDiff line numberDiff line change
@@ -66,79 +66,79 @@ const serialBatching = async function(elem) {
6666
};
6767
```
6868

69-
### Download multiple profile photos with batching and preprocess these for rendering in a browser
69+
### Download multiple profile photos with batching and preprocess these for rendering in a browser
7070

7171
You should convert the downloaded photos through batching to a Base64 representation if you want to render these in a browser.
7272

7373
```typescript
74-
b64toBlob = async (b64Data:any, contentType:string, sliceSize?:number):Promise<Blob> => {
75-
contentType = contentType || 'image/png';
76-
sliceSize = sliceSize || 512;
77-
78-
let byteCharacters:string = atob(b64Data);
79-
let byteArrays = [];
80-
81-
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
82-
let slice = byteCharacters.slice(offset, offset + sliceSize);
83-
84-
let byteNumbers = new Array(slice.length);
85-
for (let i = 0; i < slice.length; i++) {
86-
byteNumbers[i] = slice.charCodeAt(i);
87-
}
88-
89-
let byteArray = new Uint8Array(byteNumbers);
90-
byteArrays.push(byteArray);
91-
}
92-
93-
let blob = new Blob(byteArrays, {type: contentType});
94-
return blob;
95-
};
96-
97-
blobToBase64 = (blob: Blob): Promise<string> => {
98-
return new Promise((resolve, reject) => {
99-
const reader = new FileReader();
100-
reader.onerror = reject;
101-
reader.onload = _ => {
102-
resolve(reader.result as string);
103-
};
104-
reader.readAsDataURL(blob);
105-
});
106-
};
107-
108-
downloadPhotosBatching = async (client: Client) => {
109-
try {
110-
111-
112-
// create batch request steps for the users specified above
113-
const batchRequestSteps : BatchRequestStep[] = users.map((userId) => {
114-
const request : BatchRequestStep = {
115-
id: userId,
116-
request: new Request(`/users/${userId}/photo/$value`, {
117-
method: "GET",
118-
})
119-
};
120-
return request;
121-
})
122-
123-
// initiate the batchrequest and execute the operation
124-
const batchRequestContent = new BatchRequestContent(batchRequestSteps);
125-
const content = await batchRequestContent.getContent();
126-
const batchResponse = new BatchResponseContent(await client.api("/$batch").post(content));
127-
128-
// example on how to retrieve the base64 representation of the downloaded image for the first user
129-
const response = batchResponse.getResponseById(users[0]);
130-
if (response.ok) {
131-
var data = await response.text();
132-
const binToBlob = await this.b64toBlob((data),'img/jpg');
133-
134-
// you can associate the base64 output to an src attribute of an <img> HTML tag
135-
const base64Result = await this.blobToBase64(binToBlob);
136-
console.log(base64Result);
137-
}
138-
} catch (error) {
139-
console.error(error);
140-
}
141-
};
74+
b64toBlob = async (b64Data: any, contentType: string, sliceSize?: number): Promise<Blob> => {
75+
contentType = contentType || "image/png";
76+
sliceSize = sliceSize || 512;
77+
78+
let byteCharacters: string = atob(b64Data);
79+
let byteArrays = [];
80+
81+
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
82+
let slice = byteCharacters.slice(offset, offset + sliceSize);
83+
84+
let byteNumbers = new Array(slice.length);
85+
for (let i = 0; i < slice.length; i++) {
86+
byteNumbers[i] = slice.charCodeAt(i);
87+
}
88+
89+
let byteArray = new Uint8Array(byteNumbers);
90+
byteArrays.push(byteArray);
91+
}
92+
93+
let blob = new Blob(byteArrays, { type: contentType });
94+
return blob;
95+
};
96+
97+
blobToBase64 = (blob: Blob): Promise<string> => {
98+
return new Promise((resolve, reject) => {
99+
const reader = new FileReader();
100+
reader.onerror = reject;
101+
reader.onload = (_) => {
102+
resolve(reader.result as string);
103+
};
104+
reader.readAsDataURL(blob);
105+
});
106+
};
107+
108+
downloadPhotosBatching = async (client: Client) => {
109+
try {
110+
111+
112+
// create batch request steps for the users specified above
113+
const batchRequestSteps: BatchRequestStep[] = users.map((userId) => {
114+
const request: BatchRequestStep = {
115+
id: userId,
116+
request: new Request(`/users/${userId}/photo/$value`, {
117+
method: "GET",
118+
}),
119+
};
120+
return request;
121+
});
122+
123+
// initiate the batchrequest and execute the operation
124+
const batchRequestContent = new BatchRequestContent(batchRequestSteps);
125+
const content = await batchRequestContent.getContent();
126+
const batchResponse = new BatchResponseContent(await client.api("/$batch").post(content));
127+
128+
// example on how to retrieve the base64 representation of the downloaded image for the first user
129+
const response = batchResponse.getResponseById(users[0]);
130+
if (response.ok) {
131+
var data = await response.text();
132+
const binToBlob = await this.b64toBlob(data, "img/jpg");
133+
134+
// you can associate the base64 output to an src attribute of an <img> HTML tag
135+
const base64Result = await this.blobToBase64(binToBlob);
136+
console.log(base64Result);
137+
}
138+
} catch (error) {
139+
console.error(error);
140+
}
141+
};
142142
```
143143

144144
### GET and POST contents from and to different workloads - Making parallel requests

karma.conf.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = function(config) {
2-
config.set({
3-
frameworks: ["mocha", "chai", "karma-typescript"],
4-
files: ["test/common/**/*.ts", "src/**/*.ts", "test/browser/**/*.ts", "test/*.ts"],
5-
preprocessors: {
6-
"**/*.ts": ["karma-typescript"],
7-
},
8-
karmaTypescriptConfig: {
9-
tsconfig: "./tsconfig-cjs.json",
10-
},
11-
browsers: ["ChromeHeadless"],
12-
});
13-
};
2+
config.set({
3+
frameworks: ["mocha", "chai", "karma-typescript"],
4+
files: ["test/common/**/*.ts", "src/**/!(azureTokenCredentials)/*.ts", "src/*.ts", "test/browser/**/*.ts", "test/*.ts"],
5+
preprocessors: {
6+
"**/*.ts": ["karma-typescript"],
7+
},
8+
karmaTypescriptConfig: {
9+
tsconfig: "./tsconfig-cjs.json",
10+
},
11+
browsers: ["ChromeHeadless"],
12+
});
13+
};

src/content/BatchRequestContent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class BatchRequestContent {
381381
}
382382
while (!cur.done) {
383383
const requestStep: BatchRequestStep = cur.value[1];
384-
const batchRequestData: BatchRequestData = (await BatchRequestContent.getRequestData(requestStep.request as IsomorphicRequest)) as BatchRequestData;
384+
const batchRequestData: BatchRequestData = (await BatchRequestContent.getRequestData(requestStep.request as IsomorphicRequest)) as BatchRequestData;
385385
/**
386386
* @see{@https://tools.ietf.org/html/rfc7578#section-4.4}
387387
* TODO- Setting/Defaulting of content-type header to the correct value

0 commit comments

Comments
 (0)