Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

corbado

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

corbado - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

.github/workflow/build.yml

12

package.json
{
"name": "corbado",
"version": "1.0.2",
"version": "1.1.0",
"description": "",
"main": "./src/corbado.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.js"
"test": "mocha --reporter spec"
},

@@ -27,7 +26,10 @@ "repository": {

"dependencies": {
"assert": "^2.0.0",
"axios": "^1.3",
"jose": "^4.14.4"
},
"devDependencies": {
"chai": "^4.3.7",
"mocha": "^10.2.0",
"sinon": "^15.0.4"
"mocha": "^10.2.0"
}
}
const PasskeyService = require('./services/passkey.service');
const EmailLinkService = require('./services/emaillink.service');
const ShortSession = require('./services/shortsession.service');
const SessionService = require('./services/session.service');
const getClientInfo = require('./utils/clientInfo.utils');
const assert = require('assert')
class Corbado {
const EMAIL_TEMPLATES = {
EMAIL_SIGN_UP_TEMPLATE: 'email_signup_user',
EMAIL_LOGIN_TEMPLATE: 'email_login_user',
PASSKEY_SIGN_UP_TEMPLATE: 'webauthn_signup_user',
PASSKEY_LOGIN_TEMPLATE: 'webauthn_login_user',
}
#shortSession = null
#passkeyService = null
#emailLinkService = null
#sessionService = null
const API_URL = 'https://api.corbado.com/v1/';
/**
* @type {Configuration}
*/
#config = null
class Corbado {
/**
*
* @param {Configuration} config
*/
constructor(config) {
this.#config = config
}
/**
* @param {string} projectID Project ID from https://app.corbado.com/
* @param {string} apiSecret Api secret from https://app.corbado.com/app/settings/credentials/api-keys
* @param {string} baseURL Optional different api url
*
* @returns {PasskeyService}
*/
constructor(projectID, apiSecret, baseURL = API_URL) {
get passkey() {
if (this.#passkeyService === null) {
this.#passkeyService = new PasskeyService(
this.#config.projectID,
this.#config.apiSecret,
this.#config.apiURL,
this.emailLink,
)
}
if (!projectID) {
throw new Error('Project ID is required');
} else if (projectID.substr(0, 4) !== 'pro-') {
throw new Error('Project ID is invalid');
return this.#passkeyService
}
/**
*
* @returns {EmailLinkService}
*/
get emailLink() {
if (this.#emailLinkService === null) {
this.#emailLinkService = new EmailLinkService(
this.#config.projectID,
this.#config.apiSecret,
this.#config.apiURL,
this.#config.emailTemplates,
)
}
if (!apiSecret) {
throw new Error('API secret is required');
return this.#emailLinkService
}
/**
*
* @returns {SessionService}
*/
get session() {
if (this.#sessionService === null) {
this.#sessionService = new SessionService(
this.#config.projectID,
this.#config.apiSecret,
this.#config.apiURL,
)
}
this.passkeyService = new PasskeyService(projectID, apiSecret, baseURL);
this.emailLinkService = new EmailLinkService(projectID, apiSecret, baseURL, EMAIL_TEMPLATES);
this.sessionService = new SessionService(projectID, apiSecret, baseURL);
this.utils = {getClientInfo};
return this.#sessionService
}
/**
*
* @returns {ShortSession}
*/
get shortSession() {
if (this.#shortSession === null) {
assert(this.#config.issuer !== undefined, 'Issuer undefined')
assert(this.#config.issuer.length > 0, 'Issuer is empty')
assert(this.#config.jwksURI !== undefined, 'Issuer undefined')
assert(this.#config.jwksURI.length > 0, 'JWKS uri is empty')
assert(this.#config.cacheMaxAge > 0, 'Cache max age is invalid')
this.#shortSession = new ShortSession(
this.#config.shortSessionCookieName,
this.#config.issuer,
this.#config.jwksURI,
this.#config.cacheMaxAge,
)
}
return this.#shortSession
}
}
module.exports = Corbado;

@@ -28,3 +28,3 @@ const axios = require('axios');

} catch (error) {
throw new CorbadoApiError(error.response.status, error.response.statusText, error.request.method, error.config.url, error.config.data);
throw new CorbadoApiError(error.response.status, error.response.statusText, error.request.method, error.config.url, error.response.data.error);
}

@@ -34,2 +34,2 @@ }

module.exports = CorbadoApi;
module.exports = CorbadoApi;

@@ -16,2 +16,2 @@ class CorbadoApiError extends Error {

module.exports = CorbadoApiError
module.exports = CorbadoApiError

@@ -59,3 +59,3 @@ const CorbadoApi = require('./CorbadoApi');

return await this.corbadoApi.request('emailLinks', 'POST', params);
return await this.corbadoApi.request('/emailLinks', 'POST', params);
};

@@ -88,3 +88,3 @@

}
return await this.corbadoApi.request('emailLinks/' + emailLinkID + '/validate', 'PUT', params);
return await this.corbadoApi.request('/emailLinks/' + emailLinkID + '/validate', 'PUT', params);

@@ -91,0 +91,0 @@ }

@@ -6,6 +6,5 @@ const EmailLinkService = require('./emaillink.service');

constructor(projectID, apiSecret, apiURL, email_templates) {
constructor(projectID, apiSecret, apiURL, emailLinkService) {
this.corbadoApi = new CorbadoApi(projectID, apiSecret, apiURL);
this.emailLinkService = new EmailLinkService(projectID, apiSecret, apiURL, email_templates);
this.emailLinkService = emailLinkService
}

@@ -50,3 +49,3 @@

return await this.corbadoApi.request('webauthn/register/start', 'POST', params);
return await this.corbadoApi.request('/webauthn/register/start', 'POST', params);
};

@@ -90,3 +89,3 @@

return await this.corbadoApi.request('webauthn/register/finish', 'POST', params);
return await this.corbadoApi.request('/webauthn/register/finish', 'POST', params);
};

@@ -145,3 +144,3 @@

return await this.corbadoApi.request('webauthn/credential/${credentialID}', 'PUT', params);
return await this.corbadoApi.request('/webauthn/credential/${credentialID}', 'PUT', params);

@@ -184,3 +183,3 @@ }

return await this.corbadoApi.request('webauthn/authenticate/start', 'POST', params);
return await this.corbadoApi.request('/webauthn/authenticate/start', 'POST', params);
}

@@ -225,3 +224,3 @@

return await this.corbadoApi.request('webauthn/authenticate/finish', 'POST', params);
return await this.corbadoApi.request('/webauthn/authenticate/finish', 'POST', params);
}

@@ -228,0 +227,0 @@ }

@@ -31,3 +31,3 @@ const CorbadoApi = require('./CorbadoApi');

}
return await this.corbadoApi.request('sessions/verify', 'POST', params);
return await this.corbadoApi.request('/sessions/verify', 'POST', params);
}

@@ -34,0 +34,0 @@ }

@@ -0,4 +1,9 @@

const Configuration = require('../src/config/configuration')
const Corbado = require('../src/corbado')
const {expect} = require("chai");
const {expect, config} = require("chai");
const generateUsername = () => {
return "test+" + (new Date()).getTime() + "@corbado.com"
}
describe('Corbado endpoint tests', function () {

@@ -12,6 +17,13 @@

const validConfig = new Configuration()
validConfig.projectID = process.env.PROJECT_ID
validConfig.apiSecret = process.env.API_SECRET
const username = generateUsername()
it('Validation projectID should work', function () {
const cfg = new Configuration()
try {
new Corbado(undefined, undefined)
new Corbado(cfg)
} catch (err) {

@@ -27,3 +39,6 @@ expect(err).to.be.a('error')

try {
new Corbado('pro-1234', undefined)
const cfg = new Configuration()
cfg.projectID = process.env.PROJECT_ID
new Corbado(cfg)
} catch (err) {

@@ -37,7 +52,8 @@ expect(err).to.be.a('error')

it('Email link should get send', function (done) {
const corbado = new Corbado(process.env.PROJECT_ID, process.env.API_SECRET)
corbado.emailLinkService.send(
"test@corbado.com",
'http://localhost',
const corbado = new Corbado(validConfig)
corbado.emailLink.send(
generateUsername(),
'http://localhost',
true,

@@ -61,29 +77,7 @@ {UserFullName: "Test Name"},

it('Session verify', function (done) {
const corbado = new Corbado(process.env.PROJECT_ID, process.env.API_SECRET)
corbado.sessionService.verify(
process.env.SESSION_TOKEN,
clientInfo,
).then(rsp => {
expect(rsp).to.be.a('object');
expect(rsp).to.have.property('httpStatusCode').with.equal(200);
expect(rsp).to.have.property('message')
expect(rsp).to.have.property('requestData')
expect(rsp).to.have.property('runtime')
expect(rsp).to.have.property('data').with.property('userID').with.contains('usr-')
expect(rsp).to.have.property('data').with.property('userData')
done()
}).catch(err => {
done(err)
})
})
it('Passkey register', function (done) {
const corbado = new Corbado(process.env.PROJECT_ID, process.env.API_SECRET)
const corbado = new Corbado(validConfig)
corbado.passkeyService.registerStart(
'test@corbado.com',
corbado.passkey.registerStart(
username,
clientInfo,

@@ -108,6 +102,6 @@ 'http://localhost',

it('Passkey authentication', function (done) {
const corbado = new Corbado(process.env.PROJECT_ID, process.env.API_SECRET)
const corbado = new Corbado(validConfig)
corbado.passkeyService.authenticateFinish(
'test@corbado.com',
corbado.passkey.authenticateStart(
username,
clientInfo,

@@ -130,2 +124,70 @@ 'http://localhost',

})
it('Short session validation issuer undefined', function (done) {
const corbado = new Corbado(validConfig)
try {
corbado.shortSession.validate(
null
).then(() => {
done(new Error('Should not happen'))
}).catch(err => {
done(err)
})
} catch (err) {
expect(err.name).equals('AssertionError')
expect(err.message).equals('Issuer undefined')
done()
}
})
it('Short session validation issuer undefined', function (done) {
const cfg = new Configuration()
cfg.projectID = validConfig.projectID
cfg.apiSecret = validConfig.apiSecret
cfg.issuer = validConfig.projectID + '.auth.corbado.com'
const corbado = new Corbado(cfg)
try {
corbado.shortSession.validate(
null
).then(() => {
done(new Error('Should not happen'))
}).catch(err => {
done(err)
})
} catch (err) {
expect(err.name).equals('AssertionError')
expect(err.message).equals('Issuer undefined')
done()
}
})
it('Short session validation valid', function (done) {
const cfg = new Configuration()
cfg.projectID = validConfig.projectID
cfg.apiSecret = validConfig.apiSecret
cfg.issuer = validConfig.projectID + '.auth.corbado.com'
cfg.jwksURI = 'https://' + config.issuer + '/.well-known/jwks'
const corbado = new Corbado(cfg)
const req = {
cookies: {
cbo_short_session: "",
}
}
corbado.shortSession.validate(
req,
).then(() => {
done(new Error('Should not happen'))
}).catch(err => {
expect(err.message === 'JWSInvalid: Invalid Compact JWS')
done()
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc