-
Notifications
You must be signed in to change notification settings - Fork 192
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: oauth support in APIX when embedded in another app #1198
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0d3319f
fix: oauth paths for API Explorer
jkaster a318372
wip: some debug statements
jkaster b0bd49b
fixing OAuth config
jkaster 2d4b6ab
fix runit config test
jkaster c866de1
fix runit config test
jkaster ff8bcba
fix runit config test
jkaster d56b18b
WIP OAuthScene fixes
jkaster 4e8d0d2
WIP OAuthScene fixes
jkaster 8c2aa41
WIP OAuthScene fixes
jkaster 7c2c604
WIP OAuthScene fixes
jkaster ad84917
WIP OAuthScene fixes
jkaster d164c02
WIP OAuthScene fixes
jkaster 2f00e94
WIP OAuthScene fixes
jkaster 127f0f7
WIP OAuthScene tweaks
jkaster 87362c8
WIP OAuthScene tweaks
jkaster 2a0583e
WIP OAuthScene tweaks
jkaster 3018fa3
fix broken tests
jkaster 2c5796c
clean up debug statements
jkaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -42,9 +42,10 @@ import { | |
Tooltip, | ||
} from '@looker/components' | ||
import { CodeCopy } from '@looker/code-editor' | ||
import { getEnvAdaptor } from '@looker/extension-utils' | ||
import { appPath, getEnvAdaptor } from '@looker/extension-utils' | ||
import type { ILookerVersions } from '@looker/sdk-codegen' | ||
|
||
import { useLocation } from 'react-router-dom' | ||
import type { RunItValues } from '../..' | ||
import { CollapserCard, RunItHeading, DarkSpan, readyToLogin } from '../..' | ||
import { | ||
|
@@ -76,7 +77,7 @@ interface ConfigFormProps { | |
requestContent: RunItValues | ||
/** Title for the config form */ | ||
title?: string | ||
/** A set state callback which if present allows for editing, setting or clearing OAuth configuration parameters */ | ||
/** A set state callback which allows for editing, setting or clearing OAuth configuration parameters if present */ | ||
setHasConfig?: Dispatch<boolean> | ||
} | ||
|
||
|
@@ -85,14 +86,17 @@ export const ConfigForm: FC<ConfigFormProps> = ({ | |
requestContent, | ||
setHasConfig, | ||
}) => { | ||
const location = useLocation() | ||
const redirect_uri = appPath(location, '/oauth') | ||
const client_id = 'looker.api-explorer' // TODO make this configurable | ||
const BASE_URL = 'baseUrl' | ||
const WEB_URL = 'webUrl' | ||
const FETCH_INTENT = 'fetchIntent' | ||
const FETCH_RESULT = 'fetchResult' | ||
const CRITICAL: MessageBarIntent = 'critical' | ||
const appConfig = `{ | ||
"client_guid": "looker.api-explorer", | ||
"redirect_uri": "${(window as any).location.origin}/oauth", | ||
const appConfig = `// client_guid=${client_id} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like Prism can correctly highlight this comment, so that's a bonus |
||
{ | ||
"redirect_uri": "${redirect_uri}", | ||
"display_name": "CORS API Explorer", | ||
"description": "Looker API Explorer using CORS", | ||
"enabled": true | ||
|
@@ -163,24 +167,37 @@ export const ConfigForm: FC<ConfigFormProps> = ({ | |
updateMessage(CRITICAL, message) | ||
} | ||
|
||
const saveConfig = (baseUrl: string, webUrl: string) => { | ||
const data = { | ||
base_url: baseUrl, | ||
looker_url: webUrl, | ||
client_id, | ||
redirect_uri, | ||
} | ||
updateFields({ | ||
[BASE_URL]: baseUrl, | ||
[WEB_URL]: webUrl, | ||
}) | ||
// TODO: replace when redux is introduced to run it | ||
localStorage.setItem(RunItConfigKey, JSON.stringify(data)) | ||
if (setHasConfig) setHasConfig(true) | ||
setSaved(data) | ||
updateMessage(POSITIVE, `Saved ${webUrl} as OAuth server`) | ||
} | ||
|
||
const updateForm = async (_e: BaseSyntheticEvent, save: boolean) => { | ||
updateMessage('inform', '') | ||
const versionsUrl = `${fields.baseUrl}/versions` | ||
try { | ||
const { web_server_url: webUrl, api_server_url: baseUrl } = | ||
(await getVersions(versionsUrl)) as ILookerVersions | ||
updateMessage(POSITIVE, 'Configuration is valid') | ||
updateFields({ | ||
[BASE_URL]: baseUrl, | ||
[WEB_URL]: webUrl, | ||
}) | ||
updateMessage(POSITIVE, 'Configuration is valid') | ||
if (save) { | ||
const data = { base_url: baseUrl, looker_url: webUrl } | ||
// TODO: replace when redux is introduced to run it | ||
localStorage.setItem(RunItConfigKey, JSON.stringify(data)) | ||
if (setHasConfig) setHasConfig(true) | ||
setSaved(data) | ||
updateMessage(POSITIVE, `Saved ${webUrl} as OAuth server`) | ||
saveConfig(baseUrl, webUrl) | ||
} | ||
} catch (e: any) { | ||
fetchError(e.message) | ||
|
@@ -299,17 +316,33 @@ export const ConfigForm: FC<ConfigFormProps> = ({ | |
/> | ||
</Fieldset> | ||
</Form> | ||
<Paragraph fontSize="small"> | ||
The following configuration can be used to create a{' '} | ||
<Link | ||
href="https://github.com/looker-open-source/sdk-codegen/blob/main/docs/cors.md#reference-implementation" | ||
target="_blank" | ||
> | ||
Looker OAuth client | ||
</Link> | ||
. | ||
</Paragraph> | ||
<CodeCopy key="appConfig" language="json" code={appConfig} /> | ||
{!!fields.webUrl && ( | ||
<> | ||
<Paragraph fontSize="small"> | ||
On {fields.webUrl}, enable API Explorer as a{' '} | ||
<Link | ||
href="https://github.com/looker-open-source/sdk-codegen/blob/main/docs/cors.md#reference-implementation" | ||
target="_blank" | ||
> | ||
Looker OAuth client | ||
</Link>{' '} | ||
by adding "{(window as any).location.origin}" to the{' '} | ||
<Link href={`${fields.webUrl}/admin/embed`} target="_blank"> | ||
Embedded Domain Allowlist | ||
</Link> | ||
. If API Explorer is also installed, the configuration below can | ||
be used to{' '} | ||
<Link | ||
href={`${fields.webUrl}/extensions/marketplace_extension_api_explorer::api-explorer/4.0/methods/Auth/register_oauth_client_app`} | ||
target="_blank" | ||
> | ||
register this API Explorer instance | ||
</Link>{' '} | ||
as an OAuth client. | ||
</Paragraph> | ||
<CodeCopy key="appConfig" language="json" code={appConfig} /> | ||
</> | ||
)} | ||
<Space> | ||
<Tooltip content="Clear the configuration values"> | ||
<ButtonTransparent | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙀