| Crates.io | broker |
| lib.rs | broker |
| version | 15.1.0 |
| created_at | 2020-01-01 05:10:43.619529+00 |
| updated_at | 2021-05-01 01:00:07.110161+00 |
| description | Real-time BaaS (Backend as a Service) |
| homepage | |
| repository | https://github.com/apibillme/broker |
| max_upload_size | |
| id | 194042 |
| size | 136,580 |
The purpose of this service is to be your real-time BaaS (Backend as a Service).
Broker is a SSE message broker that requires you write no backend code to have a full real-time API.
Broker is born from the need that rather than building a complex REST API with web-sockets and a SQL database to provide reactive web forms (like for React) there must be a simpler way.
Broker follows an insert-only/publish/subscribe paradigm rather than a REST CRUD paradigm.
Broker also provides full identity services using JWT, HTTP Basic, Two Factor, and TOTP.
Broker is a competitor to Firebase, Parse Server, Auth0, AWS Cognito, AWS IAM, AWS SimpleDB, and AWS SNS.
In Broker you create a user, login, then insert an event with its data. Broker then publishes the event via SSE.
When the client first subscribes to the SSE connection all the latest events and data is sent to the client. Combined with sending the latest event via SSE when subscribed negates the necessity to do any GET API requests in the lifecycle of an event.
The side-effect of this system is that the latest event is the schema. This is pure NoSQL as the backend is agnostic to the event data.
POST /create_user
{
"username": "bob",
"password": "password1",
"admin_token": "letmein",
"tenant_name": "tenant_1",
"email": "bob@hotmail.com",
"two_factor": true,
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
admin_token is required and can be set in the command args - it is for not allowing everyone to add a user - the default is letmeinemail, scopes, two_factor, and data are optional fieldsscopes are biscuit authority scopes/facts so the first part before the colon is the resource while the second part after the colon is the operation. Don't add any additional colons in the scopes.will return 200 or 500 or 400
POST /login
{
"username": "bob",
"password": "password1",
"totp": "123456",
}
totp is required if two factor is enabled for the user - if not the field can be omittedwill return: 200 or 500 or 400 or 401
200 - will return a JWT
{
"jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTc2NzQ5MTUsImlhdCI6MTYxNzU4ODUxNSwiaXNzIjoiRGlzcGF0Y2hlciIsInN1YiI6ImZvbyJ9.OwiaZJcFUC_B0CA0ffRZVTWKRf5_vQ7vt5USNJEeKRE"
}
note: if you need to debug your JWT then visit jwt.io
GET /sse
note: broker-client uses fetch as eventsource doesn't support headersPOST /insert
{
"event": "test",
"data": {
"name": "robert",
"image": "https://img.com/bucket/123/123.jpg"
}
}
will return: 200 or 500 or 400 or 401
GET /verify
will return: 200 or 500 or 401
200 - will return a biscuit public key, biscuit token, username, and JWT expiry for your microservice (use from_bytes to hydrate the key and token)
{
"key": [136,133,229,196,134,20,240,80,159,158,154,20,57,35,198,7,156,160,193,224,174,209,51,150,27,86,75,122,172,24,114,66],
"token": [122,133,229,196,134,20,240,80,159,158,154,20,57,35,198,7,156,160,193,224,174,209,51,150,27,86,75,122,172,24,114,121],
"expiry": 1618352841,
"username": "bob",
"scopes": ["news:get", "news:post"]
}
POST /revoke_user
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
POST /unrevoke_user
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
POST /list_users
{
"admin_token": "letmein"
}
will return: 200 or 500 or 400 or 401
200 - will return an array of objects
[
{
"id": "69123c04-fa42-4193-a6c5-ab2fc27658b1",
"password": "***",
"totp": "***",
"revoked": false,
"tenant_name": "tenant_1",
"username": "bob",
"email": "bob@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
]
email, scopes, two_factor, and data can be nullPOST /get_user
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
200 - will return an array of objects
{
"id": "69123c04-fa42-4193-a6c5-ab2fc27658b1",
"password": "***",
"totp": "***",
"revoked": false,
"tenant_name": "tenant_1",
"username": "bob",
"email": "bob@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Wieland",
"image": "https://img.com/bucket/123/123.jpg"
}
}
email, scopes, two_factor, and data can be nullPOST /update_user
{
"admin_token": "letmein",
"username": "bob",
"tenant_name": "tenant_2",
"password": "new_password",
"email": "bober@hotmail.com",
"scopes": ["news:get", "news:post"],
"data": {
"name": "Robert Falcon",
"image": "https://img.com/bucket/123/1234.jpg"
}
}
tenant_name, password, email, scopes, data are optional fieldswill return: 200 or 500 or 400 or 401
GET or HEAD /
will return: 200
POST /create_qr
{
"issuer": "Broker",
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
200 - will return the qr code in PNG format in base64
{
"qr": "dGhpc2lzYXN0cmluZw=="
}
POST /create_totp
{
"admin_token": "letmein",
"username": "bob"
}
will return: 200 or 500 or 400 or 401
200 - will return the totp
{
"totp": "622346"
}
POST /password_reset
{
"totp": "622346",
"username": "bob",
"password": "password1"
}
will return: 200 or 500 or 400 or 401
cargo install broker
origin can be passed in as a flag - default *port can be passed in as a flag - default 8080 - can only be set for unsecure connectionsjwt_expiry for jwts can be passed in as a flag in seconds - default 86400jwt_secret for jwts should be passed in as a flag - default secretsecure flag for https and can be true or false - default falseauto_cert flag for an autorenewing LetsEncrypt SSL cert can be true or false - requires a resolvable domain - default truekey_path flag when auto_cert is false to set the SSL key path for your own cert - default certs/private_key.pemcert_path flag when auto_cert is false to set the SSL cert path for your own cert - default certs/chain.pemcerts flag is the storage path of LetsEncrypt certs - default certsdb flag is the path where the embedded database will be saved - default dbdomain flag is the domain name (e.g. api.broker.com) of the domain you want to register with LetsEncrypt - must be fully resolvableadmin_token flag is the password for the admin to add users - default letmeinpassword_checker flag enables zxcvbn password checking - default falsetotp_duration flag is the duration of the TOTP for user generated password reset - default 300 seconds (5 min)./broker --secure="true" --admin_token"23ce4234@123$" --jwt_secret="xTJEX234$##$" --domain="api.broker.com" --password_checker="true"There is an example systemctl service for Ubuntu called broker.service in the code