Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add twitch_id field to authenticate response #73

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion c_library/gamelink_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ MGL_RequestId MuxyGameLink_AuthenticateWithGameIDAndRefreshToken(MuxyGameLink Ga
MGL_RequestId res = SDK->AuthenticateWithGameIDAndRefreshToken(ClientId, GameId, RefreshToken,
C_CALLBACK(Callback, UserData, AuthenticateResponse));
return res;
}
}
else
{
MGL_RequestId res = SDK->AuthenticateWithRefreshToken(ClientId, RefreshToken,
Expand Down Expand Up @@ -185,6 +185,18 @@ const char* MuxyGameLink_Schema_User_GetTwitchName(MGL_Schema_User User)
return "";
}


const char* MuxyGameLink_Schema_User_GetTwitchID(MGL_Schema_User User)
{
const gamelink::schema::User* MGLUser = static_cast<const gamelink::schema::User*>(User.Obj);
if (MGLUser)
{
return MGLUser->GetTwitchID().c_str();
}

return "";
}

MGL_RequestId MuxyGameLink_SendBroadcast(MuxyGameLink GameLink, const char* Topic, const char* JsonString)
{
gamelink::SDK* SDK = static_cast<gamelink::SDK*>(GameLink.SDK);
Expand Down
5 changes: 3 additions & 2 deletions c_library/gamelink_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C"
typedef uint16_t MGL_RequestId;
static const MGL_RequestId ANY_REQUEST_ID = UINT16_MAX;
static const MGL_RequestId REJECTED_REQUEST_ID = UINT16_MAX-1;

typedef struct
{
void* SDK;
Expand Down Expand Up @@ -260,6 +260,7 @@ extern "C"
MUXY_CLIB_API const char* MuxyGameLink_Schema_User_GetJWT(MGL_Schema_User User);
MUXY_CLIB_API const char* MuxyGameLink_Schema_User_GetRefreshToken(MGL_Schema_User User);
MUXY_CLIB_API const char* MuxyGameLink_Schema_User_GetTwitchName(MGL_Schema_User User);
MUXY_CLIB_API const char* MuxyGameLink_Schema_User_GetTwitchID(MGL_Schema_User User);

/*
State functions
Expand Down Expand Up @@ -475,7 +476,7 @@ extern "C"
MUXY_CLIB_API uint32_t MuxyGameLink_PatchList_Empty(MGL_PatchList PList);
MUXY_CLIB_API void MuxyGameLink_PatchList_Clear(MGL_PatchList PList);

/*
/*
Drops
*/
MUXY_CLIB_API MGL_RequestId MuxyGameLink_GetDrops(MuxyGameLink GameLink, const char* Status, MGL_DropsCallback Callback, void* User);
Expand Down
77 changes: 39 additions & 38 deletions gamelink_single.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27025,7 +27025,7 @@ namespace gamelink
/// Game ID, assigned by Muxy.
string game_id;
};

MUXY_GAMELINK_SERIALIZE_3(AuthenticateWithGameAndPINRequestBody, "pin", pin, "client_id", client_id, "game_id", game_id);

struct MUXY_GAMELINK_API AuthenticateWithGameAndPINRequest : SendEnvelope<AuthenticateWithGameAndPINRequestBody>
Expand Down Expand Up @@ -27057,7 +27057,7 @@ namespace gamelink
/// @param[in] RefreshToken Refresh token obtained from authorization.
AuthenticateWithRefreshTokenRequest(const string& clientId, const string& refreshToken);
};

struct MUXY_GAMELINK_API AuthenticateWithRefreshTokenAndGameRequestBody
{
string refresh;
Expand Down Expand Up @@ -27104,8 +27104,11 @@ namespace gamelink

/// Information about the channel the auth was done with
string twitch_name;

/// The twitch id of the user in question
string twitch_id;
};
MUXY_GAMELINK_SERIALIZE_3(AuthenticateResponseBody, "jwt", jwt, "refresh", refresh, "twitch_name", twitch_name);
MUXY_GAMELINK_SERIALIZE_4(AuthenticateResponseBody, "jwt", jwt, "refresh", refresh, "twitch_name", twitch_name, "twitch_id", twitch_id);

struct MUXY_GAMELINK_API AuthenticateResponse : ReceiveEnvelope<AuthenticateResponseBody>
{
Expand All @@ -27116,16 +27119,18 @@ namespace gamelink
class MUXY_GAMELINK_API User
{
public:
User(string jwt, string refreshToken, string twitchName);
User(string jwt, string refreshToken, string twitchName, string twtichID);

const string& GetJWT() const;
const string& GetRefreshToken() const;
const string& GetTwitchName() const;
const string& GetTwitchID() const;
// string GetOpaqueID();
private:
string jwt;
string refreshToken;
string twitchName;
string twitchID;
};
}
}
Expand Down Expand Up @@ -30217,10 +30222,11 @@ namespace gateway
class AuthenticateResponse
{
public:
AuthenticateResponse(string JWT, string RefreshToken, string TwitchName, bool DidError)
AuthenticateResponse(string JWT, string RefreshToken, string TwitchName, string TwitchID, bool DidError)
: JWT(JWT)
, RefreshToken(RefreshToken)
, TwitchName(TwitchName)
, TwitchID(TwitchID)
, DidError(DidError)
{
}
Expand All @@ -30234,6 +30240,9 @@ namespace gateway
/// Information about the channel the auth was done with
string TwitchName;

// Information about the channel the auth was done with
string TwitchID;

bool HasError() const
{
return DidError;
Expand Down Expand Up @@ -30611,7 +30620,7 @@ namespace gamelink
params.target = string("authentication");
}


AuthenticateWithPINRequest::AuthenticateWithPINRequest(const string& clientId, const string& pin)
{
action = string("authenticate");
Expand Down Expand Up @@ -30646,13 +30655,14 @@ namespace gamelink
data.game_id = gameId;
}

User::User(string jwt, string refreshToken, string twitchName)
User::User(string jwt, string refreshToken, string twitchName, string twitchID)
: jwt(std::move(jwt))
, refreshToken(std::move(refreshToken))
, twitchName(std::move(twitchName))
, twitchID(std::move(twitchID))
{
}

const string& User::GetJWT() const
{
return jwt;
Expand All @@ -30667,6 +30677,11 @@ namespace gamelink
{
return twitchName;
}

const string& User::GetTwitchID() const
{
return twitchID;
}
}
}

