Skip to content

Commit

Permalink
fix: add support for okta oauth implicit flow in extension framework (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bryans99 authored Oct 6, 2021
1 parent d1f203c commit 6aaa0e5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions packages/extension-sdk/src/connect/extension_host_api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,49 @@ describe('extension_host_api tests', () => {
done()
})

it('sends oauth2 authenticate request with response_type id_token', async (done) => {
const hostApi = createHostApi({ lookerVersion: '7.9' })
const authEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth'
const authParameters = {
client_id: 'CLIENT_ID',
scope: 'SCOPE',
response_type: 'id_token',
}
await hostApi.oauth2Authenticate(authEndpoint, authParameters)
expect(sendAndReceiveSpy).toHaveBeenCalledWith('EXTENSION_API_REQUEST', {
payload: {
payload: {
authEndpoint,
authParameters,
httpMethod: 'POST',
},
type: 'oauth2_authenticate',
},
type: 'INVOKE_EXTERNAL_API',
})
done()
})

it('rejects oauth2 authenticate request with invalid response_type', async (done) => {
const hostApi = createHostApi({ lookerVersion: '7.9' })
const authEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth'
const authParameters = {
client_id: 'CLIENT_ID',
scope: 'SCOPE',
response_type: 'unknown_response_type',
}
try {
await hostApi.oauth2Authenticate(authEndpoint, authParameters)
throw new Error('How did I get here')
} catch (err: any) {
expect(err.message).toEqual(
'invalid response_type, must be token, id_token or code, unknown_response_type'
)
}
expect(sendAndReceiveSpy).not.toHaveBeenCalled()
done()
})

it('overrides http method for oauth2Authenticate', async (done) => {
const hostApi = createHostApi({ lookerVersion: '7.9' })
const authEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth'
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-sdk/src/connect/extension_host_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,10 @@ export class ExtensionHostApiImpl implements ExtensionHostApi {
}
if (
authParameters.response_type !== 'token' &&
authParameters.response_type !== 'id_token' &&
authParameters.response_type !== 'code'
) {
return `invalid response_type, must be token or code, ${authParameters.response_type}`
return `invalid response_type, must be token, id_token or code, ${authParameters.response_type}`
}
return undefined
}
Expand Down

0 comments on commit 6aaa0e5

Please sign in to comment.