Merge pull request #4170 from matrix-org/travis/sso-register-dev
Disable registration flows on SSO serverspull/21833/head
commit
7aba168c34
|
@ -28,6 +28,7 @@ import AutoDiscoveryUtils, {ValidatedServerConfig} from "../../../utils/AutoDisc
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import AuthPage from "../../views/auth/AuthPage";
|
import AuthPage from "../../views/auth/AuthPage";
|
||||||
import SSOButton from "../../views/elements/SSOButton";
|
import SSOButton from "../../views/elements/SSOButton";
|
||||||
|
import PlatformPeg from '../../../PlatformPeg';
|
||||||
|
|
||||||
// For validating phone numbers without country codes
|
// For validating phone numbers without country codes
|
||||||
const PHONE_NUMBER_REGEX = /^[0-9()\-\s]*$/;
|
const PHONE_NUMBER_REGEX = /^[0-9()\-\s]*$/;
|
||||||
|
@ -339,6 +340,21 @@ export default createReactClass({
|
||||||
this.props.onRegisterClick();
|
this.props.onRegisterClick();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onTryRegisterClick: function(ev) {
|
||||||
|
const step = this._getCurrentFlowStep();
|
||||||
|
if (step === 'm.login.sso' || step === 'm.login.cas') {
|
||||||
|
// If we're showing SSO it means that registration is also probably disabled,
|
||||||
|
// so intercept the click and instead pretend the user clicked 'Sign in with SSO'.
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
const ssoKind = step === 'm.login.sso' ? 'sso' : 'cas';
|
||||||
|
PlatformPeg.get().startSingleSignOn(this._loginLogic.createTemporaryClient(), ssoKind);
|
||||||
|
} else {
|
||||||
|
// Don't intercept - just go through to the register page
|
||||||
|
this.onRegisterClick(ev);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async onServerDetailsNextPhaseClick() {
|
async onServerDetailsNextPhaseClick() {
|
||||||
this.setState({
|
this.setState({
|
||||||
phase: PHASE_LOGIN,
|
phase: PHASE_LOGIN,
|
||||||
|
@ -652,7 +668,7 @@ export default createReactClass({
|
||||||
{ serverDeadSection }
|
{ serverDeadSection }
|
||||||
{ this.renderServerComponent() }
|
{ this.renderServerComponent() }
|
||||||
{ this.renderLoginComponentForStep() }
|
{ this.renderLoginComponentForStep() }
|
||||||
<a className="mx_AuthBody_changeFlow" onClick={this.onRegisterClick} href="#">
|
<a className="mx_AuthBody_changeFlow" onClick={this.onTryRegisterClick} href="#">
|
||||||
{ _t('Create account') }
|
{ _t('Create account') }
|
||||||
</a>
|
</a>
|
||||||
</AuthBody>
|
</AuthBody>
|
||||||
|
|
|
@ -31,6 +31,8 @@ import classNames from "classnames";
|
||||||
import * as Lifecycle from '../../../Lifecycle';
|
import * as Lifecycle from '../../../Lifecycle';
|
||||||
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
||||||
import AuthPage from "../../views/auth/AuthPage";
|
import AuthPage from "../../views/auth/AuthPage";
|
||||||
|
import Login from "../../../Login";
|
||||||
|
import dis from "../../../dispatcher";
|
||||||
|
|
||||||
// Phases
|
// Phases
|
||||||
// Show controls to configure server details
|
// Show controls to configure server details
|
||||||
|
@ -232,6 +234,13 @@ export default createReactClass({
|
||||||
serverRequiresIdServer,
|
serverRequiresIdServer,
|
||||||
busy: false,
|
busy: false,
|
||||||
});
|
});
|
||||||
|
const showGenericError = (e) => {
|
||||||
|
this.setState({
|
||||||
|
errorText: _t("Unable to query for supported registration methods."),
|
||||||
|
// add empty flows array to get rid of spinner
|
||||||
|
flows: [],
|
||||||
|
});
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
await this._makeRegisterRequest({});
|
await this._makeRegisterRequest({});
|
||||||
// This should never succeed since we specified an empty
|
// This should never succeed since we specified an empty
|
||||||
|
@ -243,18 +252,32 @@ export default createReactClass({
|
||||||
flows: e.data.flows,
|
flows: e.data.flows,
|
||||||
});
|
});
|
||||||
} else if (e.httpStatus === 403 && e.errcode === "M_UNKNOWN") {
|
} else if (e.httpStatus === 403 && e.errcode === "M_UNKNOWN") {
|
||||||
this.setState({
|
// At this point registration is pretty much disabled, but before we do that let's
|
||||||
errorText: _t("Registration has been disabled on this homeserver."),
|
// quickly check to see if the server supports SSO instead. If it does, we'll send
|
||||||
// add empty flows array to get rid of spinner
|
// the user off to the login page to figure their account out.
|
||||||
flows: [],
|
try {
|
||||||
});
|
const loginLogic = new Login(hsUrl, isUrl, null, {
|
||||||
|
defaultDeviceDisplayName: "riot login check", // We shouldn't ever be used
|
||||||
|
});
|
||||||
|
const flows = await loginLogic.getFlows();
|
||||||
|
const hasSsoFlow = flows.find(f => f.type === 'm.login.sso' || f.type === 'm.login.cas');
|
||||||
|
if (hasSsoFlow) {
|
||||||
|
// Redirect to login page - server probably expects SSO only
|
||||||
|
dis.dispatch({action: 'start_login'});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
errorText: _t("Registration has been disabled on this homeserver."),
|
||||||
|
// add empty flows array to get rid of spinner
|
||||||
|
flows: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to get login flows to check for SSO support", e);
|
||||||
|
showGenericError(e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Unable to query for supported registration methods.", e);
|
console.log("Unable to query for supported registration methods.", e);
|
||||||
this.setState({
|
showGenericError(e);
|
||||||
errorText: _t("Unable to query for supported registration methods."),
|
|
||||||
// add empty flows array to get rid of spinner
|
|
||||||
flows: [],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -2007,8 +2007,8 @@
|
||||||
"Failed to fetch avatar URL": "Failed to fetch avatar URL",
|
"Failed to fetch avatar URL": "Failed to fetch avatar URL",
|
||||||
"Set a display name:": "Set a display name:",
|
"Set a display name:": "Set a display name:",
|
||||||
"Upload an avatar:": "Upload an avatar:",
|
"Upload an avatar:": "Upload an avatar:",
|
||||||
"Registration has been disabled on this homeserver.": "Registration has been disabled on this homeserver.",
|
|
||||||
"Unable to query for supported registration methods.": "Unable to query for supported registration methods.",
|
"Unable to query for supported registration methods.": "Unable to query for supported registration methods.",
|
||||||
|
"Registration has been disabled on this homeserver.": "Registration has been disabled on this homeserver.",
|
||||||
"This server does not support authentication with a phone number.": "This server does not support authentication with a phone number.",
|
"This server does not support authentication with a phone number.": "This server does not support authentication with a phone number.",
|
||||||
"Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).": "Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).",
|
"Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).": "Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).",
|
||||||
"Continue with previous account": "Continue with previous account",
|
"Continue with previous account": "Continue with previous account",
|
||||||
|
|
Loading…
Reference in New Issue