@@ -85,35 +85,74 @@ function doGet(request: DoGet): HtmlOutput {
8585 template . reInstallUrl = handler . reInstallUrl ;
8686 } else {
8787 template = HtmlService . createTemplate (
88- `Reinstallation is complete.<br /><a href="<?= requestUrl ?>" target="_parent">refresh</a>.`
88+ "Reinstallation is complete.<br />" +
89+ '<a href="javascript:void(0)" id="refresh-link">refresh</a>.' +
90+ "<script>" +
91+ ' var requestUrl = "<?!= requestUrl ?>";' +
92+ ' document.getElementById("refresh-link").onclick = function(e) {' +
93+ " e.preventDefault();" +
94+ " window.top.location.href = requestUrl;" +
95+ " };" +
96+ "</script>"
8997 ) ;
9098 template . requestUrl = ScriptApp . getService ( ) . getUrl ( ) ;
9199 }
92- return HtmlService . createHtmlOutput ( template . evaluate ( ) ) . setTitle ( "" ) ;
100+
101+ return template
102+ . evaluate ( )
103+ . setTitle ( "Reinstallation Complete" )
104+ . setXFrameOptionsMode ( HtmlService . XFrameOptionsMode . ALLOWALL ) ;
93105 }
94106
95107 if ( handler . verifyAccessToken ( ) ) {
96108 const template = HtmlService . createTemplate (
97109 "OK!<br />" +
98- '<a href="<?!= reInstallUrl ?>" target="_parent" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px"><svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Reinstall to Slack</a>'
110+ '<a href="javascript:void(0)" id="reinstall-btn" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px">' +
111+ '<svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Reinstall to Slack</a>' +
112+ "<script>" +
113+ ' var reInstallUrl = "<?!= reInstallUrl ?>";' +
114+ ' document.getElementById("reinstall-btn").onclick = function(e) {' +
115+ " e.preventDefault();" +
116+ ' window.open(reInstallUrl, "_blank");' +
117+ " };" +
118+ "</script>"
99119 ) ;
120+
100121 template . reInstallUrl = handler . requestURL + "?reinstall=true" ;
101- return HtmlService . createHtmlOutput ( template . evaluate ( ) ) . setTitle (
102- "Installation on Slack is complete"
103- ) ;
122+
123+ return template
124+ . evaluate ( )
125+ . setTitle ( "Installation on Slack is complete" )
126+ . setXFrameOptionsMode ( HtmlService . XFrameOptionsMode . ALLOWALL ) ;
104127 }
105128 if ( request . parameter . hasOwnProperty ( "token" ) ) {
106129 return configuration ( request . parameter ) ;
107130 } else {
108131 const template = HtmlService . createTemplate (
109- '<a href="https://api.slack.com/authentication/config-tokens#creating" target="_blank">Create configuration token</a><br />' +
110- '<form action="<?!= requestURL ?>" method="get" target="_parent"><p>Configuration Tokens(Refresh Token):<input type="password" name="token" value="<?!= refreshToken ?>"></p><input type="submit" name="" value="Create App"></form>'
132+ "<div>" +
133+ '<a href="https://api.slack.com/authentication/config-tokens#creating" target="_blank">Create configuration token</a><br /><br />' +
134+ "Configuration Tokens(Refresh Token):<br />" +
135+ '<input type="password" id="token" value="<?!= refreshToken ?>"><br /><br />' +
136+ '<input type="button" value="Create App" onclick="redirectToApp()">' +
137+ "</div>" +
138+ "<script>" +
139+ "function redirectToApp() {" +
140+ ' const token = document.getElementById("token").value;' +
141+ ' const baseURL = "<?!= requestURL ?>";' +
142+ ' const url = baseURL + (baseURL.indexOf("?") === -1 ? "?" : "&") + "token=" + encodeURIComponent(token);' +
143+ " " +
144+ " window.top.location.href = url;" +
145+ "}" +
146+ "</script>"
111147 ) ;
148+
112149 template . requestURL = handler . requestURL ;
113150 template . refreshToken = new SlackConfigurator ( ) . refresh_token ;
114- return HtmlService . createHtmlOutput ( template . evaluate ( ) ) . setTitle (
115- "Start Slack application configuration."
116- ) ;
151+
152+ return template
153+ . evaluate ( )
154+ . setTitle ( "Start Slack application configuration." )
155+ . setXFrameOptionsMode ( HtmlService . XFrameOptionsMode . ALLOWALL ) ;
117156 }
118157}
119158
@@ -136,13 +175,23 @@ function configuration(data: { [key: string]: string }): HtmlOutput {
136175 ) ;
137176
138177 const template = HtmlService . createTemplate (
139- '<a href="<?!= installUrl ?>" target="_parent" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px"><svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Add to Slack</a>'
178+ '<a href="#" id="slack-btn" target="_blank" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px">' +
179+ '<svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Add to Slack</a>' +
180+ "<script>" +
181+ ' var installUrl = "<?!= installUrl ?>";' +
182+ ' var btn = document.getElementById("slack-btn");' +
183+ " btn.onclick = function(e) {" +
184+ " e.preventDefault();" +
185+ ' window.open(installUrl, "_blank");' +
186+ " };" +
187+ "</script>"
140188 ) ;
141189 template . installUrl = oAuth2Handler . installUrl ;
142190
143- return HtmlService . createHtmlOutput ( template . evaluate ( ) ) . setTitle (
144- "Slack application configuration is complete."
145- ) ;
191+ return template
192+ . evaluate ( )
193+ . setSandboxMode ( HtmlService . SandboxMode . IFRAME )
194+ . setTitle ( "Slack application configuration is complete." ) ;
146195}
147196
148197function createAppsManifest ( redirectUrls : string [ ] = [ ] , requestUrl = "" ) : AppsManifest {
@@ -1208,4 +1257,12 @@ function pickUser(users: string[], times: number) {
12081257 return `<@${ user } >` ;
12091258}
12101259
1211- export { executeSlashCommand , changeOrder , FormValue , doGet , doPost , jobEventHandler } ;
1260+ export {
1261+ executeSlashCommand ,
1262+ changeOrder ,
1263+ FormValue ,
1264+ doGet ,
1265+ doPost ,
1266+ jobEventHandler ,
1267+ handleCallback ,
1268+ } ;
0 commit comments