Expand Down Expand Up @@ -31477,15 +31492,15 @@ namespace gamelink
success = schema::ParseResponse(bytes, length, authResp);
if (success)
{
const schema::Error * err = FirstError(authResp);
const schema::Error* err = FirstError(authResp);
if (!err)
{
_lock.lock();
if (_user)
{
delete _user;
}
_user = new schema::User(authResp.data.jwt, authResp.data.refresh, authResp.data.twitch_name);
_user = new schema::User(authResp.data.jwt, authResp.data.refresh, authResp.data.twitch_name, authResp.data.twitch_id);
_lock.unlock();

_storedJWT = authResp.data.jwt;
Expand Down Expand Up @@ -33238,7 +33253,7 @@ namespace gateway
return Base.HasPayloads();
}

void SDK::OnDebugMessage(std::function<void (const gateway::string&)> callback)
void SDK::OnDebugMessage(std::function<void(const gateway::string&)> callback)
{
return Base.OnDebugMessage(std::move(callback));
}
Expand All @@ -33263,17 +33278,19 @@ namespace gateway

RequestID SDK::AuthenticateWithPIN(const string& PIN, std::function<void(const gateway::AuthenticateResponse&)> Callback)
{
return Base.AuthenticateWithGameIDAndPIN(this->ClientID, this->GameID, PIN, [=](const gamelink::schema::AuthenticateResponse& Resp) {
gateway::AuthenticateResponse Auth(Resp.data.jwt, Resp.data.refresh, Resp.data.twitch_name, gamelink::FirstError(Resp) != NULL);
Callback(Auth);
});
return Base.AuthenticateWithGameIDAndPIN(
this->ClientID, this->GameID, PIN, [=](const gamelink::schema::AuthenticateResponse& Resp) {
gateway::AuthenticateResponse Auth(Resp.data.jwt, Resp.data.refresh, Resp.data.twitch_name, Resp.data.twitch_id,
gamelink::FirstError(Resp) != NULL);
Callback(Auth);
});
}

RequestID SDK::AuthenticateWithRefreshToken(const string& JWT, std::function<void(const gateway::AuthenticateResponse&)> Callback)
{
return Base.AuthenticateWithGameIDAndRefreshToken(
this->ClientID, this->GameID, JWT, [=](const gamelink::schema::AuthenticateResponse& Resp) {
gateway::AuthenticateResponse Auth(Resp.data.jwt, Resp.data.refresh, Resp.data.twitch_name,
gateway::AuthenticateResponse Auth(Resp.data.jwt, Resp.data.refresh, Resp.data.twitch_name, Resp.data.twitch_id,
gamelink::FirstError(Resp) != NULL);
Callback(Auth);
});
Expand Down Expand Up @@ -33310,22 +33327,12 @@ namespace gateway

string SDK::GetProjectionSandboxURL(const string& projection, int major, int minor, int patch) const
{
return gamelink::ProjectionWebsocketConnectionURL(
ClientID,
gamelink::ConnectionStage::Sandbox,
projection,
major, minor, patch
);
return gamelink::ProjectionWebsocketConnectionURL(ClientID, gamelink::ConnectionStage::Sandbox, projection, major, minor, patch);
}

string SDK::GetProjectionProductionURL(const string& projection, int major, int minor, int patch) const
{
return gamelink::ProjectionWebsocketConnectionURL(
ClientID,
gamelink::ConnectionStage::Production,
projection,
major, minor, patch
);
return gamelink::ProjectionWebsocketConnectionURL(ClientID, gamelink::ConnectionStage::Production, projection, major, minor, patch);
}

void SDK::StopPoll()
Expand Down Expand Up @@ -33369,12 +33376,8 @@ namespace gateway
config.userData = cfg.UserData;

Base.RunPoll(
id,
cfg.Prompt,
config,
cfg.Options,
[=](const gamelink::schema::PollUpdateResponse& response)
{
id, cfg.Prompt, config, cfg.Options,
[=](const gamelink::schema::PollUpdateResponse& response) {
PollUpdate update;

uint32_t idx = gamelink::GetPollWinnerIndex(response.data.results);
Expand All @@ -33390,8 +33393,7 @@ namespace gateway
cfg.OnUpdate(update);
}
},
[=](const gamelink::schema::PollUpdateResponse& response)
{
[=](const gamelink::schema::PollUpdateResponse& response) {
PollUpdate finish;

uint32_t idx = gamelink::GetPollWinnerIndex(response.data.results);
Expand All @@ -33411,8 +33413,7 @@ namespace gateway
{
cfg.OnComplete(finish);
}
}
);
});
}
}

