@@ -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{
4654bool 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
6876bool 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),
0 commit comments