Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 094d006

Browse files
authored
Merge pull request #4292 from matrix-org/travis/sso-uia
Support SSO for interactive authentication
2 parents 138d280 + 64c11c3 commit 094d006

8 files changed

Lines changed: 323 additions & 14 deletions

File tree

res/css/views/auth/_InteractiveAuthEntryComponents.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,14 @@ limitations under the License.
6060
.mx_InteractiveAuthEntryComponents_passwordSection {
6161
width: 300px;
6262
}
63+
64+
.mx_InteractiveAuthEntryComponents_sso_buttons {
65+
display: flex;
66+
flex-direction: row;
67+
justify-content: flex-end;
68+
margin-top: 20px;
69+
70+
.mx_AccessibleButton {
71+
margin-left: 5px;
72+
}
73+
}

res/css/views/elements/_AccessibleButton.scss

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ limitations under the License.
3636
font-weight: 600;
3737
}
3838

39+
.mx_AccessibleButton_kind_primary_outline {
40+
color: $button-primary-bg-color;
41+
background-color: $button-secondary-bg-color;
42+
border: 1px solid $button-primary-bg-color;
43+
font-weight: 600;
44+
}
45+
3946
.mx_AccessibleButton_kind_secondary {
4047
color: $accent-color;
4148
font-weight: 600;
4249
}
4350

44-
.mx_AccessibleButton_kind_primary.mx_AccessibleButton_disabled {
51+
.mx_AccessibleButton_kind_primary.mx_AccessibleButton_disabled,
52+
.mx_AccessibleButton_kind_primary_outline.mx_AccessibleButton_disabled {
4553
opacity: 0.4;
4654
}
4755

@@ -60,7 +68,14 @@ limitations under the License.
6068
background-color: $button-danger-bg-color;
6169
}
6270

