@corbado/nodejs
Advanced tools
Comparing version 1.1.4 to 1.1.5
{ | ||
"name": "@corbado/nodejs", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -26,10 +26,9 @@ # Corbado Node.js library | ||
``` | ||
const Configuration = require('@corbado/nodejs/src/config/configuration'); | ||
const Corbado = require('@corbado/nodejs'); | ||
const config = new Configuration() | ||
const config = new Corbado.Configuration() | ||
config.projectID = process.env.PROJECT_ID | ||
config.apiSecret = process.env.API_SECRET | ||
const corbado = new Corbado(config) | ||
const sdk = new Corbado.SDK(config) | ||
@@ -40,11 +39,34 @@ ``` | ||
Corbado provides several services, e.g. ```PasskeyService```, ```SessionService```, ```EmailLinkService```. | ||
Corbado provides several services, e.g. ```PasskeyService```, ```SessionService```, ```EmailLinkService``` or ```ShortSessionService```. | ||
To access specific methods in, e.g. ```SessionService```, you can call: | ||
``` | ||
corbado.session.verify(sessionToken, clientInfo); | ||
sdk.session.verify(sessionToken, clientInfo); | ||
``` | ||
In order to | ||
### ShortSession | ||
Short session service provides you an easy way of accessing our session v2 variant. | ||
It provides a validate method that returns a user object with all information about the current users state. | ||
This state contains the current authentication state as well as users id, name, email and phone number. | ||
``` | ||
const Corbado = require('@corbado/nodejs'); | ||
const config = new Corbado.Configuration() | ||
config.projectID = process.env.PROJECT_ID | ||
config.apiSecret = process.env.API_SECRET | ||
config.authenticationURL = "https://" + validConfig.projectID + '.auth.corbado.com' | ||
const corbado = new Corbado.SDK(config) | ||
const user = await corbado.shortSession.validate(req) | ||
if (user.authenticated === true) { | ||
// Do anything with authenticated user | ||
} else { | ||
// Perform login ceremony | ||
} | ||
``` | ||
### Utilities | ||
@@ -54,4 +76,4 @@ | ||
``` | ||
corbado.utils.getClientInfo(req); | ||
Corbado.getClientInfo(req); | ||
``` | ||
helps to obtain relevant client information (```UserAgent```, ```RemoteAddress```, etc.) object from an ```HttpRequest```. |
@@ -84,4 +84,4 @@ const PasskeyService = require('./services/passkey.service'); | ||
assert(this.#config.authenticationURL !== undefined, 'Issuer undefined') | ||
assert(this.#config.authenticationURL.length > 0, 'Issuer is empty') | ||
assert(this.#config.authenticationURL !== undefined, 'AuthenticationURL undefined') | ||
assert(this.#config.authenticationURL.length > 0, 'AuthenticationURL is empty') | ||
assert(this.#config.cacheMaxAge > 0, 'Cache max age is invalid') | ||
@@ -88,0 +88,0 @@ |
@@ -42,3 +42,3 @@ const jose = require('jose'); | ||
async validate(req) { | ||
assert(typeof req === 'object') | ||
assert(typeof req === 'object' && req !== null, 'RequestObject not given') | ||
@@ -45,0 +45,0 @@ const JWKS = jose.createRemoteJWKSet(new URL(this.#jwksURI), { |
@@ -22,2 +22,3 @@ const Configuration = require('../src/config/configuration') | ||
const username = generateUsername() | ||
it('Validation projectID should work', function () { | ||
@@ -121,3 +122,3 @@ | ||
it('Short session validation issuer undefined', function (done) { | ||
it('Short session validation AuthenticationURL undefined', function (done) { | ||
const corbado = new Corbado(validConfig) | ||
@@ -135,3 +136,3 @@ | ||
expect(err.name).equals('AssertionError') | ||
expect(err.message).equals('Issuer undefined') | ||
expect(err.message).equals('AuthenticationURL undefined') | ||
done() | ||
@@ -141,3 +142,5 @@ } | ||
it('Short session validation issuer undefined', function (done) { | ||
it('Short session validation request not given', function (done) { | ||
const cfg = new Configuration() | ||
@@ -147,3 +150,3 @@ | ||
cfg.apiSecret = validConfig.apiSecret | ||
cfg.issuer = validConfig.projectID + '.auth.corbado.com' | ||
cfg.authenticationURL = "https://" + validConfig.projectID + '.auth.corbado.com' | ||
@@ -158,12 +161,14 @@ const corbado = new Corbado(cfg) | ||
}).catch(err => { | ||
done(err) | ||
expect(err.name).equals('AssertionError') | ||
expect(err.message).equals('RequestObject not given') | ||
done() | ||
}) | ||
} catch (err) { | ||
expect(err.name).equals('AssertionError') | ||
expect(err.message).equals('Issuer undefined') | ||
done() | ||
done(err) | ||
} | ||
}) | ||
it('Short session validation valid', function (done) { | ||
it('Short session validation empty', function (done) { | ||
const cfg = new Configuration() | ||
@@ -173,4 +178,3 @@ | ||
cfg.apiSecret = validConfig.apiSecret | ||
cfg.issuer = validConfig.projectID + '.auth.corbado.com' | ||
cfg.jwksURI = 'https://' + config.issuer + '/.well-known/jwks' | ||
cfg.authenticationURL = "https://" + validConfig.projectID + '.auth.corbado.com' | ||
@@ -177,0 +181,0 @@ const corbado = new Corbado(cfg) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31598
77
756