Skip to content

Commit

Permalink
fix: rename "federation" to "federated identity" in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jcabannes committed Jun 6, 2024
1 parent c4abbdf commit 04bddba
Show file tree
Hide file tree
Showing 53 changed files with 503 additions and 466 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
needs: build
steps:
- name: Add hosts for integration tests
run: sudo echo "127.0.0.1 localhost auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federation.example.com opensearch.example.com" | sudo tee -a /etc/hosts
run: sudo echo "127.0.0.1 localhost auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federated-identity.example.com opensearch.example.com" | sudo tee -a /etc/hosts
- uses: actions/checkout@v3
- name: Set up Node LTS
uses: actions/setup-node@v3
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-tom-federation-server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: publish-tom-federation-server
name: publish-tom-federated-identity-service

on:
workflow_call:
Expand All @@ -19,15 +19,15 @@ jobs:
uses: tj-actions/changed-files@v41
with:
files: |
packages/federation-server/**/*
packages/federated-identity-service/**/*
.github/workflows/**
- name: Publish to dockerhub
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: linagora/tom-federation-server
name: linagora/tom-federated-identity-service
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
workdir: "${{ github.workspace }}"
context: .
buildoptions: "-t linagora/tom-federation-server -f packages/federation-server/Dockerfile"
buildoptions: "-t linagora/tom-federated-identity-service -f packages/federated-identity-service/Dockerfile"
tags: "latest,${{ steps.date.outputs.date }}"
2 changes: 1 addition & 1 deletion .github/workflows/publish-tom-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: tj-actions/changed-files@v41
with:
files: |
packages/federation-server/**/*
packages/federated-identity-service/**/*
.github/workflows/**
- name: Publish to dockerhub
uses: elgohr/Publish-Docker-Github-Action@v5
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
name: Build And Test
uses: ./.github/workflows/build-and-test.yml
secrets: inherit
publish-federation-server:
name: Publish Federation Server
uses: ./.github/workflows/publish-tom-federation-server.yml
publish-federated-identity-service:
name: Publish Federated Identity Service
uses: ./.github/workflows/publish-tom-federated-identity-service.yml
needs: [test]
secrets: inherit
publish-tom-server:
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test:
- npm
script:
- cp /etc/hosts ~/hosts.new
- sed -i "s#\tdocker#\tdocker auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federation.example.com#g" ~/hosts.new
- sed -i "s#\tdocker#\tdocker auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federated-identity.example.com#g" ~/hosts.new
- cp -f ~/hosts.new /etc/hosts
- apt-get update && apt-get --assume-yes install ca-certificates curl gnupg coreutils
- install -m 0755 -d /etc/apt/keyrings
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env BASE_URL= \
DATABASE_USER= \
DATABASE_PASSWORD= \
DATABASE_SSL= \
FEDERATION_SERVERS= \
FEDERATED_IDENTITY_SERVICES= \
JITSI_BASE_URL= \
JITSI_JWT_ALGORITHM= \
JITSI_JWT_ISSUER= \
Expand Down Expand Up @@ -45,7 +45,7 @@ env BASE_URL= \
OPENSEARCH_WAIT_FOR_ACTIVE_SHARDS= \
SERVER_NAME= \
TEMPLATE_DIR=/usr/src/app/packages/tom-server/templates \
UDPATE_FEDERATION_HASHES_CRON="3 3 * * *" \
UPDATE_FEDERATED_IDENTITY_HASHES_CRON="3 3 * * *" \
UPDATE_USERS_CRON="*/15 * * * *" \
SMS_API_LOGIN= \
SMS_API_URL= \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ REST API Endpoints documentation is available on https://linagora.github.io/ToM-
[Matrix Identity Service](https://spec.matrix.org/v1.6/identity-service-api/) implementation for Node.js
* [@twake/matrix-invite](./packages/matrix-invite): matrix invitation web application
* [@twake/server](./packages/tom-server): the main Twake Chat Server, extends [@twake/matrix-identity-server](./packages/matrix-identity-server)
* [@twakeg/federation-server](./packages/federation-server): Twake Federation Server
* [@twake/federated-identity-service](./packages/federated-identity-service): Twake Federated Identity Service
* [@twake/config-parser](./packages/config-parser): simple file parser that uses also environment variables
* [@twake/crypto](./packages/crypto): cryptographic methods for Twake Chat
* [@twake/logger](./packages/logger): logger for Twake
Expand Down
2 changes: 1 addition & 1 deletion docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Image are published in docker hub:
* [The ToM Server itself](https://hub.docker.com/r/linagora/tom-server)
* [The Federation Identity Server](https://hub.docker.com/r/linagora/tom-federation-server)
* [The Federated Identity Service](https://hub.docker.com/r/linagora/tom-federated-identity-service)

## The ToM server image

Expand Down
4 changes: 2 additions & 2 deletions packages/federation-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ RUN apt update && apt -y dist-upgrade

WORKDIR /usr/src/app

COPY ./packages/federation-server/server.mjs .
COPY ./packages/federated-identity-service/server.mjs .

COPY ./packages/crypto ./packages/crypto
COPY ./packages/logger ./packages/logger
COPY ./packages/matrix-resolve ./packages/matrix-resolve
COPY ./packages/matrix-identity-server ./packages/matrix-identity-server
COPY ./packages/config-parser ./packages/config-parser
COPY ./packages/federation-server ./packages/federation-server
COPY ./packages/federated-identity-service ./packages/federated-identity-service
COPY .husky .husky
COPY lerna.json ./
COPY tsconfig-build.json ./
Expand Down
30 changes: 15 additions & 15 deletions packages/federation-server/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @twake/federation-server
# @twake/federated-identity-service

Node.js library that implements
[Matrix Identity Service API](https://spec.matrix.org/v1.6/identity-service-api/) and [this proposal](https://github.com/guimard/matrix-spec-proposals/blob/unified-identity-service/proposals/4004-unified-identity-service-view.md)
Expand All @@ -9,22 +9,22 @@ Example using [express](https://www.npmjs.com/package/express):

```js
import express from 'express'
import FederationServer from '@twake/federation-server'
import FederatedIdentityService from '@twake/federated-identity-service'

// if configuration is in default file (/etc/twake/federation-server.conf)
const federationServer = new FederationServer()
// if configuration is in default file (/etc/twake/federated-identity-service.conf)
const federatedIdentityService = new FederatedIdentityService()

// else if configuration is in a different file, set TWAKE_FEDERATION_SERVER_CONF
process.env.TWAKE_FEDERATION_SERVER_CONF = '/path/to/config/file'
const federationServer = new FederationServer()
// else if configuration is in a different file, set TWAKE_FEDERATED_IDENTITY_SERVICE_CONF
process.env.TWAKE_FEDERATED_IDENTITY_SERVICE_CONF = '/path/to/config/file'
const federatedIdentityService = new FederatedIdentityService()

// You can also give configuration directly
const federationServer = new FederationServer(config)
const federatedIdentityService = new FederatedIdentityService(config)

const app = express()

federationServer.ready.then( () => {
app.use(federationServer.routes)
federatedIdentityService.ready.then( () => {
app.use(federatedIdentityService.routes)
app.listen(3000)
})
```
Expand All @@ -36,15 +36,15 @@ in [src/config.json](./src/config.json).

## How to use it with a client

Sending requests to the federation server requires to be logged on this server. The token allowing to send requests to Tom-server does not work with the federation server.
Sending requests to the federated identity service requires to be logged on this server. The token allowing to send requests to Tom-server does not work with the federated identity service.

After the user signed in, the client has to send a GET request to `/.well-known/matrix/client` endpoint or `/.well-known/twake/client` endpoint. If the response body contains the `m.federation_servers` key then at least one federation server is available. Keep the value of the `base_urls` field that you will find inside the `m.federation_servers` object.
After the user signed in, the client has to send a GET request to `/.well-known/matrix/client` endpoint or `/.well-known/twake/client` endpoint. If the response body contains the `m.federated_identity_services` key then at least one federated identity service is available. Keep the value of the `base_urls` field that you will find inside the `m.federated_identity_services` object.

These are the steps to obtain a token that works on the federation server:
These are the steps to obtain a token that works on the federated identity service:
1. Send a POST request to the URL `https://<matrix_server_address>/_matrix/client/v3/user/<userId>/openid/request_token`, you have to replace `matrix_server_address` by the address of the Matrix server selected by the user, and `userId` by the Matrix id of the user. The request body has to be empty and you have to set the `Authorization` header with the value `Bearer <user_matrix_token>` where `user_matrix_token` is the token retrieved on sign in. For more details see [Matrix specification](https://spec.matrix.org/v1.8/client-server-api/#post_matrixclientv3useruseridopenidrequest_token). **NB**: The `access_token` given in response can be used to register into any Matrix identity service or to ask for a Token exchange into a [yadd/lemonldap-ng-portal](https://github.com/guimard/llng-docker) server
2. The response body of the previous request now should be sent to the URL `https://<federation_server>/_matrix/identity/v2/account/register`. `federation_server` has to be replaced by each federation server address retrieved in the response body of the request sent on the first step. One request by federation server. The `Authorization` header does not need to be set. If the request does not work, maybe the value of `matrix_server_name` in the body is not the good one.
2. The response body of the previous request now should be sent to the URL `https://<federated_identity_service>/_matrix/identity/v2/account/register`. `federated_identity_service` has to be replaced by each federated identity service address retrieved in the response body of the request sent on the first step. One request by federated identity service. The `Authorization` header does not need to be set. If the request does not work, maybe the value of `matrix_server_name` in the body is not the good one.
For more details see [Matrix specification](https://spec.matrix.org/v1.8/identity-service-api/#post_matrixidentityv2accountregister)
* The response body JSON of each request will contain a `token` field whose the value will allow to be authenticated on the matching federation server.
* The response body JSON of each request will contain a `token` field whose the value will allow to be authenticated on the matching federated identity service.

## Copyright and license

Expand Down
8 changes: 4 additions & 4 deletions packages/federation-server/example/federation-server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import express from 'express'

import FederationServer from '@twake/federation-server'
import FederatedIdentityService from '@twake/federated-identity-service'

const federationServer = new FederationServer({
const federatedIdentityService = new FederatedIdentityService({
database_host: ':memory:'
})

const app = express()

federationServer.ready
federatedIdentityService.ready
.then(() => {
app.use(federationServer.routes)
app.use(federatedIdentityService.routes)
const port = process.argv[2] != null ? parseInt(process.argv[2]) : 3000
console.log(`Listening on port ${port}`)
app.listen(port)
Expand Down
11 changes: 6 additions & 5 deletions packages/federation-server/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@twake/federation-server",
"name": "@twake/federated-identity-service",
"version": "0.0.1",
"description": "This is the Twake Federation server",
"description": "This is the Twake Federated Identity Service",
"keywords": [
"federation",
"identity",
"twake",
"server"
"service"
],
"homepage": "https://ci.linagora.com/publicgroup/oss/twake/tom-server",
"bugs": {
Expand Down Expand Up @@ -33,9 +34,9 @@
],
"scripts": {
"build": "npm run build:lib && npm run build:example",
"build:example": "rollup -p @rollup/plugin-typescript -e express,@twake/federation-server -m -o example/federation-server.js example/federation-server.ts",
"build:example": "rollup -p @rollup/plugin-typescript -e express,@twake/federated-identity-service -m -o example/federated-identity-service.js example/federated-identity-service.ts",
"build:lib": "rollup -c",
"start": "node example/federation-server.js",
"start": "node example/federated-identity-service.js",
"test": "jest"
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/federation-server/server.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FederationServer from '@twake/federation-server'
import FederatedIdentityService from '@twake/federated-identity-service'
import express from 'express'
import path from 'node:path'
import { fileURLToPath } from 'url'
Expand All @@ -16,7 +16,7 @@ const conf = {
database_user: process.env.DATABASE_USER,
database_password: process.env.DATABASE_PASSWORD,
hashes_rate_limit: process.env.HASHES_RATE_LIMIT,
is_federation_server: true,
is_federated_identity_service: true,
ldap_base: process.env.LDAP_BASE,
ldap_filter: process.env.LDAP_FILTER,
ldap_user: process.env.LDAP_USER,
Expand Down Expand Up @@ -48,9 +48,9 @@ const conf = {
trusted_servers_addresses: process.env.TRUSTED_SERVERS_ADDRESSES
}

const federationServer = new FederationServer(conf)
const federatedIdentityService = new FederatedIdentityService(conf)
const app = express()
const promises = [federationServer.ready]
const promises = [federatedIdentityService.ready]

if (process.env.CROWDSEC_URI) {
if (!process.env.CROWDSEC_KEY) {
Expand All @@ -76,7 +76,7 @@ if (process.env.CROWDSEC_URI) {

Promise.all(promises)
.then(() => {
app.use(federationServer.routes)
app.use(federatedIdentityService.routes)
const port = process.argv[2] != null ? parseInt(process.argv[2]) : 3000
console.log(`Listening on port ${port}`)
app.listen(port)
Expand Down
2 changes: 1 addition & 1 deletion packages/federation-server/src/__testData__/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"database_engine": "sqlite",
"database_host": "./src/__testData__/database.db",
"database_vacuum_delay": 3600,
"is_federation_server": true,
"is_federated_identity_service": true,
"key_delay": 3600,
"keys_depth": 5,
"ldap_base": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

psql -U postgres <<-EOSQL
CREATE USER twake PASSWORD 'twake!1';
CREATE DATABASE federation TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake';
CREATE DATABASE federatedidentity TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake';
CREATE DATABASE identity1 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake';
CREATE DATABASE identity2 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake';
CREATE DATABASE identity3 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='twake';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

psql -U postgres <<-EOSQL
CREATE USER synapse PASSWORD 'synapse!1';
CREATE DATABASE synapsefederation TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse';
CREATE DATABASE synapsefederatedidentity TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse';
CREATE DATABASE synapse1 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse';
CREATE DATABASE synapse2 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse';
CREATE DATABASE synapse3 TEMPLATE='template0' LOCALE='C' ENCODING='UTF8' OWNER='synapse';
Expand Down
24 changes: 12 additions & 12 deletions packages/federation-server/src/__testData__/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ services:
networks:
- test

synapse-federation: &synapse_template
synapse-federated-identity-service: &synapse_template
image: matrixdotorg/synapse:v1.89.0
container_name: synapse-federation
container_name: synapse-federated-identity-service
volumes:
- ./synapse-data:/data
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
Expand All @@ -35,7 +35,7 @@ services:
- UID=${MYUID}
- VIRTUAL_PORT=8008
- VIRTUAL_HOST=matrix.example.com
- SYNAPSE_CONFIG_PATH=/data/homeserver-federation.yaml
- SYNAPSE_CONFIG_PATH=/data/homeserver-federated-identity.yaml
healthcheck:
test: ["CMD", "curl", "-fSs", "http://localhost:8008/health"]
interval: 10s
Expand Down Expand Up @@ -96,17 +96,17 @@ services:
networks:
- test

federation-server:
image: federation-server
container_name: federation-server
federated-identity-service:
image: federated-identity-service
container_name: federated-identity-service
build:
context: ../../../..
dockerfile: ./packages/federation-server/Dockerfile
dockerfile: ./packages/federated-identity-service/Dockerfile
volumes:
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
- ./federation-server/federation-server.conf:/etc/twake/federation-server.conf
- ./federated-identity-service/federated-identity-service.conf:/etc/twake/federated-identity-service.conf
depends_on:
synapse-federation:
synapse-federated-identity-service:
condition: service_started
identity-server-1:
condition: service_started
Expand All @@ -117,7 +117,7 @@ services:
environment:
- NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca.pem
- VIRTUAL_PORT=3000
- VIRTUAL_HOST=federation.example.com
- VIRTUAL_HOST=federated-identity.example.com
networks:
- test

Expand All @@ -126,7 +126,7 @@ services:
container_name: identity-server-1
build:
context: ../../../..
dockerfile: ./packages/federation-server/src/__testData__/identity-server/Dockerfile
dockerfile: ./packages/federated-identity-service/src/__testData__/identity-server/Dockerfile
volumes:
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
- ./identity-server/conf/identity-server-1.conf:/etc/twake/identity-server.conf
Expand Down Expand Up @@ -196,7 +196,7 @@ services:
- matrix2.example.com
- matrix3.example.com
- auth.example.com
- federation.example.com
- federated-identity.example.com

networks:
test:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"additional_features": true,
"cron_service": true,
"base_url": "https://federation.example.com/",
"base_url": "https://federated-identity.example.com/",
"database_engine": "pg",
"database_host": "postgresql",
"database_name": "federation",
"database_name": "federatedidentity",
"database_user": "twake",
"database_password": "twake!1",
"is_federation_server": true,
"is_federated_identity_service": true,
"ldap_base": "dc=example,dc=com",
"ldap_uri": "ldap://annuaire",
"matrix_database_engine": "pg",
"matrix_database_host": "postgresql",
"matrix_database_name": "synapsefederation",
"matrix_database_name": "synapsefederatedidentity",
"matrix_database_password": "synapse!1",
"matrix_database_user": "synapse",
"pepperCron": "*/60 * * * * *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apt update && apt -y dist-upgrade

WORKDIR /usr/src/app

COPY ./packages/federation-server/src/__testData__/identity-server/server.mjs .
COPY ./packages/federated-identity-service/src/__testData__/identity-server/server.mjs .

COPY ./packages/matrix-identity-server ./packages/matrix-identity-server
COPY ./packages/logger ./packages/logger
Expand Down
Loading

0 comments on commit 04bddba

Please sign in to comment.