项目作者: matrix-org

项目描述 :
Service to verify details of a user based on a Open ID token.
高级语言: JavaScript
项目地址: git://github.com/matrix-org/matrix-user-verification-service.git
创建时间: 2020-08-26T11:41:54Z
项目社区:https://github.com/matrix-org/matrix-user-verification-service

开源协议:Other

下载


Matrix User Verification Service

Service to verify details of a user based on an Open ID Connect token.

Main features:

  • Verifies a C2S Open ID token
    using the S2S UserInfo endpoint.
  • Can verify user is a member in a given room (Synapse only currently, requires admin level token).
    In addition to returning membership status, returned will be user power level, the room power
    defaults and required power for events.

How to use

Dependencies

  1. npm install

Configuration

Copy the default .env.default to .env and modify as needed.

  1. ## REQUIRED
  2. # Homeserver client API admin token (synapse only)
  3. # Required for the service to verify room membership
  4. UVS_ACCESS_TOKEN=foobar
  5. # Homeserver client API URL
  6. UVS_HOMESERVER_URL=https://matrix.org
  7. # Disable check for non private IP range of homeserver. E.g. set to `true` if your homeserver domain resolves to a private IP.
  8. UVS_DISABLE_IP_BLACKLIST=true
  9. ## OPTIONAL
  10. # Auth token to protect the API
  11. # If this is set any calls to the provided API endpoints
  12. # need have the header "Authorization: Bearer changeme".
  13. UVS_AUTH_TOKEN=changeme
  14. # Matrix server name to verify OpenID tokens against. See below section.
  15. # Defaults to empty value which means verification is made against
  16. # whatever Matrix server name passed in with the token.
  17. UVS_OPENID_VERIFY_SERVER_NAME=matrix.org
  18. # Listen address of the bot
  19. UVS_LISTEN_ADDRESS=127.0.0.1
  20. # Listen port of the bot
  21. UVS_PORT=3000
  22. # Log level, defaults to 'info'
  23. # See choices here: https://github.com/winstonjs/winston#logging-levels
  24. UVS_LOG_LEVEL=info

OpenID token verification

UVS can run in a single homeserver mode or be configured to trust any
homeserver OpenID token. Default is to trust the any Matrix server name
that is given with the OpenID token.

To disable this and ensure only OpenID tokens from a single Matrix homeserver
will be trusted, set the homeserver Matrix server name in the variable
UVS_OPENID_VERIFY_SERVER_NAME. Note, this is the server name of the homeserver,
not the client or federation API’s domain.

In either mode, the UserInfo endpoint
is determined by resolving server names in the usual way
so a /.well-known/matrix/server file may be needed even if the homeserver
isn’t otherwise federating. If the homeserver config doesn’t have the federation
listener setup, the openid listener can be added on the same port as the client
listener.

Room membership is still currently limited to be verified from a single
configured homeserver client API via UVS_HOMESERVER_URL.

API’s available

Authentication

If UVS_AUTH_TOKEN is set, you’ll need to provide an authorization header as follows:

  1. Authorization: Bearer <value of UVS_AUTH_TOKEN>

Verify OpenID token

Verifies a user OpenID token.

  1. POST /verify/user
  2. Content-Type: application/json

Request body:

  1. {
  2. "matrix_server_name": "domain.tld",
  3. "token": "secret OpenID token provided by the user"
  4. }

Successful validation response:

  1. {
  2. "results": {
  3. "user": true
  4. },
  5. "user_id": "@user:domain.tld"
  6. }

Failed validation:

  1. {
  2. "results": {
  3. "user": false
  4. },
  5. "user_id": null
  6. }

Verify OpenID token and room membership

Verifies a user OpenID token and membership in a room.

  1. POST /verify/user_in_room
  2. Content-Type: application/json

Request body:

  1. {
  2. "matrix_server_name": "domain.tld",
  3. "room_id": "!foobar:domain.tld",
  4. "token": "secret OpenID token provided by the user"
  5. }

Successful validation response:

  1. {
  2. "results": {
  3. "room_membership": true,
  4. "user": true
  5. },
  6. "user_id": "@user:domain.tld",
  7. "power_levels": {
  8. "room": {
  9. "ban": 50,
  10. "events": {
  11. "m.room.avatar": 50,
  12. "m.room.canonical_alias": 50,
  13. "m.room.history_visibility": 100,
  14. "m.room.name": 50,
  15. "m.room.power_levels": 100
  16. },
  17. "events_default": 0,
  18. "invite": 0,
  19. "kick": 50,
  20. "redact": 50,
  21. "state_default": 50,
  22. "users_default": 0
  23. },
  24. "user": 50
  25. }
  26. }

Failed validation, in case token is not valid:

  1. {
  2. "results": {
  3. "room_membership": false,
  4. "user": false
  5. },
  6. "user_id": null,
  7. "power_levels": null
  8. }

In the token was validated but user is not in room, the failed response is:

  1. {
  2. "results": {
  3. "room_membership": false,
  4. "user": true
  5. },
  6. "user_id": "@user:domain.tld",
  7. "power_levels": null
  8. }

Running

  1. npm start

Development

Run in watch mode.

  1. npm run dev

License

Apache 2.0