Skip to content

Commit 1a3e05f

Browse files
committed
v2.0.1
- Multiple tries at initial oauth request - Use correct version number in request headers
1 parent 307237b commit 1a3e05f

7 files changed

Lines changed: 41 additions & 9 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
.vscode/
3+
*.elf
4+
*.dol

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(CMAKE_ASM_FLAGS "-x assembler-with-cpp")
1515
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-function -O2 ${CMAKE_CXX_FLAGS} ${MACHDEP}")
1616
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-function -O2 ${CMAKE_CXX_FLAGS} ${MACHDEP} -fdiagnostics-color")
1717
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
18+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/apps/wiilink-account-linker")
1819

1920
include_directories(${LIBOGCDIR}/include)
2021
include_directories(${DEVKITPRO}/portlibs/wii/include)
@@ -38,5 +39,5 @@ add_executable(WiiLinkAccountLinker
3839
)
3940

4041
target_link_libraries(WiiLinkAccountLinker
41-
PRIVATE curl wiisocket mbedtls mbedcrypto mbedx509 wiiuse bte asnd ogc qrencode z bz2
42+
PRIVATE curl wiisocket mbedtls mbedcrypto mbedx509 wiiuse bte asnd ogc z
4243
)
10.6 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<app version="1">
3+
<name>WiiLink Account Linker</name>
4+
<version>v2.0.1</version>
5+
<release_date>20251115000000</release_date>
6+
<coder>Sketch</coder>
7+
<short_description>Links your Wii to your WiiLink Account!</short_description>
8+
<long_description>
9+
</long_description>
10+
<ahb_access/>
11+
</app>

build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
mkdir -p build
4+
cd build
5+
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=../toolchain-powerpc.cmake -G Ninja ..
6+
ninja

oauth.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ bool OAuth::StartDeviceFlow() {
99
const std::string post_data = std::format("client_id={}&scope=openid+profile+email+goauthentik.io/api", CLIENT_ID);
1010

1111
std::vector<std::string> headers = {
12-
"User-Agent: WiiLink Account Linker v0.1",
12+
std::format("User-Agent: WiiLink Account Linker {}", version),
1313
"Content-Type: application/x-www-form-urlencoded"
1414
};
1515

16-
m_response = http_post(DEVICE_PATH, post_data, headers);
17-
if (m_response.status_code != 200 || m_response.curl_code != CURLE_OK) {
18-
// JSON will probably be empty. Return and display message.
19-
return false;
16+
for (int tries = 0; tries < 5; tries++) {
17+
// We do multiple tries here, as sometimes SSO returns 502 for whatever reason
18+
m_response = http_post(DEVICE_PATH, post_data, headers);
19+
20+
if (m_response.status_code == 200 && m_response.curl_code == CURLE_OK) {
21+
break;
22+
}
23+
24+
if (tries == 4) {
25+
// JSON will probably be empty. Return and display message.
26+
return false;
27+
}
2028
}
2129

2230
m_device_code = m_response.j["device_code"];
@@ -46,7 +54,7 @@ std::string OAuth::GetErrorMessage() const{
4654
bool OAuth::PollToken() {
4755
const std::string post_data = std::format("grant_type=urn:ietf:params:oauth:grant-type:device_code&client_id={}&device_code={}", CLIENT_ID, GetDeviceCode());
4856
std::vector<std::string> headers = {
49-
"User-Agent: WiiLink Account Linker v0.1",
57+
std::format("User-Agent: WiiLink Account Linker {}", version),
5058
"Content-Type: application/x-www-form-urlencoded"
5159
};
5260

@@ -67,7 +75,7 @@ bool OAuth::PollToken() {
6775

6876
bool OAuth::PerformLink(std::string_view wwfc_cert) {
6977
std::vector<std::string> headers = {
70-
"User-Agent: WiiLink Account Linker v0.1",
78+
std::format("User-Agent: WiiLink Account Linker {}", version),
7179
"Accept: application/json",
7280
"Content-Type: application/x-www-form-urlencoded",
7381
std::format("Authorization: {}", m_access_token),

utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <vector>
77
#include <iostream>
88

9+
const std::string version = "v2.0.1";
10+
911
struct File {
1012
void* data;
1113
size_t size;
@@ -23,7 +25,7 @@ inline void PrintHeader() {
2325
std::cout << std::endl;
2426
std::cout << std::endl;
2527
std::cout << "WiiLink Account Linker - (c) 2025 WiiLink" << std::endl;
26-
std::cout << "v2.0" << std::endl;
28+
std::cout << version << std::endl;
2729
std::cout << std::endl;
2830
}
2931

0 commit comments

Comments
 (0)