Comments (6)
Here's a complete example script showing how to attach a Horizon server to multiple HTTP servers and add an auth endpoint (twitch) at the end. This assumes that a RethinkDB instance is running on localhost:28015
, and that it has been initialized with hz set-schema
.
'use strict';
const horizon = require('@horizon/server');
const fs = require('fs');
const http = require('http');
const https = require('https');
// Attach the horizon server to two http servers
// one on [::]:8181 over HTTPS and one on 127.0.0.1:8282 over HTTP
const on_http_request = (req, res) => {
res.writeHead(404);
res.end('File not found.');
};
const public_server = https.createServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem'),
}, on_http_request);
const loopback_server = http.createServer(on_http_request);
public_server.listen(8181);
loopback_server.listen(8282, '127.0.0.1');
const horizon_server =
horizon([ public_server, loopback_server ],
{
project_name: 'foo',
auth: {
token_secret: 'bar',
allow_anonymous: true,
allow_unauthenticated: true,
},
});
// Add twitch authentication
horizon_server.add_auth_provider(horizon.auth.twitch,
{
path: 'twitch',
id: '0000000000000000000000000000000',
secret: '0000000000000000000000000000000',
});
// Shut down the server after 60 seconds
setTimeout(() => {
horizon_server.close();
public_server.close();
loopback_server.close();
}, 60000);
from horizon-docs.
It also looks like this technique always requires setting up your own HTTP server first. I'm not sure what the requirements on the http_servers
argument actually are.
@Tryneus Could you add some details about this please?
from horizon-docs.
A related question came up on the horizon issue tracker about how to run the Horizon server within Express: rethinkdb/horizon#425 (comment)
from horizon-docs.
One non-obvious aspect of this is configuring OAuth providers. You can't pass the provider options directly into the Server
constructor, but need to call a separate add_auth_endpoint
method on the server.
Here's some example code:
var horizon_server = require('@horizon/server');
var horizon_options = {
auth: {
token_secret: 'xxxx',
allow_anonymous: true,
allow_unauthenticated: true
}
};
// ...
// Code to construct the http_server, e.g. with Express
// ...
var horizon_instance = horizon_server(http_server, horizon_options);
// Add an OAuth endpoint for GitHub
horizon_instance.add_auth_provider(
horizon_server.auth["github"],
{id: "xxxx", secret: "xxxx", path: "github"});
from horizon-docs.
We should also list the other supported options that can be passed into the server constructor.
The full list is represented here: https://github.com/rethinkdb/horizon/blob/next/server/src/schema/server_options.js
from horizon-docs.
@Tryneus What is the meaning of these three options in the auth
field?
duration: Joi.alternatives(Joi.string(), Joi.number().positive()).default('1d'),
create_new_users: Joi.boolean().default(true),
new_user_group: Joi.string().default('authenticated'),
from horizon-docs.
Related Issues (20)
- Upgrade docker-compose files to v2 of the docker-compose file spec HOT 8
- Document integration with specific frameworks (React etc.) HOT 2
- Users doc misleading
- cookbook entry: subscribing to changing data
- Horizon 2.0 docs checklist HOT 27
- Document `Collection.update`, `Collection.insert` and correct existing write commands
- Clarify client constructor host option
- .filter() listed twice in Observable's methods. HOT 1
- We need a guide on "Deploying Horizon"
- New page about Horizon client packaging HOT 2
- Section headers should be clickable to put the fragment in the URL path
- Document admin user requirement
- Permissions only mentions `.find` once but it isn't clear if using `.findAll` covers `.find`? HOT 2
- Auth documentation needs to show boilerplate on how to handle connections by unauth'd and auth'd users
- Embedding docs incorrectly uses `_reql_conn` as a property of the server module HOT 2
- Document how to use JWT generated using CLI
- horizon js can not access rethinkdb in port 28025 without --dev flag . Error : action not permitted .
- Docs at http://horizon.io/docs/auth/ don't say what callback URL to use HOT 8
- Include section in FAQ on why full ReQL queries aren't supported in Horizon
- Document .aggregate and .model HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from horizon-docs.