Skip to content

Commit 5ba009c

Browse files
committed
2.207 yay
1 parent 5f3f383 commit 5ba009c

26 files changed

+717
-546
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ file(GLOB SOURCES
1515
src/ui/popups/*.cpp
1616
src/ui/admin/*.cpp
1717
src/ui/auth/*.cpp
18+
19+
src/gdauth/*.cpp # until fig ACCEPTS MY PR, for some reason hes inactive...
1820
)
1921

2022
# Set up the mod binary
@@ -28,7 +30,7 @@ endif()
2830

2931
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
3032

31-
#CPMAddPackage("gh:RoootTheFox/dashauth#main")
32-
#target_link_libraries(${PROJECT_NAME} DashAuth)
33+
CPMAddPackage("gh:FireMario211/dashauth#main")
34+
target_link_libraries(${PROJECT_NAME} DashAuth)
3335

3436
setup_geode_mod(${PROJECT_NAME})

about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Thank you to <cj>Midair</c> for the mod idea, <cy>Alphalaneous</c> for the extra
1616
- To upload, click on the <cy>My Objects</c> tab, and make sure that the object you want to upload is in your <co>custom objects</c> (C). Otherwise, you won't be able to <cy>upload an object</c>!
1717

1818
# Authentication Methods
19-
- <cp>DashAuth</c> is an authentication method that <cy>sends a message to a bot</c> to confirm the authenticity of your <cy>GD account</c>, similar to how mods like <cb>Globed</c> handles verifying your <cy>GD account</c>. Unfortunately, RobTop's servers <cr>IP banned my server</c>, meaning this method <cr>is not available</c>.
19+
- <cp>DashAuth</c> is an authentication method that <cy>sends a message to a bot</c> to confirm the authenticity of your <cy>GD account</c>, similar to how mods like <cb>Globed</c> handles verifying your <cy>GD account</c>. Thanks to <cp>rooot</c> for creating it!
2020
- <cg>GDAuth</c> is an authentication method made by <cg>fig</c> which <cy>sends your GJP</c> (session token for GD) to <cg>fig's server</c> to confirm the authenticity of your <cy>GD account</c>. You should only use this <cy>if you trust fig's server</c>, as this method is like sending your GD account to <cy>fig's server</c>.
2121
- <cy>Do Later</c> is what it says. This will close the menu and open up the <cy>Object Workshop</c>. Although do note that you <cy>will be limited</c> in what features you can use.
2222

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.4.1
2+
- Ported to Geode v4.0.0-beta.1 (2.207!)
3+
- Added DashAuth authentication option
14
# v1.4.0
25
- Allowed clicking on users profiles in comments (will only work for players that authenticated with Object Workshop before)
36
- Added \n for descriptions and comments

mod.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"geode": "3.9.0",
2+
"geode": "4.0.0-beta.1",
33
"gd": {
4-
"win": "2.206",
5-
"android": "2.206",
6-
"mac": "2.206",
7-
"ios": "2.206"
4+
"win": "2.2074",
5+
"android": "2.2074",
6+
"mac": "2.2074",
7+
"ios": "2.2074"
88
},
99
"id": "firee.object-workshop",
1010
"name": "Object Workshop",
11-
"version": "v1.4.0",
11+
"version": "v1.4.1",
1212
"developer": "Firee",
1313
"description": "Download, upload, or find custom objects made by other creators!",
1414
"resources": {
@@ -51,15 +51,17 @@
5151
"max": 50000
5252
}
5353
},
54-
"dependencies": [
54+
"dependentold": [
5555
{
5656
"id": "fig.authentication",
57-
"version": ">=v1.0.1",
58-
"importance": "required"
59-
},
57+
"version": ">=v1.0.2",
58+
"importance": "recommended"
59+
}
60+
],
61+
"dependencies": [
6062
{
6163
"id": "alphalaneous.editortab_api",
62-
"version": ">=v1.0.0",
64+
"version": ">=v1.0.6",
6365
"importance": "required"
6466
},
6567
{

server/src/controllers/user.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ interface GDAuth {
7070
expires_after: Date;
7171
};
7272

73+
interface DashAuth {
74+
success: boolean,
75+
message: string,
76+
data: {
77+
id: number,
78+
username: string,
79+
token: string,
80+
token_expiration: Date
81+
}
82+
};
83+
7384
uRouter.get("/testverify", query('token').notEmpty().isUUID(4), async (req: Request, res: Response) => {
7485
const result = validationResult(req);
7586
if (!result.isEmpty()) return res.status(400).json({ errors: result.array() })
@@ -261,6 +272,55 @@ uRouter.post('/gdauth',
261272
}
262273
);
263274

275+
uRouter.post('/dashauth',
276+
body('token').notEmpty(),
277+
async (req: Request, res: Response) => {
278+
const result = validationResult(req);
279+
if (!result.isEmpty()) return res.status(400).json({ errors: result.array() })
280+
const token = req.body.token as string;
281+
getCache().then(pool => {
282+
axios.post("https://dashend.firee.dev/api/v1/verify", {token}).then(axiosRes => {
283+
//axios.post("http://127.0.0.1:3001/api/v1/verify", {token}).then(axiosRes => {
284+
const dashAuthData = axiosRes.data as DashAuth;
285+
const data = dashAuthData.data;
286+
if (!process.env.PRODUCTION) {
287+
console.log("[DashAuth]", data);
288+
}
289+
if (axiosRes.data == "-1") return res.status(403).json({error: "Invalid token."});
290+
pool.query("INSERT INTO users (auth_method, account_id, name) VALUES ($1, $2, $3) ON CONFLICT (account_id) DO NOTHING RETURNING *;", ["dashauth", data.id, data.username]).then(async userResult => {
291+
let user = userResult.rows[0];
292+
if (!user) {
293+
const existingUserResult = await pool.query(
294+
`SELECT * FROM users WHERE account_id = $1;`,
295+
[data.id]
296+
);
297+
user = existingUserResult.rows[0];
298+
}
299+
if (!user) return res.status(500).json({ error: "Unable to retrieve or create user." });
300+
const authToken = generateAuthToken(user.account_id);
301+
const expiration = new Date(Date.now() + ((60 * 60 * 1000) * 24) * 14); // 2 weeks
302+
await pool.query(
303+
`INSERT INTO user_tokens (account_id, token, expiration)
304+
VALUES ($1, $2, $3);`,
305+
[user.account_id, authToken, expiration]
306+
);
307+
res.status(200).json({ token: authToken });
308+
}).catch(err => {
309+
console.error(err);
310+
res.status(500).json({ error: "Something went wrong when trying to create a user." })
311+
})
312+
313+
}).catch(e => {
314+
console.error(e);
315+
res.status(500).send({error: "Something went wrong when trying to communicate with DashEnd servers."})
316+
})
317+
}).catch(e => {
318+
console.error(e);
319+
res.sendStatus(500);
320+
});
321+
}
322+
);
323+
264324
uRouter.post('/custom',
265325
body('token').notEmpty().isString(),
266326
body('accountID').notEmpty().isString(),

src/config.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#pragma once
22
#define HOST_URL "https://ow.firee.dev"
33
//#define HOST_URL "http://localhost:3000"
4+
#define DASHEND_URL "https://dashend.firee.dev/api/v1"
5+
//#define DASHEND_URL "http://localhost:3001/api/v1"
46
#define USER_AGENT "ObjectWorkshop/1.4.0"
57

8+
#define DASHAUTH 1
9+
#define GDAUTH 1
10+
611
#define RESULT_LIMIT 9
712
#define MAX_ZOOM 10
813
#define MIN_ZOOM 0.01

src/gdauth/authentication.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// TODO: Remove after fig accepts my pr or updates to v4!
2+
3+
#include <Geode/Geode.hpp>
4+
#include <Geode/utils/web.hpp>
5+
6+
#include "authentication.hpp"
7+
8+
using namespace geode::prelude;
9+
using namespace authentication;
10+
11+
void AuthenticationManager::getAuthenticationToken(std::function<void(std::string)> onSuccess, std::function<void(std::string)> onFailure) {
12+
if (m_token != "-1") {
13+
return onSuccess(m_token);
14+
}
15+
16+
std::string url = "https://gd.figm.io/authentication/authenticate";
17+
web::WebRequest req = web::WebRequest();
18+
19+
req.bodyString(fmt::format("accountid={}&gjp={}", GJAccountManager::get()->m_accountID, GJAccountManager::get()->m_GJP2));
20+
auto task = req.post(url);
21+
22+
m_listener.bind([this, onSuccess, onFailure](web::WebTask::Event* e) {
23+
if (web::WebResponse* value = e->getValue()) {
24+
if (value->string().unwrapOr("-1") == "-1" || value->json().isErr()) {
25+
return onFailure("Authentication Failed");
26+
}
27+
28+
m_token = value->json().unwrap().get<std::string>("sessionID").unwrapOr("");
29+
onSuccess(m_token);
30+
} else if (web::WebProgress* progress = e->getProgress()) {
31+
// The request is still in progress...
32+
} else if (e->isCancelled()) {
33+
onFailure("The request was cancelled");
34+
}
35+
});
36+
37+
m_listener.setFilter(task);
38+
}

src/gdauth/authentication.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// TODO: Remove after fig accepts my pr or updates to v4!
2+
3+
#pragma once
4+
5+
#include <Geode/Geode.hpp>
6+
#include <Geode/utils/web.hpp>
7+
8+
using namespace geode::prelude;
9+
10+
namespace authentication {
11+
class AuthenticationManager {
12+
private:
13+
std::string m_token = "-1";
14+
EventListener<web::WebTask> m_listener;
15+
16+
public:
17+
static AuthenticationManager* get() {
18+
static AuthenticationManager* instance = new AuthenticationManager;
19+
return instance;
20+
}
21+
22+
void getAuthenticationToken(std::function<void(std::string)> callback, std::function<void(std::string)> onFailure = [](std::string){});
23+
};
24+
}

0 commit comments

Comments
 (0)