Expand Down
6 changes: 5 additions & 1 deletion include/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ namespace gateway
class AuthenticateResponse
{
public:
AuthenticateResponse(string JWT, string RefreshToken, string TwitchName, bool DidError)
AuthenticateResponse(string JWT, string RefreshToken, string TwitchName, string TwitchID, bool DidError)
: JWT(JWT)
, RefreshToken(RefreshToken)
, TwitchName(TwitchName)
, TwitchID(TwitchID)
, DidError(DidError)
{
}
Expand All @@ -52,6 +53,9 @@ namespace gateway
/// Information about the channel the auth was done with
string TwitchName;

// Information about the channel the auth was done with
string TwitchID;

bool HasError() const
{
return DidError;
Expand Down
12 changes: 9 additions & 3 deletions schema/authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace gamelink
params.target = string("authentication");
}


AuthenticateWithPINRequest::AuthenticateWithPINRequest(const string& clientId, const string& pin)
{
action = string("authenticate");
Expand Down Expand Up @@ -45,13 +45,14 @@ namespace gamelink
data.game_id = gameId;
}

User::User(string jwt, string refreshToken, string twitchName)
User::User(string jwt, string refreshToken, string twitchName, string twitchID)
: jwt(std::move(jwt))
, refreshToken(std::move(refreshToken))
, twitchName(std::move(twitchName))
, twitchID(std::move(twitchID))
{
}

const string& User::GetJWT() const
{
return jwt;
Expand All @@ -66,5 +67,10 @@ namespace gamelink
{
return twitchName;
}

const string& User::GetTwitchID() const
{
return twitchID;
}
}
}
13 changes: 9 additions & 4 deletions schema/authentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace gamelink
/// Game ID, assigned by Muxy.
string game_id;
};

MUXY_GAMELINK_SERIALIZE_3(AuthenticateWithGameAndPINRequestBody, "pin", pin, "client_id", client_id, "game_id", game_id);

struct MUXY_GAMELINK_API AuthenticateWithGameAndPINRequest : SendEnvelope<AuthenticateWithGameAndPINRequestBody>
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace gamelink
/// @param[in] RefreshToken Refresh token obtained from authorization.
AuthenticateWithRefreshTokenRequest(const string& clientId, const string& refreshToken);
};

struct MUXY_GAMELINK_API AuthenticateWithRefreshTokenAndGameRequestBody
{
string refresh;
Expand Down Expand Up @@ -119,8 +119,11 @@ namespace gamelink

/// Information about the channel the auth was done with
string twitch_name;

/// The twitch id of the user in question
string twitch_id;
};
MUXY_GAMELINK_SERIALIZE_3(AuthenticateResponseBody, "jwt", jwt, "refresh", refresh, "twitch_name", twitch_name);
MUXY_GAMELINK_SERIALIZE_4(AuthenticateResponseBody, "jwt", jwt, "refresh", refresh, "twitch_name", twitch_name, "twitch_id", twitch_id);

struct MUXY_GAMELINK_API AuthenticateResponse : ReceiveEnvelope<AuthenticateResponseBody>
{
Expand All @@ -131,16 +134,18 @@ namespace gamelink
class MUXY_GAMELINK_API User
{
public:
User(string jwt, string refreshToken, string twitchName);
User(string jwt, string refreshToken, string twitchName, string twtichID);

const string& GetJWT() const;
const string& GetRefreshToken() const;
const string& GetTwitchName() const;
const string& GetTwitchID() const;
// string GetOpaqueID();
private:
string jwt;
string refreshToken;
string twitchName;
string twitchID;
};
}
}
Expand Down
Loading
Loading