react-native-msal
Advanced tools
Changelog
Default exported class renamed from MSALClient
to PublicClientApplication
and constructor now accepts an MSALConfiguration
object instead of a clientId
string.
-import MSALClient from 'react-native-msal';
+import MSALClient, { MSALConfiguration } from 'react-native-msal';
-const msalClient = new MSALClient(clientId);
+const config: MSALConfiguration = {
+ auth: {
+ clientId,
+ },
+};
+const msalClient = new MSALClient(config);
MSALAccount
and accountIdentifier
propertiesThe MSALAccount
definition has been modified to include a new Claims
dictionary. All methods that previously consumed the identifier
from this type should now provide the entire MSALAccount
object instead.
const result = msalClient.acquireTokenSilent({
authority,
scopes,
- accountIdentifier: account.identifier,
+ account,
});
signOut
methodThe signout
method has been renamed signOut
and authority
removed from the MSALSignoutParams
.
-await msalClient.signout({
- authority,
+await msalClient.signOut({
removeAccount
methodMSALRemoveAccountParams
has been removed and so the removeAccount
method only requires the account
.
-await msalClient.removeAccount({
+await msalClient.removeAccount(
- authority,
account,
-})
+)
ios_prefersEphemeralWebBrowserSession
has moved from acquireToken()
and signOut()
parameters into the new webviewParameters
in MSALInteractiveParams
and MSALSignoutParams
respectively.
-ios_prefersEphemeralWebBrowserSession: true,
+webviewParameters: {
+ ios_prefersEphemeralWebBrowserSession: true,
+},
expiresOn
MSALResult.expiresOn
now returns a value in seconds instead of milliseconds.
MSALResult
interfaceThe result returned from an acquireToken
or acquireTokenSilent
call no longer has an authority
property.
See example/src/b2cClient.ts, but at the very least, knownAuthorities
should be added to the initial client constructor.
You'll need to mock the PublicClientApplication class for testing purposes. One way to do this:
// yourtestfile.test.ts
import PublicClientApplication from 'react-native-msal';
jest.mock('react-native-msal');
const MockPublicClientApplication = PublicClientApplication as jest.MockedClass<PublicClientApplication>;
it('Creates a mock instance without calling native functions', () => {
const mockPca = new MockPublicClientApplication({ auth: { clientId: '1234' } });
expect(MockPublicClientApplication).toHaveBeenCalledTimes(1);
expect(mockPca).not.toBeNull();
});