changeset 7:f29dd482a25a

login work
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 24 Oct 2023 18:59:42 -0600
parents d59ae3e468f1
children 9534dd5eda89
files src/login2.red.luan
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
diff -r d59ae3e468f1 -r f29dd482a25a src/login2.red.luan
--- a/src/login2.red.luan	Mon Oct 23 21:09:05 2023 -0600
+++ b/src/login2.red.luan	Tue Oct 24 18:59:42 2023 -0600
@@ -1,6 +1,8 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local stringify = Luan.stringify or error()
+local Parsers = require "luan:Parsers.luan"
+local json_parse = Parsers.json_parse or error()
 local Io = require "luan:Io.luan"
 local uri = Io.uri or error()
 local Http = require "luan:http/Http.luan"
@@ -21,7 +23,7 @@
 	local options = {
 		method = "POST"
 		headers = {
-			["Content-Type"] = "application/x-www-form-urlencoded"
+			["User-Agent"] = "fuck you"  -- for retarded Cloudflare
 		}
 		authorization = {
 			username = config.discord.client_id
@@ -34,7 +36,20 @@
 			redirect_uri = discord_redirect_uri()
 		}
 	}
-	logger.info(stringify(options))
+	-- logger.info(stringify(options))
+	local result = uri(url,options).read_text()
+	-- logger.info(result)
+	result = json_parse(result)
+	local access_token = result.access_token or error()
+	logger.info("access_token = "..access_token)
+
+	local url = "https://discord.com/api/users/@me"
+	local options = {
+		headers = {
+			["User-Agent"] = "fuck you"  -- for retarded Cloudflare
+			Authorization = "Bearer "..access_token
+		}
+	}
 	local result = uri(url,options).read_text()
 	logger.info(result)