Possibility to configure an OpenID Connect provider on the instance level WIP (#128).
Sign out button for external accounts.
This commit is contained in:
parent
131d9ac22d
commit
2334a5f861
@ -105,6 +105,7 @@ async function initConverse (
|
|||||||
params.allow_url_history_change = chatIncludeMode === 'chat-only'
|
params.allow_url_history_change = chatIncludeMode === 'chat-only'
|
||||||
|
|
||||||
let isAuthenticated: boolean = false
|
let isAuthenticated: boolean = false
|
||||||
|
let isAuthenticatedWithExternalAccount: boolean = false
|
||||||
let isRemoteWithNicknameSet: boolean = false
|
let isRemoteWithNicknameSet: boolean = false
|
||||||
|
|
||||||
// OIDC (OpenID Connect):
|
// OIDC (OpenID Connect):
|
||||||
@ -116,9 +117,11 @@ async function initConverse (
|
|||||||
if (!isRemoteChat) {
|
if (!isRemoteChat) {
|
||||||
localRoomAuthenticatedParams(initConverseParams, auth, params)
|
localRoomAuthenticatedParams(initConverseParams, auth, params)
|
||||||
isAuthenticated = true
|
isAuthenticated = true
|
||||||
|
isAuthenticatedWithExternalAccount = auth.type !== 'peertube'
|
||||||
} else if (remoteAuthenticatedXMPPServer) {
|
} else if (remoteAuthenticatedXMPPServer) {
|
||||||
remoteRoomAuthenticatedParams(initConverseParams, auth, params)
|
remoteRoomAuthenticatedParams(initConverseParams, auth, params)
|
||||||
isAuthenticated = true
|
isAuthenticated = true
|
||||||
|
isAuthenticatedWithExternalAccount = auth.type !== 'peertube'
|
||||||
} else if (remoteAnonymousXMPPServer) {
|
} else if (remoteAnonymousXMPPServer) {
|
||||||
// remote server does not allow remote authenticated users, falling back to anonymous mode
|
// remote server does not allow remote authenticated users, falling back to anonymous mode
|
||||||
remoteRoomAnonymousParams(initConverseParams, auth, params)
|
remoteRoomAnonymousParams(initConverseParams, auth, params)
|
||||||
@ -165,10 +168,14 @@ async function initConverse (
|
|||||||
// no viewer mode if authenticated.
|
// no viewer mode if authenticated.
|
||||||
params.livechat_enable_viewer_mode = autoViewerMode && !isAuthenticated && !isRemoteWithNicknameSet
|
params.livechat_enable_viewer_mode = autoViewerMode && !isAuthenticated && !isRemoteWithNicknameSet
|
||||||
|
|
||||||
|
params.livechat_specific_external_authent = isAuthenticatedWithExternalAccount
|
||||||
|
|
||||||
if (tryOIDC && !isAuthenticated) {
|
if (tryOIDC && !isAuthenticated) {
|
||||||
params.livechat_external_auth_oidc_button_label = initConverseParams.externalAuthOIDC?.buttonLabel
|
params.livechat_external_auth_oidc_button_label = initConverseParams.externalAuthOIDC?.buttonLabel
|
||||||
params.livechat_external_auth_oidc_url = initConverseParams.externalAuthOIDC?.url
|
params.livechat_external_auth_oidc_url = initConverseParams.externalAuthOIDC?.url
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tryOIDC) { // also needed when authenticated (for the signout button)
|
||||||
switch (chatIncludeMode) {
|
switch (chatIncludeMode) {
|
||||||
case 'peertube-video':
|
case 'peertube-video':
|
||||||
params.livechat_external_auth_reconnect_mode = 'button-close-open'
|
params.livechat_external_auth_reconnect_mode = 'button-close-open'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
interface AuthentInfos {
|
interface AuthentInfos {
|
||||||
|
type: 'peertube' | 'oidc'
|
||||||
jid: string
|
jid: string
|
||||||
password: string
|
password: string
|
||||||
nickname?: string
|
nickname?: string
|
||||||
@ -87,7 +88,8 @@ async function getLocalAuthentInfos (
|
|||||||
return {
|
return {
|
||||||
jid: data.jid,
|
jid: data.jid,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
nickname: data.nickname
|
nickname: data.nickname,
|
||||||
|
type: data.type ?? 'peertube'
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
@ -2,6 +2,51 @@ export const livechatSpecificsPlugin = {
|
|||||||
dependencies: ['converse-muc', 'converse-muc-views'],
|
dependencies: ['converse-muc', 'converse-muc-views'],
|
||||||
initialize: function (this: any) {
|
initialize: function (this: any) {
|
||||||
const _converse = this._converse
|
const _converse = this._converse
|
||||||
|
|
||||||
|
_converse.api.settings.extend({
|
||||||
|
// if user is authenticated with an external account (to add a logout button)
|
||||||
|
livechat_specific_external_authent: false
|
||||||
|
})
|
||||||
|
|
||||||
|
_converse.api.listen.on('getHeadingButtons', (view: any, buttons: any[]) => {
|
||||||
|
if (view.model.get('type') !== _converse.CHATROOMS_TYPE) {
|
||||||
|
// only on MUC.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_converse.api.settings.get('livechat_specific_external_authent')) {
|
||||||
|
// Adding a logout button
|
||||||
|
buttons.push({
|
||||||
|
i18n_text: _converse.__('Log out'),
|
||||||
|
handler: async (ev: Event) => {
|
||||||
|
ev.preventDefault()
|
||||||
|
ev.stopPropagation()
|
||||||
|
|
||||||
|
const messages = [_converse.__('Are you sure you want to leave this groupchat?')]
|
||||||
|
const result = await _converse.api.confirm(_converse.__('Confirm'), messages)
|
||||||
|
if (!result) { return }
|
||||||
|
|
||||||
|
// Deleting access token in sessionStorage.
|
||||||
|
window.sessionStorage.removeItem('peertube-plugin-livechat-oidc-token')
|
||||||
|
|
||||||
|
const reconnectMode = _converse.api.settings.get('livechat_external_auth_reconnect_mode')
|
||||||
|
if (reconnectMode === 'button-close-open') {
|
||||||
|
const button = document.getElementsByClassName('peertube-plugin-livechat-button-close')[0]
|
||||||
|
if ((button as HTMLAnchorElement).click) { (button as HTMLAnchorElement).click() }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.reload()
|
||||||
|
},
|
||||||
|
a_class: 'close-chatbox-button',
|
||||||
|
icon_class: 'fa-sign-out-alt',
|
||||||
|
name: 'signout'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons
|
||||||
|
})
|
||||||
|
|
||||||
_converse.api.listen.on('chatRoomViewInitialized', function (this: any, _model: any): void {
|
_converse.api.listen.on('chatRoomViewInitialized', function (this: any, _model: any): void {
|
||||||
// Remove the spinner if present...
|
// Remove the spinner if present...
|
||||||
document.getElementById('livechat-loading-spinner')?.remove()
|
document.getElementById('livechat-loading-spinner')?.remove()
|
||||||
@ -39,7 +84,8 @@ export const livechatSpecificsPlugin = {
|
|||||||
'livechat_enable_viewer_mode',
|
'livechat_enable_viewer_mode',
|
||||||
'livechat_external_auth_oidc_button_label', 'livechat_external_auth_oidc_url',
|
'livechat_external_auth_oidc_button_label', 'livechat_external_auth_oidc_url',
|
||||||
'livechat_external_auth_reconnect_mode',
|
'livechat_external_auth_reconnect_mode',
|
||||||
'livechat_mini_muc_head'
|
'livechat_mini_muc_head',
|
||||||
|
'livechat_specific_external_authent'
|
||||||
]) {
|
]) {
|
||||||
_converse.api.settings.set(k, params[k])
|
_converse.api.settings.set(k, params[k])
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ async function initAuthApiRouter (options: RegisterServerOptions, router: Router
|
|||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
jid: unserializedToken.jid,
|
jid: unserializedToken.jid,
|
||||||
password: unserializedToken.password,
|
password: unserializedToken.password,
|
||||||
nickname: unserializedToken.nickname
|
nickname: unserializedToken.nickname,
|
||||||
|
type: 'oidc'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -59,7 +60,8 @@ async function initAuthApiRouter (options: RegisterServerOptions, router: Router
|
|||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
jid: normalizedUsername + '@' + prosodyDomain,
|
jid: normalizedUsername + '@' + prosodyDomain,
|
||||||
password: password,
|
password: password,
|
||||||
nickname: nickname
|
nickname: nickname,
|
||||||
|
type: 'peertube'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user