First attempt at SSO from BBB to Matrix via riot-embedded · LinuxPlumbersConf/riot-embedded@b702c66 (original) (raw)
`@@ -15,6 +15,7 @@ import Avatar from './avatar';
`
15
15
` * React component for the client
`
16
16
` *
`
17
17
` * @param {string} roomId - The ID of default room
`
``
18
`+
- @param {string} displayName - The display name for the user
`
18
19
` * @param {string} userId - The ID of default user
`
19
20
` * @param {string} accessToken - Access token of default user
`
20
21
` * @param {string} baseUrl - Base URL of homeserver
`
`@@ -26,6 +27,8 @@ import Avatar from './avatar';
`
26
27
` * @param {boolean} msgComposer - If message composer should be displayed
`
27
28
` * @param {Array} whitelist - Whitelisted origins
`
28
29
` * @param {string} signInPrompt - Show sign in prompt for - none, guests, all
`
``
30
`+
- @param {string} email - LPC 2021 email transformed into Matrix userId
`
``
31
`+
- @param {string} regcode - LPC 2021 registration code
`
29
32
` */
`
30
33
`export default class Client extends Component{
`
31
34
`static propTypes = {
`
`@@ -41,7 +44,9 @@ export default class Client extends Component{
`
41
44
`roomsList: PropTypes.bool, // Enable roomsList? Overrides readOnly
`
42
45
`msgComposer: PropTypes.bool, // Enable msgComposer? Overrides readOnly
`
43
46
`whitelist: PropTypes.array, // Whitelisted origins - ignore to allow all
`
44
``
`-
signInPrompt: PropTypes.string // Show signInPrompt for - none, guests, all
`
``
47
`+
signInPrompt: PropTypes.string, // Show signInPrompt for - none, guests, all
`
``
48
`+
email: PropTypes.string, // LPC 2021 email transformed into Matrix userId
`
``
49
`+
regcode: PropTypes.string // LPC 2021 registration code
`
45
50
`};
`
46
51
``
47
52
`constructor(props) {
`
`@@ -97,8 +102,61 @@ export default class Client extends Component{
`
97
102
`this.consentModal = createRef();
`
98
103
`this.msgComposer = createRef();
`
99
104
``
100
``
`-
if (!props.accessToken || !props.userId) {
`
101
``
`-
// If either accessToken or userId is absent
`
``
105
`+
if (props.regcode && props.userId) {
`
``
106
`+
// LPC 2021 New password-based login logic
`
``
107
`+
// with the regcode as password parms
`
``
108
+
``
109
`+
this.isGuest = false;
`
``
110
`+
console.log("I suck at this :-)");
`
``
111
+
``
112
`+
this.client = this.sdk.createClient({
`
``
113
`+
baseUrl: props.baseUrl
`
``
114
`+
});
`
``
115
+
``
116
`+
this.client.login("m.login.password", {"user": props.userId, "password": props.regcode}).then((response) => {
`
``
117
+
``
118
`+
console.log(response.access_token);
`
``
119
+
``
120
`+
let userId = response.user_id;
`
``
121
`+
let accessToken = response.access_token;
`
``
122
`+
this.client = this.sdk.createClient({
`
``
123
`+
baseUrl: props.baseUrl,
`
``
124
`+
accessToken: accessToken,
`
``
125
`+
userId: userId
`
``
126
`+
});
`
``
127
+
``
128
`+
// trying to set the displayname from BBB via url
`
``
129
`+
if (this.props.displayName){
`
``
130
`+
this.client.setDisplayName(this.props.displayName);
`
``
131
`+
}
`
``
132
+
``
133
`+
this.joinRoomConsentSafe(this.props.roomId, () => {this.init();});
`
``
134
`+
});
`
``
135
+
``
136
`+
// this.client.joinRoom(this.props.roomId, {syncRoom: true}).then(() => {
`
``
137
`+
// this.init();
`
``
138
`+
// });
`
``
139
`+
} else if (props.accessToken && props.userId) {
`
``
140
`+
// Token based login (static from config.js for now)
`
``
141
`+
this.isGuest = false;
`
``
142
+
``
143
`+
this.client = this.sdk.createClient({
`
``
144
`+
baseUrl: props.baseUrl,
`
``
145
`+
accessToken: props.accessToken,
`
``
146
`+
userId: props.userId
`
``
147
`+
});
`
``
148
+
``
149
`+
if (props.readOnly) {
`
``
150
`+
this.client.peekInRoom(this.props.roomId, {syncRoom: true}).then(() => {
`
``
151
`+
this.init();
`
``
152
`+
});
`
``
153
`+
} else {
`
``
154
`+
this.client.joinRoom(this.props.roomId, {syncRoom: true}).then(() => {
`
``
155
`+
this.init();
`
``
156
`+
});
`
``
157
`+
}
`
``
158
`+
} else if (!props.accessToken || !props.regcode) {
`
``
159
`+
// If either accessToken or regcode is absent
`
102
160
`// Register as guest
`
103
161
`this.isGuest = true;
`
104
162
``
`@@ -136,24 +194,6 @@ export default class Client extends Component{
`
136
194
`});
`
137
195
`}
`
138
196
`});
`
139
``
`-
} else {
`
140
``
`-
this.isGuest = false;
`
141
``
-
142
``
`-
this.client = this.sdk.createClient({
`
143
``
`-
baseUrl: props.baseUrl,
`
144
``
`-
accessToken: props.accessToken,
`
145
``
`-
userId: props.userId
`
146
``
`-
});
`
147
``
-
148
``
`-
if (props.readOnly) {
`
149
``
`-
this.client.peekInRoom(this.props.roomId, {syncRoom: true}).then(() => {
`
150
``
`-
this.init();
`
151
``
`-
});
`
152
``
`-
} else {
`
153
``
`-
this.client.joinRoom(this.props.roomId, {syncRoom: true}).then(() => {
`
154
``
`-
this.init();
`
155
``
`-
});
`
156
``
`-
}
`
157
197
`}
`
158
198
`}
`
159
199
``