From cd48090768b172d29c39b91efb1b611a2cc764ef Mon Sep 17 00:00:00 2001 From: LucasMZ <55422065+LucasMZReal@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:18:14 -0300 Subject: [PATCH 1/3] Add type checking, fix spelling, improve errors... --- AuthAPI.lua | 19 -------------- src/init.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 19 deletions(-) delete mode 100644 AuthAPI.lua create mode 100644 src/init.lua diff --git a/AuthAPI.lua b/AuthAPI.lua deleted file mode 100644 index c94aa8e..0000000 --- a/AuthAPI.lua +++ /dev/null @@ -1,19 +0,0 @@ -local HttpService = game:GetService("HttpService") -local authAPI = {} - -function authAPI.CheckPin(code, secret) - local requesturl = "https://www.authenticatorapi.com/Validate.aspx?Pin="..code.."&SecretCode="..secret - local check = HttpService:GetAsync(requesturl) - if check == "True" then - return true - else - return false - end -end - -function authAPI.GetQRCode(secret, AppName, AppInfo) - local requesturl = "https://www.authenticatorapi.com/pair.aspx?AppName="..AppName.."&AppInfo="..AppInfo.."&SecretCode="..secret - return requesturl -end - -return authAPI diff --git a/src/init.lua b/src/init.lua new file mode 100644 index 0000000..9ec78c6 --- /dev/null +++ b/src/init.lua @@ -0,0 +1,72 @@ +local HttpService = game:GetService("HttpService") +local AuthAPI = {} + +local AUTHENTICATION_URL = "https://www.authenticatorapi.com/Validate.aspx?Pin=%s&SecretCode=%s" +local QRCODE_URL = "https://www.authenticatorapi.com/pair.aspx?AppName=%s&AppInfo=%s&SecretCode=%s" + +function AuthAPI.CheckPinAsync( + code: string | number, + secret: string +): boolean + + assert( + tonumber(code) ~= nil, + "Code must be number" + ) + + assert( + typeof(secret) == 'string', + "Secret must be string" + ) + + local requestUrl = string.format( + AUTHENTICATION_URL, + code, secret + ) + + local wasRequestSuccessful, result = pcall( + HttpService.GetAsync, HttpService, + requestUrl + ) + + if wasRequestSuccessful then + if result == "True" then + return true + elseif result == "False" then + return false + else + error("Invalid result returned\n Result: ".. result) + end + else + error("Remote request failed\n Error: ".. result) + end +end + +function AuthAPI.GetQRCodeURL( + appName: string, + appInfo: string, + secret: string +): string + + assert( + typeof(appName) == 'string', + "AppName must be string" + ) + + assert( + typeof(appInfo) == 'string', + "AppInfo must be string" + ) + + assert( + typeof(secret) == 'string', + "Secret must be string" + ) + + return string.format( + QRCODE_URL, + appName, appInfo, secret + ) +end + +return AuthAPI \ No newline at end of file From 0bcc07a93431a11cc10f55e1c04b8c30ba11a2f6 Mon Sep 17 00:00:00 2001 From: LucasMZ <55422065+LucasMZReal@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:36:39 -0300 Subject: [PATCH 2/3] Separate Services from module declaration --- src/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.lua b/src/init.lua index 9ec78c6..e982d5a 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1,4 +1,5 @@ local HttpService = game:GetService("HttpService") + local AuthAPI = {} local AUTHENTICATION_URL = "https://www.authenticatorapi.com/Validate.aspx?Pin=%s&SecretCode=%s" From 2fe7c8a063d43f84c1724904ad8848813e1396fe Mon Sep 17 00:00:00 2001 From: LucasMZ <55422065+LucasMZReal@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:40:13 -0300 Subject: [PATCH 3/3] Add author credits --- src/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/init.lua b/src/init.lua index e982d5a..fe0af5a 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1,3 +1,9 @@ +--[[ + Authors: + deprecatedbrain (co_existance) (12/11/2021), -- Creating the original file + LucasMZ (12/12/2021), -- Type annotation & checking, error improvements... +]] + local HttpService = game:GetService("HttpService") local AuthAPI = {}