MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / run

Method run

plugins/twitch/token.cpp:892–995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

890}
891
892void TokenGrabberThread::run()
893{
894 // Reset
895 _server.stop();
896 _server.~Server();
897 new (&_server) httplib::Server();
898 if (_serverThread.joinable()) {
899 _serverThread.join();
900 }
901 _stopWaiting = false;
902
903 // Generate URI to request token
904 auto state = generateStateString();
905 QString getTokenURI =
906 ("https://id.twitch.tv/oauth2/authorize"
907 "?response_type=token"
908 "&client_id=" +
909 QString(GetClientID()) +
910 "&redirect_uri=http://localhost:%1"
911 "/auth"
912 "&scope=" +
913 _scope + "&state=" + QString::fromStdString(state))
914 .arg(QString::number(tokenGrabberPort));
915
916 // Setup server receiving token string
917 auto html = getHtml(getTokenURI);
918 _server.Get("/auth", [html, state](const httplib::Request &req,
919 httplib::Response &res) {
920 // Check for errors
921 if (req.has_param("error")) {
922 auto recvState = req.get_param_value("state");
923 if (recvState != state) {
924 blog(LOG_WARNING,
925 "state string does not match in error handling?! "
926 "Got \"%s\" - expected \"%s\"\n"
927 "ignoring error ...",
928 recvState.c_str(), state.c_str());
929 return;
930 }
931 auto errorStr =
932 req.get_param_value("error_description");
933 res.set_content(getAuthErrorString(errorStr.c_str()),
934 "text/plain");
935 return;
936 }
937
938 // Parse fragments and redirect to /token with
939 // corresponding parameters.
940 res.set_content(html, "text/html");
941 });
942 _server.Get("/token", [&](const httplib::Request &req,
943 httplib::Response &res) {
944 // Check if valid request and grab the token string
945 std::lock_guard<std::mutex> lk(_mutex);
946 auto recvState = req.get_param_value("state");
947 if (recvState != state) {
948 blog(LOG_WARNING,
949 "state string does not match! "

Callers 4

ConnectThreadMethod · 0.45
ConnectThreadMethod · 0.45
ConnectThreadMethod · 0.45

Calls 8

generateStateStringFunction · 0.85
GetClientIDFunction · 0.85
getHtmlFunction · 0.85
getAuthErrorStringFunction · 0.85
obs_module_textFunction · 0.85
nowClass · 0.85
GetMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected