mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Check MIME type in auth server response.
This commit is contained in:
parent
d69c517137
commit
b821cd71a9
1 changed files with 26 additions and 5 deletions
|
@ -475,14 +475,35 @@ ServerConnection.prototype.join = async function(group, username, credentials, d
|
||||||
});
|
});
|
||||||
if(!r.ok)
|
if(!r.ok)
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The authorisation server said: ${r.status} ${r.statusText}`,
|
`The authorisation server said ${r.status} ${r.statusText}`,
|
||||||
);
|
);
|
||||||
let data = await r.text();
|
if(r.status === 204) {
|
||||||
if(!data)
|
// no data, fallback to password auth
|
||||||
// empty data, continue with password auth
|
|
||||||
m.password = credentials.password;
|
m.password = credentials.password;
|
||||||
else
|
break;
|
||||||
|
}
|
||||||
|
let ctype = r.headers.get("Content-Type");
|
||||||
|
if(!ctype)
|
||||||
|
throw new Error(
|
||||||
|
"The authorisation server didn't return a content type",
|
||||||
|
);
|
||||||
|
let semi = ctype.indexOf(";");
|
||||||
|
if(semi >= 0)
|
||||||
|
ctype = ctype.slice(0, semi);
|
||||||
|
ctype = ctype.trim();
|
||||||
|
switch(ctype.toLowerCase()) {
|
||||||
|
case 'application/jwt':
|
||||||
|
let data = await r.text();
|
||||||
|
if(!data)
|
||||||
|
throw new Error(
|
||||||
|
"The authorisation server returned empty token",
|
||||||
|
);
|
||||||
m.token = data;
|
m.token = data;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`The authorisation server returned ${ctype}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown credentials type ${credentials.type}`);
|
throw new Error(`Unknown credentials type ${credentials.type}`);
|
||||||
|
|
Loading…
Reference in a new issue