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

@jmondi/oauth2-server

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jmondi/oauth2-server - npm Package Compare versions

Comparing version 0.0.2-beta.2 to 0.0.2-beta.3

dist/code_verifiers/index.d.ts

2

dist/entities/access_token.entity.d.ts

@@ -6,3 +6,3 @@ import { User } from "./user.entity";

export interface AccessToken {
toJWT(): any;
toJWT: object;
token: string;

@@ -9,0 +9,0 @@ client: Client;

@@ -8,2 +8,3 @@ import { GrantId } from "../grants/abstract.grant";

allowedGrants: GrantId[];
isConfidential: boolean;
}
export interface User {
identifier: string;
}
import { DateInterval } from "@jmondi/date-interval";
import type { Request, Response } from "express";
import { AbstractAuthorizedGrant } from "./abstract_authorized.grant";
import { AuthorizationRequest } from "../requests/authorization.request";
import { RedirectResponse } from "../responses/redirect.response";
import { AuthorizationRequest } from "../requests";
import { RedirectResponse } from "../responses";
import { GrantId } from "./abstract.grant";

@@ -7,0 +7,0 @@ export interface IAuthCodePayload {

@@ -0,1 +1,8 @@

export * from "./entities";
export * from "./exceptions";
export * from "./grants";
export * from "./repositories";
export * from "./requests";
export * from "./responses";
export * from "./utils";
export * from "./authorization_server";

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@jmondi/date-interval");function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function u(t,e,r){return(u=a()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(o,r.prototype),o}).apply(null,arguments)}function c(t){var e="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}var s,f=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new L(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===f)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function l(){}function p(){}function h(){}var v={};v[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(_([])));y&&y!==e&&r.call(y,o)&&(v=y);var g=h.prototype=l.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:E}}function E(){return{value:void 0,done:!0}}return p.prototype=g.constructor=h,h.constructor=p,p.displayName=u(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,u(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(w.prototype),w.prototype[i]=function(){return this},t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(c(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),u(g,a,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(s={exports:{}}),s.exports),l=function(t){function e(e,r,n){return t.call(this,"oauth exception: "+e.toString(),r)||this}return n(e,t),e.missingRedirectUri=function(){return new e("missing redirect uri",500)},e.invalidRequest=function(t,r){return new e("invalid request"+(t=t?" "+r+" missing: ("+t.toString()+")":r),406)},e.errorValidatingClient=function(){return new e("error validating client",403)},e.invalidGrant=function(t){return new e("invalid grant_type: "+t,406)},e.unsupportedGrantType=function(){return console.error("UNSUPPORTED GRANT TYPE"),new e("unsupported grant_type",406)},e.invalidClient=function(){return new e("client authentication failed",406)},e.invalidScopes=function(t,r){return new e("invalid scopes: ("+t.join(" ")+")",406,r)},e.serverError=function(t){return new e(t,500)},e}(function(t){function e(e,r){return t.call(this)||this}return n(e,t),e}(c(Error)));exports.AuthorizationServer=function(){function e(){this.enabledGrantTypes={},this.grantTypeAccessTokenTTL={}}var n=e.prototype;return n.enableGrantType=function(e,r){r||(r=new t.DateInterval("PT1H")),this.enabledGrantTypes[e.identifier]=e,this.grantTypeAccessTokenTTL[e.identifier]=r},n.respondToAccessTokenRequest=function(t,e){for(var r=0,n=Object.values(this.enabledGrantTypes);r<n.length;r++){var o=n[r];if(o.canRespondToAccessTokenRequest(t))return o.respondToAccessTokenRequest(t,e,this.grantTypeAccessTokenTTL[o.identifier])}throw l.unsupportedGrantType()},n.validateAuthorizationRequest=function(t){for(var e=0,r=Object.values(this.enabledGrantTypes);e<r.length;e++){var n=r[e];if(n.canRespondToAuthorizationRequest(t))return n.validateAuthorizationRequest(t)}throw l.unsupportedGrantType()},n.completeAuthorizationRequest=function(){var t=r(f.mark((function t(e,r){var n,o;return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.enabledGrantTypes[e.grantTypeId],t.next=3,n.completeAuthorizationRequest(e);case 3:return o=t.sent,t.next=6,o.generateHttpResponse(r);case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e}();
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@jmondi/date-interval"),r=e(require("querystring")),n=e(require("crypto"));function i(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function o(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){i(a,n,o,s,c,"next",e)}function c(e){i(a,n,o,s,c,"throw",e)}s(void 0)}))}}function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function l(e,t,r){return(l=u()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&c(i,r.prototype),i}).apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return(h=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return l(e,arguments,s(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}var d,p=function(e){function t(t,r){return e.call(this)||this}return a(t,e),t}(h(Error)),f={NOT_ACCEPTABLE:406,FORBIDDEN:403,INTERNAL_SERVER_ERROR:500},v=function(e){function t(t,r,n){return e.call(this,"oauth exception: "+t.toString(),r)||this}return a(t,e),t.missingRedirectUri=function(){return new t("missing redirect uri",f.INTERNAL_SERVER_ERROR)},t.invalidRequest=function(e,r){return new t("invalid request"+(e=e?" "+r+" missing: ("+e.toString()+")":r),f.NOT_ACCEPTABLE)},t.errorValidatingClient=function(){return new t("error validating client",f.FORBIDDEN)},t.invalidGrant=function(e){return new t("invalid grant_type: "+e,f.NOT_ACCEPTABLE)},t.unsupportedGrantType=function(){return console.error("UNSUPPORTED GRANT TYPE"),new t("unsupported grant_type",f.NOT_ACCEPTABLE)},t.invalidClient=function(){return new t("client authentication failed",f.NOT_ACCEPTABLE)},t.invalidScopes=function(e,r){return new t("invalid scopes: ("+e.join(" ")+")",f.NOT_ACCEPTABLE,r)},t.serverError=function(e){return new t(e,500)},t}(p),y=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function c(e,t,r,n){var i=Object.create((t&&t.prototype instanceof h?t:h).prototype),o=new b(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=m(a,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(e,r,o),i}function u(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function h(){}function d(){}function p(){}var f={};f[i]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(k([])));y&&y!==t&&r.call(y,i)&&(f=y);var g=p.prototype=h.prototype=Object.create(f);function w(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(i,o){function a(){return new t((function(n,a){!function n(i,o,a,s){var c=u(e[i],e,o);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(h).then((function(e){l.value=e,a(l)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function m(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=u(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function _(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function b(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function k(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return d.prototype=g.constructor=p,p.constructor=d,d.displayName=s(p,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,s(e,a,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},w(x.prototype),x.prototype[o]=function(){return this},e.AsyncIterator=x,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new x(c(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},w(g),s(g,a,"Generator"),g[i]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=k,b.prototype={constructor:b,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),R(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;R(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(d={exports:{}}),d.exports);function g(e){return"string"==typeof e&&(e=Buffer.from(e)),e.toString("base64")}function w(e){return"string"==typeof e&&(e=Buffer.from(e,"base64")),e.toString("binary")}function x(e){return g(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var m=function(e,t){return e.filter((function(e){return!t.includes(e)}))},_=function(){function e(e,t,r,n,i,o,a){this.clientRepository=e,this.accessTokenRepository=t,this.refreshTokenRepository=r,this.authCodeRepository=n,this.scopeRepository=i,this.userRepository=o,this.jwt=a,this.scopeDelimiterString=" ",this.supportedGrantTypes=["client_credentials","authorization_code"]}var t=e.prototype;return t.validateClient=function(){var e=o(y.mark((function e(t){var r,n,i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.getClientCredentials(t),n=r[0],i=r[1],e.next=3,this.clientRepository.validateClient(this.identifier,n,i);case 3:if(e.sent){e.next=5;break}throw v.errorValidatingClient();case 5:return e.abrupt("return",this.clientRepository.getClientById(n));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.getClientCredentials=function(e){var t,r,n,i,o=this.getBasicAuthCredentials(e),a=o[1],s=null!=(t=null==(r=e.body)?void 0:r.client_id)?t:o[0];if(!s)throw v.invalidRequest("client_id");var c=null!=(n=null==(i=e.body)?void 0:i.client_secret)?n:a;return Array.isArray(s)&&(s=s[0]),Array.isArray(c)&&(c=c[0]),[s,c]},t.getBasicAuthCredentials=function(e){var t;if(!(null==(t=e.headers)?void 0:t.hasOwnProperty("authorization")))return[void 0,void 0];var r=e.headers.authorization;if(!r||!r.startsWith("Basic "))return[void 0,void 0];var n=w(r.substr(6,r.length));return n.includes(":")?n.split(":"):[void 0,void 0]},t.validateRedirectUri=function(e,t){if(""===e||!t.redirectUris.includes(e))throw v.invalidClient()},t.validateScopes=function(){var e=o(y.mark((function e(t,r){var n,i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"string"==typeof t&&(t=t.split(this.scopeDelimiterString)),e.next=3,this.scopeRepository.getScopesByIdentifier(t);case 3:if(!((i=m(t,(n=e.sent).map((function(e){return e.name})))).length>0)){e.next=7;break}throw v.invalidScopes(i,r);case 7:return e.abrupt("return",n);case 8:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),t.issueAccessToken=function(){var e=o(y.mark((function e(t,r,n,i){var o;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===i&&(i=[]),e.next=3,this.accessTokenRepository.getNewToken(r,i,n);case 3:return(o=e.sent).expiresAt=t.end(),e.next=7,this.accessTokenRepository.persistNewAccessToken(o);case 7:return e.abrupt("return",o);case 8:case"end":return e.stop()}}),e,this)})));return function(t,r,n,i){return e.apply(this,arguments)}}(),t.issueAuthCode=function(){var e=o(y.mark((function e(t,r,n,i,o,a,s){var c,u;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===s&&(s=[]),!n){e.next=7;break}return e.next=4,this.userRepository.getByUserIdentifier(n);case 4:e.t0=e.sent,e.next=8;break;case 7:e.t0=void 0;case 8:return c=e.t0,e.next=11,this.authCodeRepository.getNewAuthCode(r,c,s);case 11:return(u=e.sent).expiresAt=t.end(),u.redirectUri=i,u.codeChallenge=o,u.codeChallengeMethod=a,s.forEach((function(e){return u.scopes?u.scopes.push(e):u.scopes=[e]})),e.next=19,this.authCodeRepository.persistNewAuthCode(u);case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e,this)})));return function(t,r,n,i,o,a,s){return e.apply(this,arguments)}}(),t.issueRefreshToken=function(){var e=o(y.mark((function e(t){var r;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.refreshTokenRepository.getNewToken(t);case 2:if(r=e.sent){e.next=5;break}return e.abrupt("return");case 5:return e.next=7,this.refreshTokenRepository.persistNewRefreshToken(r);case 7:return e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.generateUniqueIdentifier=function(e){return void 0===e&&(e=40),n.randomBytes(e).toString("hex")},t.getGrantType=function(e){var t,r,n,i=null!=(t=null==(r=e.body)?void 0:r.grant_type)?t:null==(n=e.query)?void 0:n.grant_type;if(!i)throw v.invalidRequest("grant_type");if(!this.supportedGrantTypes.includes(i))throw v.invalidRequest("grant_type");return i},t.getRequestParameter=function(e,t,r){var n,i;return null!=(n=null==(i=t.body)?void 0:i[e])?n:r},t.getQueryStringParameter=function(e,t,r){var n,i;return null!=(n=null==(i=t.query)?void 0:i[e])?n:r},t.encrypt=function(e){return this.jwt.signAsync(e)},t.decrypt=function(e){return this.jwt.decode(e)},t.validateAuthorizationRequest=function(e){throw new Error("not implemented error")},t.canRespondToAccessTokenRequest=function(e){var t;return(null==(t=e.body)?void 0:t.grant_type)===this.identifier},t.canRespondToAuthorizationRequest=function(e){return!1},t.completeAuthorizationRequest=function(){var e=o(y.mark((function e(t){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("not implemented error");case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.respondToAccessTokenRequest=function(){var e=o(y.mark((function e(t,r,n){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("not implemented error");case 1:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),e}(),R=function(e){function t(){return e.apply(this,arguments)||this}return a(t,e),t.prototype.makeRedirectUrl=function(e,t,n){void 0===n&&(n="?");var i=e.includes(n)?n:"&";return e+i+r.stringify(t)},t}(_),b=function(e,t,r){this.grantTypeId=e,this.client=t,this.user=r,this.scopes=[],this.scopes=[],this.isAuthorizationApproved=!1},k=function(){function e(){this.method="plain"}return e.prototype.verifyCodeChallenge=function(e,t){return console.log({type:"verifyCodeChallenge plain",codeVerifier:e,codeChallenge:t}),t===e},e}(),T=function(){function e(){this.method="S256"}return e.prototype.verifyCodeChallenge=function(e,t){return t===x(n.createHash("sha256").update(e).digest("hex"))},e}(),C=function(e){function t(t){var r;return(r=e.call(this)||this)._redirectUri=t,r}return a(t,e),t.prototype.generateHttpResponse=function(){var e=o(y.mark((function e(t){return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._redirectUri){e.next=2;break}throw v.missingRedirectUri();case 2:return e.abrupt("return",t.redirect(302,this._redirectUri));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}((function(){})),A=function(e){function r(){var r;return(r=e.apply(this,arguments)||this).identifier="authorization_code",r.authCodeTTL=new t.DateInterval({minutes:15}),r.codeChallengeVerifiers={plain:new k,S256:new T},r}a(r,e);var n=r.prototype;return n.respondToAccessTokenRequest=function(){var e=o(y.mark((function e(t,r,n){var i,o,a,s,c,u,l,h,d,p,f,g;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=this.getClientCredentials(t),a=o[0],e.next=3,this.clientRepository.getClientById(a);case 3:if(!(s=e.sent).isConfidential){e.next=7;break}return e.next=7,this.validateClient(t);case 7:if(c=null==(i=t.body)?void 0:i.code){e.next=10;break}throw v.invalidRequest("code");case 10:return l=[],e.prev=11,e.next=14,this.validateAuthorizationCode(this.decrypt(c),s,t);case 14:u=e.sent,e.next=20;break;case 17:throw e.prev=17,e.t0=e.catch(11),v.invalidRequest("code","cannot decrypt the authorization code");case 20:return e.prev=20,e.t1=this.scopeRepository,e.next=24,this.validateScopes(null!=(h=u.scopes)?h:[]);case 24:return e.t2=e.sent,e.t3=this.identifier,e.t4=s,e.t5=u.user_id,e.next=30,e.t1.finalizeScopes.call(e.t1,e.t2,e.t3,e.t4,e.t5);case 30:e.sent.forEach((function(e){return l.push(e)})),e.next=37;break;case 34:throw e.prev=34,e.t6=e.catch(20),v.invalidRequest("code","cannot verify scopes");case 37:return e.next=39,this.authCodeRepository.getAuthCodeByIdentifier(u.auth_code_id);case 39:if(e.sent.codeChallenge===u.code_challenge){e.next=42;break}throw v.invalidRequest("code_challenge","Provided code challenge does not match auth code");case 42:if(!u.code_challenge){e.next=61;break}if(d=this.getRequestParameter("code_verifier",t)){e.next=46;break}throw v.invalidRequest("code_verifier");case 46:if(/^[A-Za-z0-9-._~]{43,128}$/.test(d)){e.next=49;break}throw v.invalidRequest("code_verifier","Code verifier must follow the specifications of RFS-7636");case 49:if(!u.code_challenge_method){e.next=61;break}if("S256"!==u.code_challenge_method){e.next=54;break}p=this.codeChallengeVerifiers.S256,e.next=59;break;case 54:if("plain"!==u.code_challenge_method){e.next=58;break}p=this.codeChallengeVerifiers.plain,e.next=59;break;case 58:throw v.serverError("Unsupported code challenge method "+u.code_challenge_method);case 59:if(p.verifyCodeChallenge(d,u.code_challenge)){e.next=61;break}throw v.invalidGrant("Failed to verify `code_verifier`");case 61:return e.next=63,this.issueAccessToken(n,s,u.user_id,l);case 63:return f=e.sent,e.next=66,this.issueRefreshToken(f);case 66:return g=e.sent,e.next=69,this.authCodeRepository.revokeAuthCode(u.auth_code_id);case 69:return e.abrupt("return",r.send({token_type:"Bearer",expires_in:Math.ceil((f.expiresAt.getTime()-Date.now())/1e3),access_token:f.token,refresh_token:null==g?void 0:g.token}));case 70:case"end":return e.stop()}}),e,this,[[11,17],[20,34]])})));return function(t,r,n){return e.apply(this,arguments)}}(),n.canRespondToAuthorizationRequest=function(e){var t,r;return"code"===(null==(t=e.query)?void 0:t.response_type)&&!!(null==(r=e.query)?void 0:r.client_id)},n.validateAuthorizationRequest=function(){var e=o(y.mark((function e(t){var r,n,i,o,a,s,c,u,l,h;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"==typeof(r=this.getQueryStringParameter("client_id",t))){e.next=3;break}throw v.invalidRequest("client_id");case 3:return e.next=5,this.clientRepository.getClientById(r);case 5:return n=e.sent,i=this.getQueryStringParameter("redirect_uri",t),Array.isArray(i)&&1===i.length&&(i=i[0]),this.validateRedirectUri(i,n),"string"==typeof(o=this.getQueryStringParameter("scope",t,[]))&&(o=o.split(this.scopeDelimiterString)),e.next=13,this.validateScopes(o);case 13:if(a=e.sent,s=this.getQueryStringParameter("state",t),(c=new b(this.identifier,n)).state=s,c.scopes=a,i&&(c.redirectUri=i),!(u=this.getQueryStringParameter("code_challenge",t))){e.next=34;break}l=this.getQueryStringParameter("code_challenge_method",t,"plain"),h=/^[A-Za-z0-9-._~]{43,128}$/g,e.prev=23,u=w(u),e.next=30;break;case 27:throw e.prev=27,e.t0=e.catch(23),v.invalidRequest("code_challenge","Code challenge must be base64 encoded.");case 30:if(h.test(u)){e.next=32;break}throw v.invalidRequest("code_challenge","Code challenge must follow the specifications of RFC-7636.");case 32:c.codeChallenge=u,c.codeChallengeMethod=l;case 34:return e.abrupt("return",c);case 35:case"end":return e.stop()}}),e,this,[[23,27]])})));return function(t){return e.apply(this,arguments)}}(),n.completeAuthorizationRequest=function(){var e=o(y.mark((function e(t){var r,n,i,o,a,s;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.user){e.next=2;break}throw new v("authorization request error user not found",500);case 2:if(n=null!=(r=t.redirectUri)?r:this.getClientRedirectUri(t),!t.isAuthorizationApproved){e.next=19;break}return e.next=6,this.issueAuthCode(this.authCodeTTL,t.client,null==(i=t.user)?void 0:i.identifier,t.redirectUri,t.codeChallenge,t.codeChallengeMethod,t.scopes);case 6:return a={client_id:(o=e.sent).client.id,redirect_uri:o.redirectUri,auth_code_id:o.token,scopes:o.scopes.map((function(e){return e.name})),user_id:o.userId,expire_time:this.authCodeTTL.end().getTime()/1e3,code_challenge:t.codeChallenge,code_challenge_method:t.codeChallengeMethod},s=JSON.stringify(a),e.t0=C,e.t1=this,e.t2=n,e.next=14,this.encrypt(s);case 14:return e.t3=e.sent,e.t4=t.state,e.t5={code:e.t3,state:e.t4},e.t6=e.t1.makeRedirectUrl.call(e.t1,e.t2,e.t5),e.abrupt("return",new e.t0(e.t6));case 19:throw new v("error something went wrong",500);case 20:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.validateAuthorizationCode=function(){var e=o(y.mark((function e(t,r,n){var i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.auth_code_id){e.next=2;break}throw v.invalidRequest("code","Authorization code malformed");case 2:if(!(Date.now()/1e3>t.expire_time)){e.next=4;break}throw v.invalidRequest("code","Authorization code has expired");case 4:return e.next=6,this.authCodeRepository.isAuthCodeRevoked(t.auth_code_id);case 6:if(!e.sent){e.next=8;break}throw v.invalidRequest("code","Authorization code has expired");case 8:if(t.client_id===r.id){e.next=10;break}throw v.invalidRequest("code","Authorization code was not issued to this client");case 10:if(i=this.getRequestParameter("redirect_uri",n),!t.redirect_uri||i){e.next=13;break}throw v.invalidRequest("redirect_uri");case 13:if(t.redirect_uri===i){e.next=15;break}throw v.invalidRequest("redirect_uri","Invalid redirect URI");case 15:return e.abrupt("return",t);case 16:case"end":return e.stop()}}),e,this)})));return function(t,r,n){return e.apply(this,arguments)}}(),n.getClientRedirectUri=function(e){if(0===e.client.redirectUris.length)throw v.missingRedirectUri();return e.client.redirectUris[0]},r}(R),E=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).identifier="client_credentials",t}return a(t,e),t.prototype.respondToAccessTokenRequest=function(){var e=o(y.mark((function e(t,r,n){var i,o,a,s,c,u,l,h,d,p,f,g;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=this.getClientCredentials(t),s=a[0],c=a[1],(u=this.getGrantType(t))===this.identifier){e.next=4;break}throw v.invalidGrant();case 4:return e.next=6,this.clientRepository.getClientById(s);case 6:return l=e.sent,e.next=9,this.clientRepository.validateClient(u,s,c);case 9:if(e.sent){e.next=11;break}throw v.errorValidatingClient();case 11:return h=null!=(i=null==(o=t.body)?void 0:o.scopes)?i:[],e.next=14,this.validateScopes(h);case 14:return d=e.sent,e.next=18,this.issueAccessToken(n,l,void 0,d);case 18:return p=e.sent,f=n.toSeconds(),g=this.jwt.sign(p.toJWT,{expiresIn:f}),e.abrupt("return",r.send({token_type:"Bearer",expires_in:n.toSeconds(),access_token:g}));case 22:case"end":return e.stop()}}),e,this)})));return function(t,r,n){return e.apply(this,arguments)}}(),t}(_),q=function(){function e(){this.enabledGrantTypes={},this.grantTypeAccessTokenTTL={}}var r=e.prototype;return r.enableGrantType=function(e,r){r||(r=new t.DateInterval("PT1H")),this.enabledGrantTypes[e.identifier]=e,this.grantTypeAccessTokenTTL[e.identifier]=r},r.respondToAccessTokenRequest=function(e,t){for(var r=0,n=Object.values(this.enabledGrantTypes);r<n.length;r++){var i=n[r];if(i.canRespondToAccessTokenRequest(e))return i.respondToAccessTokenRequest(e,t,this.grantTypeAccessTokenTTL[i.identifier])}throw v.unsupportedGrantType()},r.validateAuthorizationRequest=function(e){for(var t=0,r=Object.values(this.enabledGrantTypes);t<r.length;t++){var n=r[t];if(n.canRespondToAuthorizationRequest(e))return n.validateAuthorizationRequest(e)}throw v.unsupportedGrantType()},r.completeAuthorizationRequest=function(){var e=o(y.mark((function e(t,r){var n,i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.enabledGrantTypes[t.grantTypeId],e.next=3,n.completeAuthorizationRequest(t);case 3:return i=e.sent,e.next=6,i.generateHttpResponse(r);case 6:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),e}();exports.AuthCodeGrant=A,exports.AuthorizationRequest=b,exports.AuthorizationServer=q,exports.ClientCredentialsGrant=E,exports.HttpException=p,exports.HttpStatus=f,exports.OAuthException=v,exports.RedirectResponse=C,exports.arrayDiff=m,exports.base64decode=w,exports.base64encode=g,exports.base64urlencode=x;
//# sourceMappingURL=oauth2-server.cjs.production.min.js.map

@@ -1,4 +0,2 @@

import { AccessToken } from "../entities/access_token.entity";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { AccessToken, Client, Scope } from "../entities";
export interface AccessTokenRepository {

@@ -5,0 +3,0 @@ getNewToken(client: Client, scopes: Scope[], userId: string | undefined): Promise<AccessToken>;

@@ -1,7 +0,4 @@

import { User } from "../entities/user.entity";
import { AuthCode } from "../entities/auth_code.entity";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { AuthCode, Client, Scope, User } from "../entities";
export interface AuthCodeRepository {
getNewAuthCode(client: Client, user?: User, scopes?: Scope[]): AuthCode;
getNewAuthCode(client: Client, user: User | undefined, scopes: Scope[]): AuthCode;
persistNewAuthCode(authCode: AuthCode): Promise<AuthCode>;

@@ -8,0 +5,0 @@ isAuthCodeRevoked(authCodeCode: string): Promise<any>;

import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Client } from "../entities";
export interface ClientRepository {

@@ -4,0 +4,0 @@ getClientById(clientId: string): Promise<Client>;

@@ -1,3 +0,2 @@

import { RefreshToken } from "../entities/refresh_token.entity";
import { AccessToken } from "../entities/access_token.entity";
import { AccessToken, RefreshToken } from "../entities";
export interface RefreshTokenRepository {

@@ -4,0 +3,0 @@ getNewToken(accessToken: AccessToken): Promise<RefreshToken | undefined>;

import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { Client, Scope } from "../entities";
export interface ScopeRepository {

@@ -5,0 +4,0 @@ getScopesByIdentifier(scopeNames: string[]): Promise<Scope[]>;

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

import { User } from "../entities/user.entity";
import { User } from "../entities";
export interface UserRepository {
getByUserIdentifier(userIdentifier: string): Promise<User>;
}

@@ -1,5 +0,3 @@

import { User } from "../entities/user.entity";
import { Client, Scope, User } from "../entities";
import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
export declare class AuthorizationRequest {

@@ -6,0 +4,0 @@ readonly grantTypeId: GrantId;

@@ -1,7 +0,6 @@

import { AccessToken } from "../entities/access_token.entity";
import { RefreshToken } from "../entities/refresh_token.entity";
import { AccessToken, RefreshToken } from "../entities";
export declare abstract class AbstractResponse {
protected accessToken: AccessToken;
protected refreshToken: RefreshToken;
protected privateKey: any;
protected accessToken?: AccessToken;
protected refreshToken?: RefreshToken;
protected privateKey?: any;
}
{
"version": "0.0.2-beta.2",
"version": "0.0.2-beta.3",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -7,3 +7,3 @@ import { User } from "./user.entity";

export interface AccessToken {
toJWT(): any; // @todo refactor
toJWT: object; // @todo refactor
token: string;

@@ -10,0 +10,0 @@ client: Client;

@@ -9,2 +9,3 @@ import { GrantId } from "../grants/abstract.grant";

allowedGrants: GrantId[];
isConfidential: boolean;
}
export interface User {
identifier: string;
}

@@ -5,17 +5,15 @@ import crypto from "crypto";

import { ClientRepository } from "../repositories/client.repository";
import { RefreshTokenRepository } from "../repositories/refresh_token.repository";
import { AuthorizationRequest } from "../requests/authorization.request";
import { AuthCodeRepository } from "../repositories/auth_code.repository";
import { AuthCode } from "../entities/auth_code.entity";
import { RedirectResponse } from "../responses/redirect.response";
import { OAuthException } from "../exceptions/oauth.exception";
import { AccessTokenRepository } from "../repositories/access_token.repository";
import { base64decode } from "../utils/base64";
import { UserRepository } from "../repositories/user.repository";
import { RefreshToken } from "../entities/refresh_token.entity";
import { arrayDiff } from "../utils/array";
import { AccessToken } from "../entities/access_token.entity";
import { Client } from "../entities/client.entity";
import { ScopeRepository } from "../repositories/scope.repository";
import { AuthorizationRequest } from "../requests";
import {
AccessTokenRepository,
AuthCodeRepository,
ClientRepository,
RefreshTokenRepository,
ScopeRepository,
UserRepository,
} from "../repositories";
import { AccessToken, AuthCode, Client, RefreshToken, Scope } from "../entities";
import { RedirectResponse } from "../responses";
import { OAuthException } from "../exceptions";
import { arrayDiff, base64decode, JwtService } from "../utils";

@@ -179,3 +177,5 @@ export type GrantId = "authorization_code" | "client_credentials";

return await this.refreshTokenRepository.persistNewRefreshToken(refreshToken);
await this.refreshTokenRepository.persistNewRefreshToken(refreshToken);
return refreshToken;
}

@@ -182,0 +182,0 @@

import { DateInterval } from "@jmondi/date-interval";
import type { Request, Response } from "express";
import { AbstractAuthorizedGrant } from "./abstract_authorized.grant";
import { base64decode } from "../utils/base64";
import { AuthorizationRequest } from "../requests/authorization.request";
import { ICodeChallenge } from "../code_verifiers/verifier";
import { RedirectResponse } from "../responses/redirect.response";
import { S256Verifier } from "../code_verifiers/s265.verifier";
import { OAuthException } from "../exceptions/oauth.exception";
import { base64decode } from "../utils";
import { AuthorizationRequest } from "../requests";
import { ICodeChallenge, PlainVerifier, S256Verifier } from "../code_verifiers";
import { RedirectResponse } from "../responses";
import { OAuthException } from "../exceptions";
import { GrantId } from "./abstract.grant";
import { Client } from "../entities/client.entity";
import { PlainVerifier } from "../code_verifiers/plain.verifier";
import { Client, Scope } from "../entities";
export interface IAuthCodePayload {

@@ -210,3 +210,3 @@ client_id: string;

authorizationRequest.client,
authorizationRequest.user?.id,
authorizationRequest.user?.identifier,
authorizationRequest.redirectUri,

@@ -213,0 +213,0 @@ authorizationRequest.codeChallenge,

@@ -5,3 +5,3 @@ import { DateInterval } from "@jmondi/date-interval";

import { AbstractGrant } from "./abstract.grant";
import { OAuthException } from "../exceptions/oauth.exception";
import { OAuthException } from "../exceptions";

@@ -8,0 +8,0 @@ export class ClientCredentialsGrant extends AbstractGrant {

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

export * from "./entities"
export * from "./exceptions"
export * from "./grants"
export * from "./repositories"
export * from "./requests"
export * from "./responses"
export * from "./utils"
export * from "./authorization_server"

@@ -1,4 +0,2 @@

import { AccessToken } from "../entities/access_token.entity";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { AccessToken, Client, Scope } from "../entities";

@@ -5,0 +3,0 @@ export interface AccessTokenRepository {

@@ -1,8 +0,5 @@

import { User } from "../entities/user.entity";
import { AuthCode } from "../entities/auth_code.entity";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { AuthCode, Client, Scope, User } from "../entities";
export interface AuthCodeRepository {
getNewAuthCode(client: Client, user?: User, scopes: Scope[] = []): AuthCode;
getNewAuthCode(client: Client, user: User | undefined, scopes: Scope[]): AuthCode;

@@ -9,0 +6,0 @@ persistNewAuthCode(authCode: AuthCode): Promise<AuthCode>;

import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Client } from "../entities";

@@ -4,0 +4,0 @@ export interface ClientRepository {

@@ -1,3 +0,2 @@

import { RefreshToken } from "../entities/refresh_token.entity";
import { AccessToken } from "../entities/access_token.entity";
import { AccessToken, RefreshToken } from "../entities";

@@ -4,0 +3,0 @@ export interface RefreshTokenRepository {

import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";
import { Client, Scope } from "../entities";

@@ -5,0 +4,0 @@ export interface ScopeRepository {

@@ -1,2 +0,2 @@

import { User } from "../entities/user.entity";
import { User } from "../entities";

@@ -3,0 +3,0 @@ export interface UserRepository {

@@ -1,5 +0,3 @@

import { User } from "../entities/user.entity";
import { Client, Scope, User } from "../entities";
import { GrantId } from "../grants/abstract.grant";
import { Client } from "../entities/client.entity";
import { Scope } from "../entities/scope.entity";

@@ -6,0 +4,0 @@ export class AuthorizationRequest {

@@ -1,8 +0,8 @@

import { AccessToken } from "../entities/access_token.entity";
import { RefreshToken } from "../entities/refresh_token.entity";
import { AccessToken, RefreshToken } from "../entities";
// @todo this is not used......
export abstract class AbstractResponse {
protected accessToken: AccessToken;
protected refreshToken: RefreshToken;
protected privateKey: any;
protected accessToken?: AccessToken;
protected refreshToken?: RefreshToken;
protected privateKey?: any;
}
import type { Response } from "express";
import { AbstractResponse } from "./abstract.response";
import { OAuthException } from "../exceptions/oauth.exception";
import { OAuthException } from "../exceptions";

@@ -6,0 +6,0 @@ export class RedirectResponse extends AbstractResponse {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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