File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { AppContext } from "../../mod.ts" ;
22import { SlackOAuthResponse } from "../../utils/client.ts" ;
3+ import { decodeCustomBotState } from "../../utils/state-helpers.ts" ;
34
45export interface Props {
56 code : string ;
@@ -19,15 +20,6 @@ export interface Props {
1920 state ?: string ;
2021}
2122
22- function decodeState ( state : string ) {
23- try {
24- const decoded = atob ( decodeURIComponent ( state ) ) ;
25- return JSON . parse ( decoded ) ;
26- } catch {
27- return { } ;
28- }
29- }
30-
3123/**
3224 * @name SLACK_OAUTH_CALLBACK
3325 * @title Slack OAuth Callback
@@ -54,7 +46,7 @@ export default async function callback(
5446 let finalBotName = botName ;
5547
5648 if ( state ) {
57- const stateData = decodeState ( state ) ;
49+ const stateData = decodeCustomBotState ( state ) ;
5850 if ( stateData . isCustomBot ) {
5951 finalClientSecret = stateData . customClientSecret || clientSecret ;
6052 finalBotName = stateData . customBotName || botName ;
Original file line number Diff line number Diff line change 11import { OAUTH_URL_AUTH , SCOPES } from "../../utils/constants.ts" ;
22import { generateBotSelectionPage } from "../../utils/ui-templates/page-generator.ts" ;
3+ import { decodeState } from "../../utils/state-helpers.ts" ;
34
45export interface Props {
56 clientId : string ;
@@ -12,15 +13,6 @@ export interface Props {
1213 botName ?: string ;
1314}
1415
15- function decodeState ( state : string ) {
16- try {
17- const decoded = atob ( decodeURIComponent ( state ) ) ;
18- return JSON . parse ( decoded ) ;
19- } catch {
20- return { } ;
21- }
22- }
23-
2416export default function start ( props : Props , req : Request ) {
2517 const url = new URL ( req . url ) ;
2618 const useDecoChatBot = url . searchParams . get ( "useDecoChatBot" ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Decodes a base64-encoded state parameter from OAuth flow
3+ * @param state - The base64-encoded state string
4+ * @returns The decoded state object or empty object if decoding fails
5+ */
6+ export function decodeState ( state : string ) : Record < string , unknown > {
7+ try {
8+ const decoded = atob ( decodeURIComponent ( state ) ) ;
9+ return JSON . parse ( decoded ) ;
10+ } catch {
11+ return { } ;
12+ }
13+ }
14+
15+ /**
16+ * Type-safe version of decodeState for custom bot state
17+ */
18+ export interface CustomBotState {
19+ customClientSecret ?: string ;
20+ customBotName ?: string ;
21+ isCustomBot ?: boolean ;
22+ [ key : string ] : unknown ;
23+ }
24+
25+ export function decodeCustomBotState ( state : string ) : CustomBotState {
26+ return decodeState ( state ) as CustomBotState ;
27+ }
You can’t perform that action at this time.
0 commit comments