63-
.mx_AccessibleButton_kind_danger.mx_AccessibleButton_disabled {
71+
.mx_AccessibleButton_kind_danger_outline {
72+
color: $button-danger-bg-color;
73+
background-color: $button-secondary-bg-color;
74+
border: 1px solid $button-danger-bg-color;
75+
}
76+
77+
.mx_AccessibleButton_kind_danger.mx_AccessibleButton_disabled,
78+
.mx_AccessibleButton_kind_danger_outline.mx_AccessibleButton_disabled {
6479
color: $button-danger-disabled-fg-color;
6580
background-color: $button-danger-disabled-bg-color;
6681
}

src/AddThreepid.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as sdk from './index';
2121
import Modal from './Modal';
2222
import { _t } from './languageHandler';
2323
import IdentityAuthClient from './IdentityAuthClient';
24+
import {SSOAuthEntry} from "./components/views/auth/InteractiveAuthEntryComponents";
2425

2526
function getIdServerDomain() {
2627
return MatrixClientPeg.get().idBaseUrl.split("://")[1];
@@ -188,11 +189,31 @@ export default class AddThreepid {
188189
// pop up an interactive auth dialog
189190
const InteractiveAuthDialog = sdk.getComponent("dialogs.InteractiveAuthDialog");
190191

192+
193+
const dialogAesthetics = {
194+
[SSOAuthEntry.PHASE_PREAUTH]: {
195+
title: _t("Use Single Sign On to continue"),
196+
body: _t("Confirm adding this email address by using " +
197+
"Single Sign On to prove your identity."),
198+
continueText: _t("Single Sign On"),
199+
continueKind: "primary",
200+
},
201+
[SSOAuthEntry.PHASE_POSTAUTH]: {
202+
title: _t("Confirm adding email"),
203+
body: _t("Click the button below to confirm adding this email address."),
204+
continueText: _t("Confirm"),
205+
continueKind: "primary",
206+
},
207+
};
191208
const { finished } = Modal.createTrackedDialog('Add Email', '', InteractiveAuthDialog, {
192209
title: _t("Add Email Address"),
193210
matrixClient: MatrixClientPeg.get(),
194211
authData: e.data,
195212
makeRequest: this._makeAddThreepidOnlyRequest,
213+
aestheticsForStagePhases: {
214+
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
215+
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
216+
},
196217
});
197218
return finished;
198219
}
@@ -285,11 +306,30 @@ export default class AddThreepid {
285306
// pop up an interactive auth dialog
286307
const InteractiveAuthDialog = sdk.getComponent("dialogs.InteractiveAuthDialog");
287308

309+
const dialogAesthetics = {
310+
[SSOAuthEntry.PHASE_PREAUTH]: {
311+
title: _t("Use Single Sign On to continue"),
312+
body: _t("Confirm adding this phone number by using " +
313+
"Single Sign On to prove your identity."),
314+
continueText: _t("Single Sign On"),
315+
continueKind: "primary",
316+
},
317+
[SSOAuthEntry.PHASE_POSTAUTH]: {
318+
title: _t("Confirm adding phone number"),
319+
body: _t("Click the button below to confirm adding this phone number."),
320+
continueText: _t("Confirm"),
321+
continueKind: "primary",
322+
},
323+
};
288324
const { finished } = Modal.createTrackedDialog('Add MSISDN', '', InteractiveAuthDialog, {
289325
title: _t("Add Phone Number"),
290326
matrixClient: MatrixClientPeg.get(),
291327
authData: e.data,
292328
makeRequest: this._makeAddThreepidOnlyRequest,
329+
aestheticsForStagePhases: {
330+
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
331+
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
332+
},
293333
});
294334
return finished;
295335
}

src/components/structures/InteractiveAuth.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright 2017 Vector Creations Ltd.
3-
Copyright 2019 The Matrix.org Foundation C.I.C.
3+
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -24,6 +24,8 @@ import getEntryComponentForLoginType from '../views/auth/InteractiveAuthEntryCom
2424

2525
import * as sdk from '../../index';
2626

27+
export const ERROR_USER_CANCELLED = new Error("User cancelled auth session");
28+
2729
export default createReactClass({
2830
displayName: 'InteractiveAuth',
2931

@@ -47,7 +49,7 @@ export default createReactClass({
4749
// @param {bool} status True if the operation requiring
4850
// auth was completed sucessfully, false if canceled.
4951
// @param {object} result The result of the authenticated call
50-
// if successful, otherwise the error object
52+
// if successful, otherwise the error object.
5153
// @param {object} extra Additional information about the UI Auth
5254
// process:
5355
// * emailSid {string} If email auth was performed, the sid of
@@ -75,6 +77,15 @@ export default createReactClass({
7577
// is managed by some other party and should not be managed by
7678
// the component itself.
7779
continueIsManaged: PropTypes.bool,
80+
81+
// Called when the stage changes, or the stage's phase changes. First
82+
// argument is the stage, second is the phase. Some stages do not have
83+
// phases and will be counted as 0 (numeric).
84+
onStagePhaseChange: PropTypes.func,
85+
86+
// continueText and continueKind are passed straight through to the AuthEntryComponent.
87+
continueText: PropTypes.string,
88+
continueKind: PropTypes.string,
7889
},
7990

8091
getInitialState: function() {
@@ -204,6 +215,16 @@ export default createReactClass({
204215
this._authLogic.submitAuthDict(authData);
205216
},
206217

218+
_onPhaseChange: function(newPhase) {
219+
if (this.props.onStagePhaseChange) {
220+
this.props.onStagePhaseChange(this.state.authStage, newPhase || 0);
221+
}
222+
},
223+
224+
_onStageCancel: function() {
225+
this.props.onAuthFinished(false, ERROR_USER_CANCELLED);
226+
},
227+
207228
_renderCurrentStage: function() {
208229
const stage = this.state.authStage;
209230
if (!stage) {
@@ -232,6 +253,10 @@ export default createReactClass({
232253
fail={this._onAuthStageFailed}
233254
setEmailSid={this._setEmailSid}
234255
showContinue={!this.props.continueIsManaged}
256+
onPhaseChange={this._onPhaseChange}
257+
continueText={this.props.continueText}
258+
continueKind={this.props.continueKind}
259+
onCancel={this._onStageCancel}
235260
/>
236261
);
237262
},

0 commit comments

Comments
 (0)