Skip to content

Commit 8ee9df3

Browse files
Resolving review comments
1 parent ba34bd9 commit 8ee9df3

File tree

10 files changed

+57
-11
lines changed

10 files changed

+57
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ supported authentication portals:
5959

6060
### 2. Authenticate for the Microsoft Graph service
6161

62-
The Microsoft Graph JavaScript Client Library has an adapter implementation ([MSALAuthenticationProvider](src/MSALAuthenticationProvider.ts)) for [MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core) (Microsoft Authentication Library) which takes care of getting the `accessToken`. MSAL library does not ship with this library, user have to include it externally (For including MSAL, refer [this](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core#installation)).
62+
The Microsoft Graph JavaScript Client Library has an adapter implementation ([MSALAuthenticationProvider](src/MSALAuthenticationProvider.ts)) for [MSAL](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core) (Microsoft Authentication Library) which takes care of getting the `accessToken`. MSAL library does not ship with this library, user has to include it externally (For including MSAL, refer [this](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core#installation)).
6363

6464
> **Note:** MSAL is supported only for frontend applications, for server-side authentication you have to implement your own AuthenticationProvider. Refer implementing [Custom Authentication Provider](./docs/CustomAuthenticationProvider.md).
6565

docs/CreatingClientInstance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In order to instantiate a Client object, one has to pass in the `authProvider` o
88

99
### Option A. Default Middleware chain
1010

11-
Pass an instance of a class which implementing [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface as `authProvider` in [ClientOptions](../src/IClientOptions.ts), which will instantiate the Client with default set of middleware chain.
11+
Pass an instance of a class which implements [AuthenticationProvider](../src/IAuthenticationProvider.ts) interface as `authProvider` in [ClientOptions](../src/IClientOptions.ts), which will instantiate the Client with default set of middleware chain.
1212

1313
Library is shipped with one such authentication provider named [MSALAuthenticationProvider](../src/MSALAuthenticationProvider.ts). This MSALAuthenticationProvider depends on an authentication library [msal.js](https://github.com/AzureAD/microsoft-authentication-library-for-js) which is not shipped along with the library, one has to externally include msal.js to use MSALAuthenticationProvider.
1414

@@ -49,7 +49,7 @@ Refer, [custom middleware chain](./CustomMiddlewareChain.md) for more detailed i
4949

5050
## 2. Create With Options
5151

52-
Pass an [authProvider function](../src/IAuthProvider.ts) in [Options](../src/IOptions.ts) while initializing the Client. In this case, user have to provide his own implementation for getting and refreshing accessToken. A callback will be passed into this authProvider function, accessToken or error needs to be passed in to that callback.
52+
Pass an [authProvider function](../src/IAuthProvider.ts) in [Options](../src/IOptions.ts) while initializing the Client. In this case, user has to provide his own implementation for getting and refreshing accessToken. A callback will be passed into this authProvider function, accessToken or error needs to be passed in to that callback.
5353

5454
```typescript
5555
// Some callback function

lib/graph-js-sdk-core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/graph-js-sdk-web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/spec/core/Client.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/spec/core/Client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/Client.js

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/Client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/core/Client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ describe("Client.ts", function () {
2525
const dummyAuthProvider = new DummyAuthenticationProvider(),
2626
customHTTPHandler = new CustomHTTPHandler();
2727

28+
it("Should throw an error in case if both auth provider and custom middleware is passed", () => {
29+
try {
30+
const options: ClientOptions = {
31+
authProvider: dummyAuthProvider,
32+
middleware: customHTTPHandler
33+
};
34+
const client: Client = Client.initWithMiddleware(options);
35+
throw new Error("Something wrong with the ambiguity check");
36+
} catch(error) {
37+
assert.equal(error.name, "AmbiguityInInitialization");
38+
}
39+
});
40+
2841
it("Should return client instance for an authentication provider", () => {
2942
let options: ClientOptions = {
3043
authProvider: dummyAuthProvider

src/Client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ export class Client {
5353
self.config[key] = clientOptions[key];
5454
}
5555
let httpClient: HTTPClient;
56-
if (clientOptions.authProvider !== undefined) {
56+
if(clientOptions.authProvider !== undefined && clientOptions.middleware !== undefined) {
57+
const error = new Error();
58+
error.name = "AmbiguityInInitialization";
59+
error.message = "Unable to Create Client, Please provide either authentication provider for default middleware chain or custom middleware chain not both";
60+
throw error;
61+
} else if (clientOptions.authProvider !== undefined) {
5762
httpClient = HTTPClientFactory.createWithAuthenticationProvider(clientOptions.authProvider);
5863
} else if (clientOptions.middleware !== undefined) {
5964
httpClient = new HTTPClient(clientOptions.middleware);
@@ -93,7 +98,11 @@ export class Client {
9398
* @returns The Client instance
9499
*/
95100
public static initWithMiddleware(options: ClientOptions): Client {
96-
return new Client(options);
101+
try {
102+
return new Client(options);
103+
} catch (error) {
104+
throw error;
105+
}
97106
}
98107

99108
/**

0 commit comments

Comments
 (0)