Skip to content

Commit

Permalink
feat: All oauth methods to handle reconection case
Browse files Browse the repository at this point in the history
Now checkOAuthData and handleOAuthResponse can handle calls without any
account id when in reconnection case.
  • Loading branch information
doubleface authored and doubleface committed Jul 1, 2022
1 parent 58e1bb1 commit b1a6033
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
9 changes: 4 additions & 5 deletions packages/cozy-harvest-lib/src/helpers/oauth.js
Expand Up @@ -21,8 +21,8 @@ export const OAUTH_REALTIME_CHANNEL = 'oauth-popup'
export const checkOAuthData = (konnector, data) => {
if (!data) return false

const { key, oAuthStateKey } = data
if (!key || !oAuthStateKey) return false
const { oAuthStateKey } = data
if (!oAuthStateKey) return false

const accountType = konnectors.getAccountType(konnector)

Expand All @@ -41,10 +41,10 @@ export const checkOAuthData = (konnector, data) => {
* @param {Object} options.realtime (optional) : cozy-realtime instance used to notify the
* resulting accountId to the origin harvest window after OAuth redirect
*
* We are supposed here to be in the OAuth popup, at the end of the process.
* We are supposed here to be in the OAuth popup or OAuth inAppBrowser, at the end of the process.
*
* We first check that we are actually getting the response we were expecting
* for, and then we sent the account Id with postMessage
* for, and then we sent the account Id with postMessage if any
*
* This handler should be typically used in the OAuth popup the following way:
* ```js
Expand Down Expand Up @@ -73,7 +73,6 @@ export const handleOAuthResponse = (options = {}) => {
const queryParams = new URLSearchParams(window.location.search)

const accountId = queryParams.get('account')
if (!accountId) return false

/**
* Key for localStorage, used at the beginning of the OAuth process to store
Expand Down
9 changes: 0 additions & 9 deletions packages/cozy-harvest-lib/src/helpers/oauth.spec.js
Expand Up @@ -147,15 +147,6 @@ describe('Oauth helper', () => {
expect(result).toBe(true)
})

it('should return false when no account is present in query string', () => {
window.location = {
search: 'state=70720eb0-6204-484d'
}

const result = handleOAuthResponse({ realtime })
expect(result).toBe(false)
})

it('should return false when no state is present in query string', () => {
window.location = {
search: 'account=bc2aca6566cf4a72afe6c615aa1e3d31'
Expand Down

0 comments on commit b1a6033

Please sign in to comment.