|
1 | 1 | # Argon |
2 | 2 |
|
3 | | -todo make this an api mod? |
| 3 | +API for authenticating Geometry Dash accounts. Made by creators of Globed, and is completely free and open-source, including the [server](https://github.com/GlobedGD/argon-server). Can be selfhosted (for example for a GDPS), but we provide our server at https://argon.globed.dev and this library uses it by default. |
| 4 | + |
| 5 | +Benefits compared to some of the other auth APIs (Globed, DashAuth, GDAuth): |
| 6 | + |
| 7 | +* Does not send your GJP or password to any 3rd party server |
| 8 | +* Tokens are stored globally, meaning that authentication is done only once even if the user has multiple mods installed that use Argon |
| 9 | +* Smooth UX for switching accounts (will not try to use or overwrite the token of the other account) |
| 10 | +* Our official instance is whitelisted by RobTop, which means authentication is faster and more reliable against IP blocks |
| 11 | +* Challenges don't entirely rely on the IP address, but are still secured in other ways, preventing errors if the user has a weird ISP |
| 12 | +* Ability to retrieve user's username without making requests to the GD server (with just their token) |
| 13 | +* (TODO, not done yet) Automatic troubleshooter for figuring out the cause of auth issues (for example invalid session or too many sent messages) |
| 14 | + |
| 15 | +## Usage (client-side) |
| 16 | + |
| 17 | +First, add Argon to the `CMakeLists.txt` of your mod: |
| 18 | + |
| 19 | +```cmake |
| 20 | +CPMAddPackage("gh:GlobedGD/argon@1.0.0") |
| 21 | +target_link_libraries(${PROJECT_NAME} argon) |
| 22 | +``` |
| 23 | + |
| 24 | +Complete example of how to perform authentication: |
| 25 | + |
| 26 | +```cpp |
| 27 | +#include <argon/argon.hpp> |
| 28 | +#include <Geode/Geode.hpp> |
| 29 | + |
| 30 | +using namespace geode::prelude; |
| 31 | + |
| 32 | + |
| 33 | +$on_mod(Loaded) { |
| 34 | + // Do note the authentication is asynchronous, do NOT pass anything in the lambda captures to these callbacks, |
| 35 | + // unless you are certain that object will continue to exist. |
| 36 | + |
| 37 | + auto res = argon::startAuth([](Result<std::string> res) { |
| 38 | + // This callback is called on the main thread once the authentication completes. |
| 39 | + // Note that if the authtoken is already stored in user's cache, |
| 40 | + // this function will be called immediately! |
| 41 | + |
| 42 | + if (!res) { |
| 43 | + log::warn("Auth failed: {}", res.unwrapErr()); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + auto token = std::move(res).unwrap(); |
| 48 | + |
| 49 | + // Now you have an authtoken that you can use to verify the user! |
| 50 | + // Send this to your mod's server, which should verify it with the Argon server to ensure it is valid. |
| 51 | + |
| 52 | + log::debug("Token: {}", token); |
| 53 | + }, [](argon::AuthProgress progress) { |
| 54 | + // This callback is called whenever the client moves to the next step of authentication |
| 55 | + |
| 56 | + log::info("Auth progress: {}", argon::authProgressToString(progress)); |
| 57 | + }); |
| 58 | + |
| 59 | + if (!res) { |
| 60 | + log::warn("Failed to start auth attempt: {}", res.unwrapErr()); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | +
|
| 65 | +If running into token validation issues, tokens can be cleared to attempt authentication again: |
| 66 | +
|
| 67 | +```cpp |
| 68 | +argon::clearToken(); |
| 69 | +``` |
| 70 | + |
| 71 | +If using a custom server, the URL can be set like so: |
| 72 | + |
| 73 | +```cpp |
| 74 | +// this unwrap is safe as long as *no* auth requests are currently running |
| 75 | +argon::setServerUrl("http://localhost:4341").unwrap(); |
| 76 | +``` |
| 77 | +
|
| 78 | +Few more functions are provided for managing tokens and for ensuring thread safety, you can find out about the rest of the functionality by reading the docstrings in `include/argon/argon.hpp` header. |
| 79 | +
|
| 80 | +## Usage (server-side) |
| 81 | +
|
| 82 | +After the user has generated an authtoken, they should send it to your server, which in turn will send the token to the Argon server for validation. Server-side API has its own [documentation](https://github.com/GlobedGD/argon-server/blob/main/docs/server-api.md) which describes in detail how to use it. |
0 commit comments