You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-07 23:02:56 +03:00
Implementation of MSC3824 to add action= param on SSO login (#2398)
Co-authored-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { SSOAction } from '../../src/@types/auth';
|
||||||
import { TestClient } from '../TestClient';
|
import { TestClient } from '../TestClient';
|
||||||
|
|
||||||
describe('Login request', function() {
|
describe('Login request', function() {
|
||||||
@@ -22,3 +23,37 @@ describe('Login request', function() {
|
|||||||
expect(client.client.getUserId()).toBe(response.user_id);
|
expect(client.client.getUserId()).toBe(response.user_id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('SSO login URL', function() {
|
||||||
|
let client: TestClient;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
client = new TestClient();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
client.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SSOAction', function() {
|
||||||
|
const redirectUri = "https://test.com/foo";
|
||||||
|
|
||||||
|
it('No action', function() {
|
||||||
|
const urlString = client.client.getSsoLoginUrl(redirectUri, undefined, undefined, undefined);
|
||||||
|
const url = new URL(urlString);
|
||||||
|
expect(url.searchParams.has('org.matrix.msc3824.action')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('register', function() {
|
||||||
|
const urlString = client.client.getSsoLoginUrl(redirectUri, undefined, undefined, SSOAction.REGISTER);
|
||||||
|
const url = new URL(urlString);
|
||||||
|
expect(url.searchParams.get('org.matrix.msc3824.action')).toEqual('register');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('login', function() {
|
||||||
|
const urlString = client.client.getSsoLoginUrl(redirectUri, undefined, undefined, SSOAction.LOGIN);
|
||||||
|
const url = new URL(urlString);
|
||||||
|
expect(url.searchParams.get('org.matrix.msc3824.action')).toEqual('login');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -82,3 +82,11 @@ export interface ILoginParams {
|
|||||||
initial_device_display_name?: string;
|
initial_device_display_name?: string;
|
||||||
}
|
}
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
|
|
||||||
|
export enum SSOAction {
|
||||||
|
/** The user intends to login to an existing account */
|
||||||
|
LOGIN = "login",
|
||||||
|
|
||||||
|
/** The user intends to register for a new account */
|
||||||
|
REGISTER = "register",
|
||||||
|
}
|
||||||
|
@@ -188,13 +188,14 @@ import { IPusher, IPusherRequest, IPushRules, PushRuleAction, PushRuleKind, Rule
|
|||||||
import { IThreepid } from "./@types/threepids";
|
import { IThreepid } from "./@types/threepids";
|
||||||
import { CryptoStore } from "./crypto/store/base";
|
import { CryptoStore } from "./crypto/store/base";
|
||||||
import { MediaHandler } from "./webrtc/mediaHandler";
|
import { MediaHandler } from "./webrtc/mediaHandler";
|
||||||
import { ILoginFlowsResponse, IRefreshTokenResponse } from "./@types/auth";
|
import { ILoginFlowsResponse, IRefreshTokenResponse, SSOAction } from "./@types/auth";
|
||||||
import { TypedEventEmitter } from "./models/typed-event-emitter";
|
import { TypedEventEmitter } from "./models/typed-event-emitter";
|
||||||
import { ReceiptType } from "./@types/read_receipts";
|
import { ReceiptType } from "./@types/read_receipts";
|
||||||
import { MSC3575SlidingSyncRequest, MSC3575SlidingSyncResponse, SlidingSync } from "./sliding-sync";
|
import { MSC3575SlidingSyncRequest, MSC3575SlidingSyncResponse, SlidingSync } from "./sliding-sync";
|
||||||
import { SlidingSyncSdk } from "./sliding-sync-sdk";
|
import { SlidingSyncSdk } from "./sliding-sync-sdk";
|
||||||
import { Thread, THREAD_RELATION_TYPE } from "./models/thread";
|
import { Thread, THREAD_RELATION_TYPE } from "./models/thread";
|
||||||
import { MBeaconInfoEventContent, M_BEACON_INFO } from "./@types/beacon";
|
import { MBeaconInfoEventContent, M_BEACON_INFO } from "./@types/beacon";
|
||||||
|
import { UnstableValue } from "./NamespacedValue";
|
||||||
import { ToDeviceMessageQueue } from "./ToDeviceMessageQueue";
|
import { ToDeviceMessageQueue } from "./ToDeviceMessageQueue";
|
||||||
import { ToDeviceBatch } from "./models/ToDeviceMessage";
|
import { ToDeviceBatch } from "./models/ToDeviceMessage";
|
||||||
import { IgnoredInvites } from "./models/invites-ignorer";
|
import { IgnoredInvites } from "./models/invites-ignorer";
|
||||||
@@ -881,6 +882,8 @@ export type ClientEventHandlerMap = {
|
|||||||
& HttpApiEventHandlerMap
|
& HttpApiEventHandlerMap
|
||||||
& BeaconEventHandlerMap;
|
& BeaconEventHandlerMap;
|
||||||
|
|
||||||
|
const SSO_ACTION_PARAM = new UnstableValue("action", "org.matrix.msc3824.action");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Matrix Client. Only directly construct this if you want to use
|
* Represents a Matrix Client. Only directly construct this if you want to use
|
||||||
* custom modules. Normally, {@link createClient} should be used
|
* custom modules. Normally, {@link createClient} should be used
|
||||||
@@ -7156,15 +7159,26 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @param {string} loginType The type of SSO login we are doing (sso or cas).
|
* @param {string} loginType The type of SSO login we are doing (sso or cas).
|
||||||
* Defaults to 'sso'.
|
* Defaults to 'sso'.
|
||||||
* @param {string} idpId The ID of the Identity Provider being targeted, optional.
|
* @param {string} idpId The ID of the Identity Provider being targeted, optional.
|
||||||
|
* @param {SSOAction} action the SSO flow to indicate to the IdP, optional.
|
||||||
* @return {string} The HS URL to hit to begin the SSO login process.
|
* @return {string} The HS URL to hit to begin the SSO login process.
|
||||||
*/
|
*/
|
||||||
public getSsoLoginUrl(redirectUrl: string, loginType = "sso", idpId?: string): string {
|
public getSsoLoginUrl(
|
||||||
|
redirectUrl: string,
|
||||||
|
loginType = "sso",
|
||||||
|
idpId?: string,
|
||||||
|
action?: SSOAction,
|
||||||
|
): string {
|
||||||
let url = "/login/" + loginType + "/redirect";
|
let url = "/login/" + loginType + "/redirect";
|
||||||
if (idpId) {
|
if (idpId) {
|
||||||
url += "/" + idpId;
|
url += "/" + idpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.http.getUrl(url, { redirectUrl }, PREFIX_R0);
|
const params = {
|
||||||
|
redirectUrl,
|
||||||
|
[SSO_ACTION_PARAM.unstable!]: action,
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.getUrl(url, params, PREFIX_R0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user