Added roomid to authenitcation data flow to make mapping user info better.
parent
7f2f27b858
commit
603368007a
|
|
@ -391,7 +391,7 @@ export default class RoomClient
|
||||||
|
|
||||||
login()
|
login()
|
||||||
{
|
{
|
||||||
const url = `/auth/login?id=${this._peerId}`;
|
const url = `/auth/login?peerId=${this._peerId}&roomId=${this._roomId}`;
|
||||||
|
|
||||||
window.open(url, 'loginWindow');
|
window.open(url, 'loginWindow');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,13 @@ module.exports =
|
||||||
// use case: loadbalancer backend
|
// use case: loadbalancer backend
|
||||||
httpOnly : false,
|
httpOnly : false,
|
||||||
// This function will be called on successful login through oidc.
|
// This function will be called on successful login through oidc.
|
||||||
// Use this function to map your oidc userinfo to the Peer object,
|
// Use this function to map your oidc userinfo to the Peer object.
|
||||||
// see examples below.
|
// The roomId is equal to the room name.
|
||||||
|
// See examples below.
|
||||||
// Examples:
|
// Examples:
|
||||||
/*
|
/*
|
||||||
// All authenicated users will be MODERATOR and AUTHENTICATED
|
// All authenicated users will be MODERATOR and AUTHENTICATED
|
||||||
userMapping : async ({ peer, userinfo }) =>
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
{
|
{
|
||||||
peer.addRole(userRoles.MODERATOR);
|
peer.addRole(userRoles.MODERATOR);
|
||||||
peer.addRole(userRoles.AUTHENTICATED);
|
peer.addRole(userRoles.AUTHENTICATED);
|
||||||
|
|
@ -65,7 +66,7 @@ module.exports =
|
||||||
// All authenicated users will be AUTHENTICATED,
|
// All authenicated users will be AUTHENTICATED,
|
||||||
// and those with the moderator role set in the userinfo
|
// and those with the moderator role set in the userinfo
|
||||||
// will also be MODERATOR
|
// will also be MODERATOR
|
||||||
userMapping : async ({ peer, userinfo }) =>
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
Array.isArray(userinfo.meet_roles) &&
|
Array.isArray(userinfo.meet_roles) &&
|
||||||
|
|
@ -88,7 +89,7 @@ module.exports =
|
||||||
// All authenicated users will be AUTHENTICATED,
|
// All authenicated users will be AUTHENTICATED,
|
||||||
// and those with email ending with @example.com
|
// and those with email ending with @example.com
|
||||||
// will also be MODERATOR
|
// will also be MODERATOR
|
||||||
userMapping : async ({ peer, userinfo }) =>
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
{
|
{
|
||||||
if (userinfo.email && userinfo.email.endsWith('@example.com'))
|
if (userinfo.email && userinfo.email.endsWith('@example.com'))
|
||||||
{
|
{
|
||||||
|
|
@ -96,8 +97,21 @@ module.exports =
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.addRole(userRoles.AUTHENTICATED);
|
peer.addRole(userRoles.AUTHENTICATED);
|
||||||
},*/
|
}
|
||||||
userMapping : async ({ peer, userinfo }) =>
|
// All authenicated users will be AUTHENTICATED,
|
||||||
|
// and those with email ending with @example.com
|
||||||
|
// will also be MODERATOR
|
||||||
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
|
{
|
||||||
|
if (userinfo.email && userinfo.email.endsWith('@example.com'))
|
||||||
|
{
|
||||||
|
peer.addRole(userRoles.MODERATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
peer.addRole(userRoles.AUTHENTICATED);
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
{
|
{
|
||||||
if (userinfo.picture != null)
|
if (userinfo.picture != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const userRoles = require('../userRoles');
|
const userRoles = require('../userRoles');
|
||||||
const config = require('../config/config');
|
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
|
|
||||||
const logger = new Logger('Peer');
|
const logger = new Logger('Peer');
|
||||||
|
|
||||||
class Peer extends EventEmitter
|
class Peer extends EventEmitter
|
||||||
{
|
{
|
||||||
constructor({ id, socket })
|
constructor({ id, roomId, socket })
|
||||||
{
|
{
|
||||||
logger.info('constructor() [id:"%s", socket:"%s"]', id, socket.id);
|
logger.info('constructor() [id:"%s", socket:"%s"]', id, socket.id);
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._id = id;
|
this._id = id;
|
||||||
|
|
||||||
|
this._roomId = roomId;
|
||||||
|
|
||||||
this._authId = null;
|
this._authId = null;
|
||||||
|
|
||||||
this._socket = socket;
|
this._socket = socket;
|
||||||
|
|
@ -87,6 +88,16 @@ class Peer extends EventEmitter
|
||||||
this._id = id;
|
this._id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get roomId()
|
||||||
|
{
|
||||||
|
return this._roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
set roomId(roomId)
|
||||||
|
{
|
||||||
|
this._roomId = roomId;
|
||||||
|
}
|
||||||
|
|
||||||
get authId()
|
get authId()
|
||||||
{
|
{
|
||||||
return this._authId;
|
return this._authId;
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,8 @@ async function setupAuth()
|
||||||
{
|
{
|
||||||
passport.authenticate('oidc', {
|
passport.authenticate('oidc', {
|
||||||
state : base64.encode(JSON.stringify({
|
state : base64.encode(JSON.stringify({
|
||||||
id : req.query.id
|
peerId : req.query.peerId,
|
||||||
|
roomId : req.query.roomId
|
||||||
}))
|
}))
|
||||||
})(req, res, next);
|
})(req, res, next);
|
||||||
});
|
});
|
||||||
|
|
@ -324,14 +325,21 @@ async function setupAuth()
|
||||||
picture = '/static/media/buddy.403cb9f6.svg';
|
picture = '/static/media/buddy.403cb9f6.svg';
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer = peers.get(state.id);
|
const peer = peers.get(state.peerId);
|
||||||
|
|
||||||
|
if (peer && peer.roomId !== state.roomId) // The peer is mischievous
|
||||||
|
throw new Error('peer authenticated with wrong room');
|
||||||
|
|
||||||
peer && (peer.displayName = displayName);
|
peer && (peer.displayName = displayName);
|
||||||
peer && (peer.picture = picture);
|
peer && (peer.picture = picture);
|
||||||
|
|
||||||
if (peer && typeof config.userMapping === 'function')
|
if (peer && typeof config.userMapping === 'function')
|
||||||
{
|
{
|
||||||
await config.userMapping({ peer, userinfo: req.user._userinfo });
|
await config.userMapping({
|
||||||
|
peer,
|
||||||
|
roomId : state.roomId,
|
||||||
|
userinfo : req.user._userinfo
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(loginHelper({
|
res.send(loginHelper({
|
||||||
|
|
@ -454,7 +462,7 @@ async function runWebSocketServer()
|
||||||
queue.push(async () =>
|
queue.push(async () =>
|
||||||
{
|
{
|
||||||
const room = await getOrCreateRoom({ roomId });
|
const room = await getOrCreateRoom({ roomId });
|
||||||
const peer = new Peer({ id: peerId, socket });
|
const peer = new Peer({ id: peerId, roomId, socket });
|
||||||
|
|
||||||
peers.set(peerId, peer);
|
peers.set(peerId, peer);
|
||||||
|
|
||||||
|
|
@ -480,7 +488,7 @@ async function runWebSocketServer()
|
||||||
|
|
||||||
if (typeof config.userMapping === 'function')
|
if (typeof config.userMapping === 'function')
|
||||||
{
|
{
|
||||||
await config.userMapping({ peer, userinfo: _userinfo });
|
await config.userMapping({ peer, roomId, userinfo: _userinfo });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue