Add utility method mxLoginWithAccessToken to login with existing access token (#7261)
This commit is contained in:
parent
b69ad0cd0b
commit
aa7cae08aa
3 changed files with 18 additions and 3 deletions
1
src/@types/global.d.ts
vendored
1
src/@types/global.d.ts
vendored
|
@ -100,6 +100,7 @@ declare global {
|
||||||
mxOnRecaptchaLoaded?: () => void;
|
mxOnRecaptchaLoaded?: () => void;
|
||||||
electron?: Electron;
|
electron?: Electron;
|
||||||
mxSendSentryReport: (userText: string, issueUrl: string, error: Error) => Promise<void>;
|
mxSendSentryReport: (userText: string, issueUrl: string, error: Error) => Promise<void>;
|
||||||
|
mxLoginWithAccessToken: (hsUrl: string, accessToken: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DesktopCapturerSource {
|
interface DesktopCapturerSource {
|
||||||
|
|
|
@ -538,8 +538,8 @@ export function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixC
|
||||||
* fires on_logging_in, optionally clears localstorage, persists new credentials
|
* fires on_logging_in, optionally clears localstorage, persists new credentials
|
||||||
* to localstorage, starts the new client.
|
* to localstorage, starts the new client.
|
||||||
*
|
*
|
||||||
* @param {MatrixClientCreds} credentials
|
* @param {IMatrixClientCreds} credentials
|
||||||
* @param {Boolean} clearStorage
|
* @param {Boolean} clearStorageEnabled
|
||||||
*
|
*
|
||||||
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
|
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
|
||||||
*/
|
*/
|
||||||
|
@ -918,3 +918,17 @@ export function stopMatrixClient(unsetClient = true): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility method to perform a login with an existing access_token
|
||||||
|
window.mxLoginWithAccessToken = async (hsUrl: string, accessToken: string): Promise<void> => {
|
||||||
|
const tempClient = createClient({
|
||||||
|
baseUrl: hsUrl,
|
||||||
|
accessToken,
|
||||||
|
});
|
||||||
|
const { user_id: userId } = await tempClient.whoami();
|
||||||
|
await doSetLoggedIn({
|
||||||
|
homeserverUrl: hsUrl,
|
||||||
|
accessToken,
|
||||||
|
userId,
|
||||||
|
}, true);
|
||||||
|
};
|
||||||
|
|
|
@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
export interface IMatrixClientCreds {
|
export interface IMatrixClientCreds {
|
||||||
homeserverUrl: string;
|
homeserverUrl: string;
|
||||||
identityServerUrl: string;
|
identityServerUrl?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
deviceId?: string;
|
deviceId?: string;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
|
Loading…
Reference in a new issue