embassy
Version:
Simple JSON Web Tokens (JWT) with embedded scopes for services
40 lines • 1.25 kB
JavaScript
;
/*
* Embassy
* Copyright (c) 2017-2021 Tom Shawver
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Embassy = void 0;
const Token_1 = require("./Token");
class Embassy {
/**
* Creates a new Embassy instance.
*
* @param opts - Options with which to initialize every new {@link Token}.
*/
constructor(opts = {}) {
this.tokenOptions = {};
this.tokenOptions = Object.assign({ domainScopes: {}, keys: {} }, opts);
}
/**
* Creates a new Token, optionally initializing it with a set of claims.
*
* @param claims - A mapping of JWT claim keys to appropriate values
* @returns The newly created Token
*/
createToken(claims) {
return new Token_1.Token(Object.assign(Object.assign({}, this.tokenOptions), { claims }));
}
/**
* Creates a Token object from a signed JWT string.
*
* @param token - The JWT to be parsed
* @returns A token object, initiated with the data contained in the token
* string
*/
parseToken(token) {
return new Token_1.Token(Object.assign(Object.assign({}, this.tokenOptions), { token }));
}
}
exports.Embassy = Embassy;
//# sourceMappingURL=Embassy.js.map