MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / parseXTokenResponse

Function parseXTokenResponse

launcher/minecraft/auth/Parsers.cpp:76–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

onRequestDoneMethod · 0.85
onRequestDoneMethod · 0.85

Calls 7

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

Tested by

no test coverage detected