-
Notifications
You must be signed in to change notification settings - Fork 52
wip: demo that uses Looker as an OAUTH provider for private embed #218
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -525,6 +525,52 @@ const initializeContentControls = () => { | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
async function oauth_login() { | ||||||||||||||||||
const base_url = 'https://self-signed.looker.com:9999/auth' | ||||||||||||||||||
const code_verifier = secure_random(32) | ||||||||||||||||||
const code_challenge = await sha256_hash(code_verifier) | ||||||||||||||||||
const params = { | ||||||||||||||||||
response_type: 'code', | ||||||||||||||||||
client_id: 'embed-server', | ||||||||||||||||||
redirect_uri: `${location.origin}`, | ||||||||||||||||||
scope: 'cors_api', | ||||||||||||||||||
state: '1235813', | ||||||||||||||||||
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. The Could you consider implementing a mechanism to:
Using a hardcoded As this is a WIP, the suggestion below is a minimal marker. A full implementation would involve more logic.
Suggested change
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. something like "rubber baby buggy bumpers"? |
||||||||||||||||||
code_challenge_method: 'S256', | ||||||||||||||||||
code_challenge: code_challenge, | ||||||||||||||||||
} | ||||||||||||||||||
const url = `${base_url}?${new URLSearchParams(params).toString()}` | ||||||||||||||||||
document.location.assign(url) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
function array_to_hex(array: any) { | ||||||||||||||||||
return Array.from(array) | ||||||||||||||||||
.map((b: any) => b.toString(16).padStart(2, '0')) | ||||||||||||||||||
.join('') | ||||||||||||||||||
Comment on lines
+545
to
+548
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. The Considering its usage with
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
function secure_random(byte_count: any) { | ||||||||||||||||||
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. |
||||||||||||||||||
const array = new Uint8Array(byte_count) | ||||||||||||||||||
crypto.getRandomValues(array) | ||||||||||||||||||
return array_to_hex(array) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
async function sha256_hash(message: any) { | ||||||||||||||||||
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. The
Suggested change
|
||||||||||||||||||
const msgUint8 = new TextEncoder().encode(message) | ||||||||||||||||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8) | ||||||||||||||||||
const hashArray = Array.from(new Uint8Array(hashBuffer)) | ||||||||||||||||||
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('') | ||||||||||||||||||
return hashHex | ||||||||||||||||||
Comment on lines
+560
to
+562
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. The logic here to convert the hash buffer to a hex string seems to duplicate the functionality of the Could we reuse
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
const initializeLoginControl = () => { | ||||||||||||||||||
const b = document.getElementById('oauth-login') | ||||||||||||||||||
if (b) { | ||||||||||||||||||
b.addEventListener('click', () => { | ||||||||||||||||||
oauth_login() | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Initialize controls. | ||||||||||||||||||
*/ | ||||||||||||||||||
|
@@ -535,6 +581,7 @@ const initializeControls = () => { | |||||||||||||||||
initializeUseDynamicHeightsCheckbox() | ||||||||||||||||||
initializeTabs() | ||||||||||||||||||
initializeContentControls() | ||||||||||||||||||
initializeLoginControl() | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
|
@@ -649,7 +696,7 @@ const createEmbed = (runtimeConfig: RuntimeConfig, sdk: ILookerEmbedSDK) => { | |||||||||||||||||
// Applicable to private embed only. If the user is not logged in, | ||||||||||||||||||
// the Looker login page will be displayed. Note that this will not | ||||||||||||||||||
// in Looker core. | ||||||||||||||||||
.withAllowLoginScreen() | ||||||||||||||||||
// .withAllowLoginScreen() | ||||||||||||||||||
// Append to the #dashboard element | ||||||||||||||||||
.appendTo('#embed-container') | ||||||||||||||||||
.on('page:changed', (event: PageChangedEvent) => { | ||||||||||||||||||
|
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.
The
base_url
(line 529),client_id
(line 534), andscope
(line 536) are hardcoded here.While this might be acceptable for an initial WIP demo, would it be beneficial to make these configurable? For instance, they could be sourced from
demo_config.ts
or environment variables, similar to how other configurations are handled indemo_config.ts
. This would make the demo more adaptable and easier to configure for different environments or use cases.