Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for okta oauth implicit flow in extension framework #847

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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