mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-08-05 16:59:10 +00:00
extend sasl password to include server domain for non-matrix.org accounts. Part of #12
This commit is contained in:
parent
31a869f04b
commit
05d6973506
4 changed files with 14 additions and 10 deletions
|
@ -44,4 +44,4 @@ That said, it is usable for basic chatting.
|
||||||
Copy `config.example.json` to `config.json`, edit the values if needed, then `npm run build` and then `node reflection.js` to start it
|
Copy `config.example.json` to `config.json`, edit the values if needed, then `npm run build` and then `node reflection.js` to start it
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
Authentication is done via `SASL PLAIN`, the username is your mxid and the password is an access token from another session.
|
Authentication is done via `SASL PLAIN`, the username is your mxid and the password is an access token from another session plus your server domain, separated by a `:` (so `access_token:matrix.org` if your server is matrix.org). Note this is the domain for `m.server`, not necessarily the homeserver domain.
|
|
@ -156,8 +156,12 @@ export class Client {
|
||||||
this.closeConnectionWithError('Invalid authentication')
|
this.closeConnectionWithError('Invalid authentication')
|
||||||
}
|
}
|
||||||
const mxid = authArray[1];
|
const mxid = authArray[1];
|
||||||
const accessToken = authArray[2];
|
const accessTokenAndServer = authArray[2];
|
||||||
const thisIRCUser = this.server.getOrCreateIRCUser(mxid, accessToken);
|
const sepIndex = accessTokenAndServer.indexOf(":");
|
||||||
|
const accessToken = accessTokenAndServer.slice(0, sepIndex);
|
||||||
|
const homeserver = accessTokenAndServer.slice(sepIndex+1);
|
||||||
|
console.log(accessToken, homeserver);
|
||||||
|
const thisIRCUser = this.server.getOrCreateIRCUser(mxid, accessToken, homeserver);
|
||||||
thisIRCUser.getVerification().then((response) => {
|
thisIRCUser.getVerification().then((response) => {
|
||||||
if (response.status === 401 || response.status === 403) {
|
if (response.status === 401 || response.status === 403) {
|
||||||
this.sendMessage(this.server.name, '904', numerics['904']('*'), message.tags)
|
this.sendMessage(this.server.name, '904', numerics['904']('*'), message.tags)
|
||||||
|
@ -180,7 +184,7 @@ export class Client {
|
||||||
if (this.user.isSynced()) {
|
if (this.user.isSynced()) {
|
||||||
this.user.addClient(this, message.tags);
|
this.user.addClient(this, message.tags);
|
||||||
} else {
|
} else {
|
||||||
axios.get(`https://matrix.org/_matrix/client/v3/sync?access_token=${accessToken}`).then(response => {
|
axios.get(`https://${this.user.homeserver}/_matrix/client/v3/sync?access_token=${accessToken}`).then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
const rooms = data.rooms;
|
const rooms = data.rooms;
|
||||||
if (this.user === null)
|
if (this.user === null)
|
||||||
|
|
|
@ -17,7 +17,7 @@ export class IRCUser {
|
||||||
public nextBatch: string
|
public nextBatch: string
|
||||||
private initialSync: boolean
|
private initialSync: boolean
|
||||||
private syncIntervalID: NodeJS.Timeout;
|
private syncIntervalID: NodeJS.Timeout;
|
||||||
constructor(public mxid: string, private accessToken: string, private server: Server) {
|
constructor(public mxid: string, private accessToken: string, public homeserver: string, private server: Server) {
|
||||||
this.clients = new Set();
|
this.clients = new Set();
|
||||||
this.channels = new Set();
|
this.channels = new Set();
|
||||||
const mxidSplit = mxid.split(':')
|
const mxidSplit = mxid.split(':')
|
||||||
|
@ -37,7 +37,7 @@ export class IRCUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
getVerification() {
|
getVerification() {
|
||||||
return axios.get(`https://matrix.org/_matrix/client/v3/account/whoami?access_token=${this.accessToken}`);
|
return axios.get(`https://${this.homeserver}/_matrix/client/v3/account/whoami?access_token=${this.accessToken}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMask(): string {
|
getMask(): string {
|
||||||
|
@ -58,7 +58,7 @@ export class IRCUser {
|
||||||
console.log("not syncing, initial sync not completed");
|
console.log("not syncing, initial sync not completed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const endpoint = `https://matrix.org/_matrix/client/v3/sync?access_token=${this.accessToken}&since=${this.nextBatch}`;
|
const endpoint = `https://${this.homeserver}/_matrix/client/v3/sync?access_token=${this.accessToken}&since=${this.nextBatch}`;
|
||||||
axios.get(endpoint).then(response => {
|
axios.get(endpoint).then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
this.nextBatch = data.next_batch;
|
this.nextBatch = data.next_batch;
|
||||||
|
@ -94,7 +94,7 @@ export class IRCUser {
|
||||||
}
|
}
|
||||||
const newTxnid = randomUUID();
|
const newTxnid = randomUUID();
|
||||||
this.txnIdStore.set(newTxnid, client);
|
this.txnIdStore.set(newTxnid, client);
|
||||||
axios.put(`https://matrix.org/_matrix/client/v3/rooms/${channel.roomId}/send/m.room.message/${newTxnid}?access_token=${this.accessToken}`, content);
|
axios.put(`https://${this.homeserver}/_matrix/client/v3/rooms/${channel.roomId}/send/m.room.message/${newTxnid}?access_token=${this.accessToken}`, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) {
|
sendToAll(prefix: string, command: string, params: string[], tags: Map<string, string> = new Map(), skipClient: Client|null = null) {
|
||||||
|
|
|
@ -22,12 +22,12 @@ export class Server {
|
||||||
this.nickToMxid = new Map();
|
this.nickToMxid = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrCreateIRCUser(mxid: string, accessToken: string): IRCUser {
|
getOrCreateIRCUser(mxid: string, accessToken: string, homeserver: string): IRCUser {
|
||||||
const maybeUser = this.ircUsers.get(mxid);
|
const maybeUser = this.ircUsers.get(mxid);
|
||||||
if (maybeUser) {
|
if (maybeUser) {
|
||||||
return maybeUser;
|
return maybeUser;
|
||||||
}
|
}
|
||||||
return new IRCUser(mxid, accessToken, this);
|
return new IRCUser(mxid, accessToken, homeserver, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrCreateIRCChannel(roomId: string): Channel {
|
getOrCreateIRCChannel(roomId: string): Channel {
|
||||||
|
|
Loading…
Add table
Reference in a new issue