Prompt to add redirect URI in setup
This commit is contained in:
		
							parent
							
								
									cf756cb0af
								
							
						
					
					
						commit
						5dbd79cf39
					
				
					 1 changed files with 27 additions and 2 deletions
				
			
		|  | @ -148,10 +148,15 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}) | 		}) | ||||||
|  | 		bridgeOriginResponse.bridge_origin = bridgeOriginResponse.bridge_origin.replace(/\/+$/, "") // remove trailing slash
 | ||||||
| 
 | 
 | ||||||
| 		await server.close() | 		await server.close() | ||||||
| 
 | 
 | ||||||
| 		console.log("What is your Discord bot token?") | 		console.log("What is your Discord bot token?") | ||||||
|  | 		/** @type {SnowTransfer} */ // @ts-ignore
 | ||||||
|  | 		let snow = null | ||||||
|  | 		/** @type {{id: string, redirect_uris: string[]}} */ // @ts-ignore
 | ||||||
|  | 		let client = null | ||||||
| 		/** @type {{discord_token: string}} */ | 		/** @type {{discord_token: string}} */ | ||||||
| 		const discordTokenResponse = await prompt({ | 		const discordTokenResponse = await prompt({ | ||||||
| 			type: "input", | 			type: "input", | ||||||
|  | @ -160,8 +165,8 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { | ||||||
| 			validate: async token => { | 			validate: async token => { | ||||||
| 				process.stdout.write(magenta(" checking, please wait...")) | 				process.stdout.write(magenta(" checking, please wait...")) | ||||||
| 				try { | 				try { | ||||||
| 					const snow = new SnowTransfer(token) | 					snow = new SnowTransfer(token) | ||||||
| 					await snow.user.getSelf() | 					client = await snow.requestHandler.request(`/applications/@me`, {}, "get") | ||||||
| 					return true | 					return true | ||||||
| 				} catch (e) { | 				} catch (e) { | ||||||
| 					return e.message | 					return e.message | ||||||
|  | @ -170,6 +175,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
| 		console.log("What is your Discord client secret?") | 		console.log("What is your Discord client secret?") | ||||||
|  | 		console.log(`You can find it on the application page: https://discord.com/developers/applications/${client.id}/oauth2`) | ||||||
| 		/** @type {{discord_client_secret: string}} */ | 		/** @type {{discord_client_secret: string}} */ | ||||||
| 		const clientSecretResponse = await prompt({ | 		const clientSecretResponse = await prompt({ | ||||||
| 			type: "input", | 			type: "input", | ||||||
|  | @ -177,6 +183,25 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { | ||||||
| 			message: "Client secret" | 			message: "Client secret" | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
|  | 		const expectedUri = `${bridgeOriginResponse.bridge_origin}/oauth` | ||||||
|  | 		if (!client.redirect_uris.includes(expectedUri)) { | ||||||
|  | 			console.log(`On the same application page, go to the Redirects section, and add this URI: ${cyan(expectedUri)}`) | ||||||
|  | 			await prompt({ | ||||||
|  | 				type: "invisible", | ||||||
|  | 				name: "redirect_uri", | ||||||
|  | 				message: "Press Enter when you've added it", | ||||||
|  | 				validate: async token => { | ||||||
|  | 					process.stdout.write(magenta("checking, please wait...")) | ||||||
|  | 					client = await snow.requestHandler.request(`/applications/@me`, {}, "get") | ||||||
|  | 					if (client.redirect_uris.includes(expectedUri)) { | ||||||
|  | 						return true | ||||||
|  | 					} else { | ||||||
|  | 						return "Redirect URI has not been added yet" | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			}) | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		const template = getTemplateRegistration(serverNameResponse.server_name) | 		const template = getTemplateRegistration(serverNameResponse.server_name) | ||||||
| 		reg = { | 		reg = { | ||||||
| 			...template, | 			...template, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue