Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return;
}
console.log(TAG, 'Device connected.', device_id);
// Update the socket on the device.
device.setGatewaySocket(socket, device_token);
// Return because the rest of this function is for connections to the client API.
return;
}
// Client API
const cookies = socket.handshake.headers.cookie ? cookie.parse(socket.handshake.headers.cookie) : {};
// TODO: Allow passing access_token through query params for non-browser clients (e.g. native apps).
if (!cookies.access_token) {
handleAuthenticationError('no access token');
return;
}
function verifyAccessToken () {
return new Promise((resolve, reject) => {
jwt.verify(cookies.access_token, jwt_secret, {issuer: config.api_token_issuer}, (error, claims) => {
if (error) {
reject();
handleAuthenticationError('invalid access token ' + error.name);
return;
}
compileUrl: function(config, url, fillSessionId) {
// Acquire cookie values.
var cstlUrl = $cookieStore.get(CstlConfig['cookie.cstl.url']),
domainId = $cookieStore.get(CstlConfig['cookie.domain.id']),
userId = $cookieStore.get(CstlConfig['cookie.user.id']);
// Inject cstl-service webapp url.
if (angular.isDefined(cstlUrl)) {
url = url.replace(CstlConfig['inject.expr.ctrl.url'], cstlUrl);
if(config){
config.headers.access_token = $.cookie(CstlConfig['cookie.auth.token']);
}
}else if (/@cstl/.test(url)){
window.location.href="index.html";
}
// Inject domain id value.
if (angular.isDefined(domainId)) {
url = url.replace(CstlConfig['inject.expr.domain.id'], domainId);
}
compileUrl: function(config, url, fillSessionId) {
// Acquire cookie values.
var cstlUrl = $cookieStore.get(CstlConfig['cookie.cstl.url']),
domainId = $cookieStore.get(CstlConfig['cookie.domain.id']),
userId = $cookieStore.get(CstlConfig['cookie.user.id']);
// Inject cstl-service webapp url.
if (angular.isDefined(cstlUrl)) {
url = url.replace(CstlConfig['inject.expr.ctrl.url'], cstlUrl);
if(config){
config.headers.access_token = $.cookie(CstlConfig['cookie.auth.token']);
}
}else if (/@cstl/.test(url)){
window.location.href="index.html";
}
// Inject domain id value.
if (angular.isDefined(domainId)) {
url = url.replace(CstlConfig['inject.expr.domain.id'], domainId);
}
// Inject user id value.
if (angular.isDefined(userId)) {
url = url.replace(CstlConfig['inject.expr.user.id'], userId);
}
url = url.replace(';jsessionid=', ''); // remove it if no session
compileUrl: function(config, url, fillSessionId) {
// Acquire cookie values.
var cstlUrl = $cookieStore.get(CstlConfig['cookie.cstl.url']),
domainId = $cookieStore.get(CstlConfig['cookie.domain.id']),
userId = $cookieStore.get(CstlConfig['cookie.user.id']);
// Inject cstl-service webapp url.
if (angular.isDefined(cstlUrl)) {
url = url.replace(CstlConfig['inject.expr.ctrl.url'], cstlUrl);
if(config){
config.headers.access_token = $.cookie(CstlConfig['cookie.auth.token']);
}
}else if (/@cstl/.test(url)){
window.location.href="index.html";
}
// Inject domain id value.
if (angular.isDefined(domainId)) {
url = url.replace(CstlConfig['inject.expr.domain.id'], domainId);
}
compileUrl: function(config, url, fillSessionId) {
// Acquire cookie values.
var cstlUrl = $cookieStore.get(CstlConfig['cookie.cstl.url']),
domainId = $cookieStore.get(CstlConfig['cookie.domain.id']),
userId = $cookieStore.get(CstlConfig['cookie.user.id']);
// Inject cstl-service webapp url.
if (angular.isDefined(cstlUrl)) {
url = url.replace(CstlConfig['inject.expr.ctrl.url'], cstlUrl);
if(config){
config.headers.access_token = $.cookie(CstlConfig['cookie.auth.token']);
}
}else if (/@cstl/.test(url)){
window.location.href="index.html";
}
// Inject domain id value.
if (angular.isDefined(domainId)) {
url = url.replace(CstlConfig['inject.expr.domain.id'], domainId);
http.createServer(function(req, res){
try {
cookie.parseCookie(req);
//cookie.parseRememberMe(req, res, function(req, res){
//
// test
//});
cookie.setCookie();
console.log(req.headers);
res.end(util.inspect(req.headers, null ,true));
} catch (e) { }
}).listen(1337);
// Add Set-Cookie headers before request ends
res.cookies = {};
res.before('headers', function() {
this.setHeader('Set-Cookie', Object.keys(res.cookies).map(function(name) {
return res.cookies[name].serialize();
}));
});
// No request cookies. Carry on.
if (!req.headers.cookie) {
req.cookies = {};
return next();
}
req.cookies = CookieCodec.parse(req.headers.cookie || '');
next();
});
};
{ },
config.PRIVATE_KEY.trim(),
{
"audience": headers.host[0].value,
"subject": auth.getSubject(decodedData),
"expiresIn": config.SESSION_DURATION,
"algorithm": "RS256"
} // Options
), {
path: '/',
maxAge: config.SESSION_DURATION
})
},
{
"key": "Set-Cookie",
"value" : cookie.serialize('NONCE', '', {
path: '/',
expires: new Date(1970, 1, 1, 0, 0, 0, 0)
})
}
],
},
};
callback(null, response);
} else {
unauthorized('Nonce Verification Failed', '', '', callback);
}
}
});
} catch (error) {
setCookie (key, value, options = {}) {
if (!this.options.cookie) {
return
}
const _key = this.options.cookie.prefix + key
const _options = Object.assign({}, this.options.cookie.options, options)
const _value = encodeValue(value)
const serializedCookie = serializeCookie(_key, _value, _options)
if (process.client) {
// Set in browser
document.cookie = serializedCookie
} else if (process.server && this.ctx.res) {
// Send Set-Cookie header from server side
this.ctx.res.setHeader('Set-Cookie', serializedCookie)
}
return value
}
const onCompleted = data => {
// Store the token in cookie
document.cookie = cookie.serialize('token', data.signinUser.token, {
sameSite: true,
path: '/',
maxAge: 30 * 24 * 60 * 60, // 30 days
})
// Force a reload of all the current queries now that the user is
// logged in
client.cache.reset().then(() => {
redirect({}, '/')
})
}