Skip to content

Commit 10b0f2e

Browse files
committed
send idToken when requested
1 parent 29987e5 commit 10b0f2e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

components/simple-transcription/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,31 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
876876
this.#postToTool(this.#buildTPENContext(), targetWindow)
877877
}
878878

879+
#sendIdTokenToTool(targetWindow = this.#activeToolIframe?.contentWindow) {
880+
const idToken = TPEN.getAuthorization()
881+
882+
if (!idToken) {
883+
TPEN.login()
884+
return
885+
}
886+
887+
const tool = this.getToolByName(this.state.activeTool)
888+
const toolLabel = tool?.label ?? tool?.custom?.tagName ?? 'Tool'
889+
890+
this.#postToTool(
891+
{
892+
type: 'TPEN_ID_TOKEN',
893+
idToken
894+
},
895+
targetWindow
896+
)
897+
898+
TPEN.eventDispatcher.dispatch('tpen-toast', {
899+
message: `Authorized ${toolLabel} to act on your behalf`,
900+
status: 'info'
901+
})
902+
}
903+
879904
loadRightPaneContent() {
880905
const rightPane = this.shadowRoot.querySelector('.tools')
881906
let tool = this.getToolByName(this.state.activeTool)
@@ -1017,6 +1042,11 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
10171042
this.#sendTPENContextToTool(event.source)
10181043
return
10191044
}
1045+
1046+
if (event.data?.type === 'REQUEST_ID_TOKEN' || event.data?.type === 'REQUEST_TPEN_ID_TOKEN') {
1047+
this.#sendIdTokenToTool(event.source)
1048+
return
1049+
}
10201050

10211051
// Handle incoming messages from tools
10221052
const lineId = event.data?.lineId ?? event.data?.lineid ?? event.data?.annotation // handle different casing and properties

0 commit comments

Comments
 (0)