Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions scaffoldTpl/app.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,79 @@
let express = require('express');
let path = require('path');
let favicon = require('serve-favicon');
let logger = require('morgan');
let cookieParser = require('cookie-parser');
let bodyParser = require('body-parser');
let express = require("express");
let path = require("path");
let favicon = require("serve-favicon");
let logger = require("morgan");
let cookieParser = require("cookie-parser");
let bodyParser = require("body-parser");

let index = require('./routes/index');
let users = require('./routes/users');
let index = require("./routes/index");
let users = require("./routes/users");

let app = express();

const staffbaseKey = null;
const pluginID = null;
let ssoMiddleWare;
ssoMiddleWare = require('@staffbase/staffbase-plugin-sdk').middleware(staffbaseKey, pluginID);

ssoMiddleWare = require("@staffbase/staffbase-plugin-sdk").middleware(
staffbaseKey,
pluginID
);

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, "public")));

app.use('/', index);
app.use('/users', users);
app.use("/", index);
app.use("/users", users);

// Frontend Handler
app.use('/frontEnd', ssoMiddleWare);
app.get('/frontEnd', function(req, res) {
res.render('plugin', req.sbSSO);
app.use("/frontEnd", ssoMiddleWare);
app.get("/frontEnd", function (req, res) {
res.render("plugin", req.sbSSO);
});

// Setup SSO Milleware on the endpoint server
app.use('/staffbase/sso/backoffice', ssoMiddleWare);
app.use("/staffbase/sso/backoffice", ssoMiddleWare);

// Handle SSO response from server with decoded data
app.get('/staffbase/sso/backoffice', function(req, res) {
app.get("/staffbase/sso/backoffice", function (req, res) {
// Middleware was able to decode the token
if (req.sbSSO) {
console.log('Decoded data on backend(admin):', req.sbSSO);
res.render('plugin', req.sbSSO);
console.log("Decoded data on backend(admin):", req.sbSSO);
res.render("plugin", req.sbSSO);
return res.end();
}
res.json({
error: {
msg: 'Unable to get token information.',
msg: "Unable to get token information.",
},
});
return res.end();
});

// catch 404 and forward to error handler
app.use(function(req, res, next) {
let err = new Error('Not Found');
app.use(function (req, res, next) {
let err = new Error("Not Found");
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.locals.error = req.app.get("env") === "development" ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
res.render("error");
});

module.exports = app;
117 changes: 77 additions & 40 deletions scaffoldTpl/views/index.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,97 @@
<p><img src="https://staffbase.com/wp-content/themes/staffbase-theme/img/logo-blau.svg" alt="Staffbase Logo"></p>
<p>Welcome to your Staffbase SSO plugin server. Please follow the following instructions
to get started with your Plugin Application.</p>
<p>
<img
src="https://staffbase.com/wp-content/themes/staffbase-theme/img/logo-blau.svg"
alt="Staffbase Logo"
/>
</p>
<p>
Welcome to your Staffbase SSO plugin server. Please follow the following
instructions to get started with your Plugin Application.
</p>
<h2>Prerequisites</h2>
<p>In order to get connected with the Staffbase SSO interface, you need a Valid Secret and an Audience ID.</p>
<p>If you are here, you probably have a secret and audience ID registered with Staffbase. If you are not sure about it or you need more information about Staffbase SSO, feel free to contact the Customer Success team at Staffbase.</p>
<p>
In order to get connected with the Staffbase SSO interface, you need a Valid
Secret and an Audience ID.
</p>
<p>
If you are here, you probably have a secret and audience ID registered with
Staffbase. If you are not sure about it or you need more information about
Staffbase SSO, feel free to contact the Customer Success team at Staffbase.
</p>
<h2>Configuration</h2>
<p>After the scaffolding is complete, you need to provide some values for configuring your
plugin server. The following values need to be configured.</p>
<p>
After the scaffolding is complete, you need to provide some values for
configuring your plugin server. The following values need to be configured.
</p>
<ul>
<li>Plugin Secret</li>
<li>Plugin Audience</li>
<li>Plugin Secret</li>
<li>Plugin Audience</li>
</ul>
<p>You can either specify these values in environment variables or directly passing
the values in the <code>app.js</code> file where the middleware is initialized.</p>
<p>To configure values in <code>app.js</code> file, change the following lines:</p>
<p>
You can either specify these values in environment variables or directly
passing the values in the <code>app.js</code> file where the middleware is
initialized.
</p>
<p>
To configure values in <code>app.js</code> file, change the following lines:
</p>
<p>app.js</p>
<pre><code class="language-javascript">12 ...
13 ...
14 const key = null;
15 const pluginID = null;
16 ...
</code></pre>
<p>You can also specify these values using environment variables.
Refer to the table to see which environment variables can be used.</p>
<p>
You can also specify these values using environment variables. Refer to the
table to see which environment variables can be used.
</p>
<table>
<thead>
<tr>
<th style="text-align:left"><em>Value</em></th>
<th style="text-align:center"><em>Environment Variable</em></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Secret</td>
<td style="text-align:center">STAFFBASE_SSO_SECRET</td>
</tr>
<tr>
<td style="text-align:left">Audience</td>
<td style="text-align:center">STAFFBASE_SSO_AUDIENCE</td>
</tr>
<tr>
<td style="text-align:left">Server Port</td>
<td style="text-align:center">PORT</td>
</tr>
</tbody>
<thead>
<tr>
<th style="text-align: left"><em>Value</em></th>
<th style="text-align: center"><em>Environment Variable</em></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">Secret</td>
<td style="text-align: center">STAFFBASE_SSO_SECRET</td>
</tr>
<tr>
<td style="text-align: left">Audience</td>
<td style="text-align: center">STAFFBASE_SSO_AUDIENCE</td>
</tr>
<tr>
<td style="text-align: left">Server Port</td>
<td style="text-align: center">PORT</td>
</tr>
</tbody>
</table>
<h2>Running the server</h2>
<p><em>create-staffbase-plugin</em> installs the project dependencies for you.
After configurations is done, the only thing you need to do is navigate to the
folder where your app was generated and start the express server.</p>
<p>
<em>create-staffbase-plugin</em> installs the project dependencies for you.
After configurations is done, the only thing you need to do is navigate to the
folder where your app was generated and start the express server.
</p>
<pre><code class="language-bash">$ cd [path of generated app]
$ npm start
</code></pre>
<h2>Further Reading</h2>
<p>For getting more information about Staffbase SSO, please check out the following links:</p>
<p>
For getting more information about Staffbase SSO, please check out the
following links:
</p>
<ul>
<li><a href="https://developers.staffbase.com/concepts/customplugin-overview/">Developer Portal: Custom Plugins</a></li>
<li><a href="https://github.com/Staffbase/plugins-sdk-nodejs/blob/master/README.MD">Staffbase Plugins SDK for Node.js</a></li>
<li>
<a href="https://developers.staffbase.com/concepts/customplugin-overview/"
>Developer Portal: Custom Plugins</a
>
</li>
<li>
<a
href="https://github.com/Staffbase/plugins-sdk-nodejs/blob/master/README.md"
>Staffbase Plugins SDK for Node.js</a
>
</li>
</ul>