Improved flow for using OAuth2 while logged out.
This commit is contained in:
parent
8be630531a
commit
8f63b57c0c
9 changed files with 35 additions and 93 deletions
assets/oauth2.js
|
@ -161,8 +161,14 @@ const MszOAuth2Authorise = async () => {
|
|||
const { body } = await $x.get(`/oauth2/resolve-authorise-app?${resolveParams}`, { authed: true, csrf: true, type: 'json' });
|
||||
if(!body)
|
||||
throw 'authorisation resolve failed';
|
||||
if(typeof body.error === 'string')
|
||||
if(typeof body.error === 'string') {
|
||||
if(body.error === 'auth') {
|
||||
window.location.assign(`/auth/login.php?oauth2=1&redirect=${encodeURIComponent(`${window.location.pathname}${window.location.search}`)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
return translateError(body.error, body);
|
||||
}
|
||||
|
||||
const userHeader = new MszOAuth2UserHeader(body.user);
|
||||
header.setElement(userHeader);
|
||||
|
|
|
@ -104,9 +104,10 @@ const MszOAuth2Verify = () => {
|
|||
|
||||
if(typeof body.error === 'string') {
|
||||
// TODO: nicer errors
|
||||
if(body.error === 'auth')
|
||||
alert('You are not logged in.');
|
||||
else if(body.error === 'csrf')
|
||||
if(body.error === 'auth') {
|
||||
window.location.assign(`/auth/login.php?oauth2=1&redirect=${encodeURIComponent(`${window.location.pathname}${window.location.search}`)}`);
|
||||
return;
|
||||
} else if(body.error === 'csrf')
|
||||
alert('Request verification failed, please refresh and try again.');
|
||||
else if(body.error === 'code')
|
||||
alert('This code is not associated with any authorisation request.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue