-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into axios-validate-status
- Loading branch information
Showing
15 changed files
with
295 additions
and
64 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-04c92788-a1e3-4dac-ba88-85c8f9be715d.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Fix PCA stub errors (#2963)", | ||
"packageName": "@azure/msal-browser", | ||
"email": "thomas.norling@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-1ebcd183-1b87-40b5-8756-87dcae107034.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Allow apps to not use the current page as default postLogoutRedirectUri in MSAL Browser (#2789)", | ||
"packageName": "@azure/msal-browser", | ||
"email": "janutter@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-720b8a3e-318e-4e14-be1c-9d6be0a687bb.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Setting postLogoutRedirectUri as null will disable post logout redirect", | ||
"packageName": "@azure/msal-common", | ||
"email": "janutter@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,71 @@ | ||
# Errors | ||
1. [I get this error "Access to fetch at [url] has been blocked by CORS policy"](#I-get-this-error-Access-to-fetch-at-[url]-has-been-blocked-by-CORS-policy") | ||
|
||
## I get this error "Access to fetch at [url] has been blocked by CORS policy" | ||
*** | ||
|
||
This error occurs with MSAL.js v2.x and is due to improper configuration during **App Registration** on **Azure Portal**. In particular, you should not have both `Web` and `Single-page application` added as a platform under the **Authentication** blade in your App Registration. | ||
**[BrowserConfigurationAuthErrors](#Browserconfigurationautherrors)** | ||
|
||
1. [stubbed_public_client_application_called](#stubbed_public_client_application_called) | ||
|
||
**[Other](#other)** | ||
|
||
1. [Access to fetch at [url] has been blocked by CORS policy](#Access-to-fetch-at-[url]-has-been-blocked-by-CORS-policy) | ||
|
||
*** | ||
|
||
## BrowserConfigurationAuthErrors | ||
|
||
### stubbed_public_client_application_called | ||
|
||
**Error Message**: Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. | ||
|
||
When using `msal-react` this error is thrown when you try to use an msal component or hook without an `MsalProvider` higher up in the component tree. All `msal-react` hooks and components make use of the [React Context API](https://reactjs.org/docs/context.html) and require a provider. | ||
|
||
❌ The following example will throw this error because the `useMsal` hook is used outside the context of `MsalProvider`: | ||
|
||
```javascript | ||
import { useMsal, MsalProvider } from "@azure/msal-react"; | ||
import { PublicClientApplication } from "@azure/msal-browser"; | ||
|
||
const pca = new PublicClientApplication(config); | ||
|
||
function App() { | ||
const { accounts } = useMsal(); | ||
|
||
return ( | ||
<MsalProvider instance={pca}> | ||
<YourAppComponent> | ||
</ MsalProvider> | ||
) | ||
} | ||
``` | ||
|
||
✔️ To resolve the error you should refactor the code above so that the `useMsal` hook is called in a component underneath `MsalProvider`: | ||
|
||
```javascript | ||
import { useMsal, MsalProvider } from "@azure/msal-react"; | ||
import { PublicClientApplication } from "@azure/msal-browser"; | ||
|
||
const pca = new PublicClientApplication(config); | ||
|
||
function ExampleComponent () { | ||
const { accounts } = useMsal(); | ||
|
||
return <YourAppComponent />; | ||
}; | ||
|
||
function App() { | ||
return ( | ||
<MsalProvider instance={pca}> | ||
<ExampleComponent /> | ||
</ MsalProvider> | ||
) | ||
} | ||
``` | ||
|
||
## Other | ||
|
||
Errors not thrown by msal, such as server errors | ||
|
||
### Access to fetch at [url] has been blocked by CORS policy | ||
|
||
This error occurs with MSAL.js v2.x and is due to improper configuration during **App Registration** on **Azure Portal**. In particular, you should not have both `Web` and `Single-page application` added as a platform under the **Authentication** blade in your App Registration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
lib/msal-browser/test/app/IPublicClientApplication.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import "mocha"; | ||
import chai from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
import { stubbedPublicClientApplication } from "../../src/app/IPublicClientApplication"; | ||
import { BrowserConfigurationAuthErrorMessage } from "../../src/error/BrowserConfigurationAuthError"; | ||
|
||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
|
||
describe("IPublicClientApplication.ts Class Unit Tests", () => { | ||
describe("stubbedPublicClientApplication tests", () => { | ||
it("acquireTokenPopup throws", (done) => { | ||
stubbedPublicClientApplication.acquireTokenPopup({scopes: ["openid"]}).catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("acquireTokenRedirect throws", (done) => { | ||
stubbedPublicClientApplication.acquireTokenRedirect({scopes: ["openid"]}).catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("acquireTokenSilent throws", (done) => { | ||
stubbedPublicClientApplication.acquireTokenSilent({scopes: ["openid"]}).catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
it("handleRedirectPromise throws", (done) => { | ||
stubbedPublicClientApplication.handleRedirectPromise().catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("loginPopup throws", (done) => { | ||
stubbedPublicClientApplication.loginPopup().catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("loginRedirect throws", (done) => { | ||
stubbedPublicClientApplication.loginRedirect().catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("logout throws", (done) => { | ||
stubbedPublicClientApplication.logout().catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("ssoSilent throws", (done) => { | ||
stubbedPublicClientApplication.ssoSilent({}).catch(e => { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("getLogger throws", () => { | ||
try { | ||
stubbedPublicClientApplication.getLogger(); | ||
} catch (e) { | ||
expect(e.errorCode).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code); | ||
expect(e.errorMessage).to.eq(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc); | ||
}; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.