MCPcopy Create free account
hub / github.com/MultiMC/Launcher / parseXTokenResponse

Function parseXTokenResponse

launcher/minecraft/auth/Parsers.cpp:75–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73*/
74
75bool parseXTokenResponse(QByteArray & data, Katabasis::Token &output, QString name) {
76 qDebug() << "Parsing" << name <<":";
77#ifndef NDEBUG
78 qDebug() << data;
79#endif
80 QJsonParseError jsonError;
81 QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
82 if(jsonError.error) {
83 qWarning() << "Failed to parse response from user.auth.xboxlive.com as JSON: " << jsonError.errorString();
84 return false;
85 }
86
87 auto obj = doc.object();
88 if(!getDateTime(obj.value("IssueInstant"), output.issueInstant)) {
89 qWarning() << "User IssueInstant is not a timestamp";
90 return false;
91 }
92 if(!getDateTime(obj.value("NotAfter"), output.notAfter)) {
93 qWarning() << "User NotAfter is not a timestamp";
94 return false;
95 }
96 if(!getString(obj.value("Token"), output.token)) {
97 qWarning() << "User Token is not a string";
98 return false;
99 }
100 auto arrayVal = obj.value("DisplayClaims").toObject().value("xui");
101 if(!arrayVal.isArray()) {
102 qWarning() << "Missing xui claims array";
103 return false;
104 }
105 bool foundUHS = false;
106 for(auto item: arrayVal.toArray()) {
107 if(!item.isObject()) {
108 continue;
109 }
110 auto obj = item.toObject();
111 if(obj.contains("uhs")) {
112 foundUHS = true;
113 } else {
114 continue;
115 }
116 // consume all 'display claims' ... whatever that means
117 for(auto iter = obj.begin(); iter != obj.end(); iter++) {
118 QString claim;
119 if(!getString(obj.value(iter.key()), claim)) {
120 qWarning() << "display claim " << iter.key() << " is not a string...";
121 return false;
122 }
123 output.extra[iter.key()] = claim;
124 }
125
126 break;
127 }
128 if(!foundUHS) {
129 qWarning() << "Missing uhs";
130 return false;
131 }
132 output.validity = Katabasis::Validity::Certain;

Callers 2

onRequestDoneMethod · 0.85
onRequestDoneMethod · 0.85

Calls 8

fromJsonFunction · 0.85
getDateTimeFunction · 0.85
getStringFunction · 0.85
objectMethod · 0.80
keyMethod · 0.80
containsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected