-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from auth0/webauth-logout-android
Enable WebAuth Logout for Android & Fix iOS Logout.
- Loading branch information
Showing
4 changed files
with
68 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
jest.mock('react-native'); | ||
import Auth from '../../auth'; | ||
import WebAuth from '../index'; | ||
import { NativeModules } from 'react-native'; | ||
import { URL } from 'url'; | ||
|
||
const A0Auth0 = NativeModules.A0Auth0; | ||
|
||
describe('WebAuth', () => { | ||
const auth = new Auth({ baseUrl: 'https://auth0.com', clientId: 'abc123' }); | ||
const webauth = new WebAuth(auth); | ||
|
||
describe('clearSession', () => { | ||
beforeEach(() => { | ||
NativeModules.A0Auth0 = A0Auth0; | ||
A0Auth0.reset(); | ||
}); | ||
|
||
it('should open log out URL', async () => { | ||
await webauth.clearSession(); | ||
|
||
const parsedUrl = new URL(A0Auth0.url); | ||
expect(parsedUrl.protocol).toEqual('https:'); | ||
expect(parsedUrl.hostname).toEqual('auth0.com'); | ||
const urlQuery = parsedUrl.searchParams; | ||
expect(urlQuery.get('returnTo')).toEqual( | ||
'com.my.app://auth0.com/test-os/com.My.App/callback' | ||
); | ||
expect(urlQuery.get('client_id')).toEqual('abc123'); | ||
expect(urlQuery.has('federated')).toEqual(false); | ||
expect(urlQuery.has('auth0Client')).toEqual(true); | ||
}); | ||
|
||
it('should open log out URL with federated=true', async () => { | ||
const options = { federated: true }; | ||
await webauth.clearSession(options); | ||
|
||
const parsedUrl = new URL(A0Auth0.url); | ||
expect(parsedUrl.protocol).toEqual('https:'); | ||
expect(parsedUrl.hostname).toEqual('auth0.com'); | ||
const urlQuery = parsedUrl.searchParams; | ||
expect(urlQuery.get('returnTo')).toEqual( | ||
'com.my.app://auth0.com/test-os/com.My.App/callback' | ||
); | ||
expect(urlQuery.get('client_id')).toEqual('abc123'); | ||
expect(urlQuery.get('federated')).toEqual('true'); | ||
expect(urlQuery.has('auth0Client')).toEqual(true); | ||
}); | ||
}); | ||
}); |
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