mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 14:05:04 +08:00
Support IS token handling without checking terms
This is so we can optionally do our own terms handling.
This commit is contained in:
parent
83af732d05
commit
525b4cad0f
@ -65,7 +65,7 @@ export default class IdentityAuthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a promise that resolves to the access_token string from the IS
|
// Returns a promise that resolves to the access_token string from the IS
|
||||||
async getAccessToken() {
|
async getAccessToken(check=true) {
|
||||||
if (!this.authEnabled) {
|
if (!this.authEnabled) {
|
||||||
// The current IS doesn't support authentication
|
// The current IS doesn't support authentication
|
||||||
return null;
|
return null;
|
||||||
@ -77,7 +77,7 @@ export default class IdentityAuthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await this.registerForToken();
|
token = await this.registerForToken(check);
|
||||||
if (token) {
|
if (token) {
|
||||||
this.accessToken = token;
|
this.accessToken = token;
|
||||||
this._writeToken();
|
this._writeToken();
|
||||||
@ -85,18 +85,20 @@ export default class IdentityAuthClient {
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (check) {
|
||||||
await this._checkToken(token);
|
try {
|
||||||
} catch (e) {
|
await this._checkToken(token);
|
||||||
if (e instanceof TermsNotSignedError) {
|
} catch (e) {
|
||||||
// Retrying won't help this
|
if (e instanceof TermsNotSignedError) {
|
||||||
throw e;
|
// Retrying won't help this
|
||||||
}
|
throw e;
|
||||||
// Retry in case token expired
|
}
|
||||||
token = await this.registerForToken();
|
// Retry in case token expired
|
||||||
if (token) {
|
token = await this.registerForToken();
|
||||||
this.accessToken = token;
|
if (token) {
|
||||||
this._writeToken();
|
this.accessToken = token;
|
||||||
|
this._writeToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,12 +128,12 @@ export default class IdentityAuthClient {
|
|||||||
// See also https://github.com/vector-im/riot-web/issues/10455.
|
// See also https://github.com/vector-im/riot-web/issues/10455.
|
||||||
}
|
}
|
||||||
|
|
||||||
async registerForToken() {
|
async registerForToken(check=true) {
|
||||||
try {
|
try {
|
||||||
const hsOpenIdToken = await MatrixClientPeg.get().getOpenIdToken();
|
const hsOpenIdToken = await MatrixClientPeg.get().getOpenIdToken();
|
||||||
const { access_token: identityAccessToken } =
|
const { access_token: identityAccessToken } =
|
||||||
await this._matrixClient.registerWithIdentityServer(hsOpenIdToken);
|
await this._matrixClient.registerWithIdentityServer(hsOpenIdToken);
|
||||||
await this._checkToken(identityAccessToken);
|
if (check) await this._checkToken(identityAccessToken);
|
||||||
return identityAccessToken;
|
return identityAccessToken;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.cors === "rejected" || e.httpStatus === 404) {
|
if (e.cors === "rejected" || e.httpStatus === 404) {
|
||||||
|
Loading…
Reference in New Issue
Block a user