forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): HostedUI oidc signout (aws-amplify#13512)
* chore(auth): add oauth metadata into token orchestrator (aws-amplify#13712) (aws-amplify#13736) * chore: add oauth metadata into token orchestrator * chore: add unit tests * chore: address feedback * wip: hardcode signout uri for poc * chore: expose the prefferedRedirectSignOutUrl * chore: add prefered url change to native file * chore: correct param name * chore: update getRedirectUrl function to consider preferred url * chore: add unit test for the feature * chore: update input type to use the accepted format * chore: review comments * fix: address npm audit issues * chore: update comments, bundle size and rn version * chore: update bundle size limit * chore: update bundle size limit * chore: address coments and rename a param to getRedirecturl funciton * chore: make preid release ready * chore: update yarn.lock * chore: add test and update push-integ branch * chore: revert preid release updates * chore: update sample name * chore: enable react native tests with localhost server * chore: enable subdomain test * chore: update some function calls in tests * chore: minor reverts * fix: unit tests fail on mehtod params * chore: revert ppush branch * chore: remove subdomain test rdundant * chore: upadte step name * chore: reflect API changes and clean up * chore: revert unintented change glob * chore: bundle size minor adjustments * chore: move localhost page hosting to RN script in the app * chore: revert unintended change * chore: revert branch name for integ test --------- Co-authored-by: israx <70438514+israx@users.noreply.github.com> Co-authored-by: AllanZhengYP <zheallan@amazon.com>
- Loading branch information
1 parent
a363362
commit e8fb997
Showing
22 changed files
with
463 additions
and
199 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
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 |
---|---|---|
|
@@ -137,5 +137,8 @@ | |
"nx": "16.7.0", | ||
"xml2js": "0.5.0", | ||
"tar": "6.2.1" | ||
}, | ||
"overrides": { | ||
"tar": "6.2.1" | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
packages/auth/__tests__/providers/cognito/utils/oauth/getRedirectUrl.native.test.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,35 @@ | ||
import { invalidAppSchemeException } from '../../../../../src/errors/constants'; | ||
import { getRedirectUrl } from '../../../../../src/providers/cognito/utils/oauth/getRedirectUrl.native'; | ||
|
||
describe('getRedirectUrl (native)', () => { | ||
const mockRedirectUrls = [ | ||
'myDevApp://', | ||
'myProdApp://', | ||
'https://intermidiateSite.com', | ||
]; | ||
|
||
it('should return the first non http/s url from the array when redirectUrl is not provided', () => { | ||
expect(getRedirectUrl(mockRedirectUrls)).toStrictEqual(mockRedirectUrls[0]); | ||
}); | ||
|
||
it('should return redirectUrl if it matches at least one of the redirect urls from config', () => { | ||
const configRedirectUrl = mockRedirectUrls[2]; | ||
|
||
expect(getRedirectUrl(mockRedirectUrls, configRedirectUrl)).toStrictEqual( | ||
configRedirectUrl, | ||
); | ||
}); | ||
|
||
it('should throw an exception when there is no url with no http nor https as prefix irrespective of a redirectUrl is given or not', () => { | ||
const mockRedirectUrlsWithNoAppScheme = ['https://intermidiateSite.com']; | ||
expect(() => | ||
getRedirectUrl( | ||
mockRedirectUrlsWithNoAppScheme, | ||
mockRedirectUrlsWithNoAppScheme[0], | ||
), | ||
).toThrow(invalidAppSchemeException); | ||
expect(() => getRedirectUrl(mockRedirectUrlsWithNoAppScheme)).toThrow( | ||
invalidAppSchemeException, | ||
); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/auth/__tests__/providers/cognito/utils/oauth/getRedirectUrl.test.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,66 @@ | ||
import { getRedirectUrl } from '../../../../../src/providers/cognito/utils/oauth'; | ||
import { | ||
invalidOriginException, | ||
invalidPreferredRedirectUrlException, | ||
invalidRedirectException, | ||
} from '../../../../../src/errors/constants'; | ||
|
||
describe('getRedirectUrl', () => { | ||
const mockRedirectUrls = ['https://example.com/app']; | ||
let windowSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
windowSpy = jest.spyOn(window, 'window', 'get'); | ||
}); | ||
|
||
afterEach(() => { | ||
windowSpy.mockRestore(); | ||
}); | ||
|
||
it('should return the redirect url that has the same origin and same pathName', () => { | ||
windowSpy.mockReturnValue({ | ||
location: { | ||
origin: 'https://example.com/', | ||
pathname: 'app', | ||
}, | ||
}); | ||
expect(getRedirectUrl(mockRedirectUrls)).toStrictEqual(mockRedirectUrls[0]); | ||
}); | ||
|
||
it('should throw an invalid origin exception if there is no url that is the same origin and pathname', () => { | ||
windowSpy.mockReturnValue({ | ||
location: { | ||
origin: 'https://differentOrigin.com/', | ||
pathname: 'differentApp', | ||
}, | ||
}); | ||
expect(() => getRedirectUrl(mockRedirectUrls)).toThrow( | ||
invalidOriginException, | ||
); | ||
}); | ||
|
||
it('should throw an invalid redirect exception if there is no url that is the same origin/pathname and is also not http or https', () => { | ||
const mockNonHttpRedirectUrls = ['test-non-http-string']; | ||
windowSpy.mockReturnValue({ | ||
location: { | ||
origin: 'https://differentOrigin.com/', | ||
pathname: 'differentApp', | ||
}, | ||
}); | ||
expect(() => getRedirectUrl(mockNonHttpRedirectUrls)).toThrow( | ||
invalidRedirectException, | ||
); | ||
}); | ||
|
||
it('should return the redirectUrl if it is provided and matches one of the redirectUrls from config', () => { | ||
expect(getRedirectUrl(mockRedirectUrls, mockRedirectUrls[0])).toStrictEqual( | ||
mockRedirectUrls[0], | ||
); | ||
}); | ||
|
||
it('should throw an exception if redirectUrl is given but does not match any of the redirectUrls from config', () => { | ||
expect(() => | ||
getRedirectUrl(mockRedirectUrls, 'https://unknownOrigin.com'), | ||
).toThrow(invalidPreferredRedirectUrlException); | ||
}); | ||
}); |
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
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
Oops, something went wrong.