Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@555platform/author.js
Advanced tools
Isomorphic Javascript toolkit for OAuth 2.0 with 555 Platform
Full API documentation is here
From npm
npm install @555platform/Author.js
import { WebAuth } from '@555platform/Author.js';
const webAuth = WebAuth({
domain: config.domain,
clientID: config.clientID,
responseType: 'code',
redirectURI: config.redirectURI,
scope: 'everything',
authServer: config.authServer
});
The above is example of typical initialization of client side SDK. authServer
field is optional and it will default to 555 Platform production server.
Available response types are code
, token
, id_token
, and id_token token
.
Sample initialization on server side. Note, currently SDK helper functions support only express.js.
serverAuth = ServerAuth({
domain: config.domain,
clientID: config.clientID,
clientSecret: config.clientSecret,
redirectURI: config.redirectURI,
authServer: config.authServer
});
When using response type code you will need to initiate login from the client side that will take you to 555 Platform login screen. After successful login 555 Platform will redirect to URI that should be implemented on application server. In order to implement this flow we will need code on both client and server. Let's start with the client code first.
const webAuth = WebAuth({
domain: config.domain,
clientID: config.clientID,
responseType: 'code',
redirectURI: config.redirectURI,
scope: 'everything',
authServer: config.authServer
});
webAuth.login({ state: 'xyz' });
Above code will initialize client side of SDK and initiate login flow with response type code.
Now on the server side we will need to create basic set up with express.js. In the index.js file:
const express = require('express');
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: ['victor is a cool cat']
})
);
require('./routes/authRoutes')(app);
const PORT = process.env.PORT || 3033;
app.listen(PORT);
Since we will be using cookie to store 555 Platform access token we also included cookie-session
module.
Next we need to create route that will handle redirect from login page. In file routes/authRoutes.js
add the following code:
const { ServerAuth } = require('@555platform/Author.js');
const config = require('./config');
serverAuth = ServerAuth({
domain: config.domain,
clientID: config.clientID,
clientSecret: config.clientSecret,
redirectURI: config.redirectURI,
authServer: config.authServer
});
serverAuth.serializeUser(payload => {
return payload.access_token;
});
serverAuth.deserializeUser(payload => {
return payload;
});
module.exports = app => {
app.use(serverAuth.session);
app.get(
'/auth/555/callback',
serverAuth.authenticate({
successRedirect: config.loginSuccess,
failureRedirect: config.loginFailure,
state: 'xyz',
nonce: '123'
})
);
}
The first thing we did is to initialize server side SDK with client ID/secret, redirect URI, domain and optional auth server URL.
Two calls serializeUser
and deserializeUser
are used to put/retrieve access token from the req.user
and req.session.user
.
We are also providing session
middleware that attaches user object to the request.
Finally, we handle /auth/555/callback URI that received code
from 555 Platform. Helper function authenticate
takes care of entire exchange of code for access token and it will redirect to either success or failure URLs as specified above.
It is also possible to control what happens after authenticate
completes code exchange for access token. If you rather not automatically redirect use the following sample code instead to introduce your own logic:
app.get(
'/auth/555/callback',
serverAuth.authenticate({
state: 'xyz',
nonce: '123'
}), (req, res) => {
console.log('AUTH CHECK: ', req.auth)
if (req.auth) {
res.send({message: 'authed'})
return
}
res.status(401).send({message: 'unauthorized'})
}
);
Note: In order to receive authorization data in req.auth
do not pass functions to serializeUser
and deserializeUser
. If you do req.auth
will not contain any data but rather req.user
will contain deserialized information you selected.
For implicit flow you initiate call to login from the client and receive redirected URL with access token and/or id token directly without the need to exchange the code. This is useful if you want to handle authentication directly in the client.
To initiate login with implicit flow call SDK with the following sample code:
import { WebAuth } from '@555platform/Author.js';
.
.
.
const webAuth = WebAuth({
domain: config.domain,
clientID: config.clientID,
responseType: 'id_token token',
redirectURI: config.implicitRedirectURI,
scope: 'openid email',
authServer: config.authServer
});
webAuth.login({ state: 'xyz' });
In this case, after login is completed 555 Platform will redirect to URL specified in redirectURI with the following sample values:
/implicit#access_token=<access_token>&expires_in=216000&id_token=<id_token>&scope=openid+email&state=xyz&token_type=Bearer
FAQs
555 Platform OAuth2 JS SDK
The npm package @555platform/author.js receives a total of 6 weekly downloads. As such, @555platform/author.js popularity was classified as not popular.
We found that @555platform/author.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.