diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..3629ba8
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+updates:
+ - package-ecosystem: "npm"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ time: "06:00"
+ timezone: "Asia/Kolkata"
+ reviewers:
+ - "dhawani"
diff --git a/README.md b/README.md
index 48c6d25..1234cc2 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
+
@@ -6,21 +6,24 @@
-
- Official Scalekit Node SDK
-
-Scalekit helps you in shipping enterprise auth in days.
+# Official Node.js SDK
+Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node.js SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours.
-This Node SDK is a wrapper around Scalekit's REST API to help you integrate Scalekit with your Node.js applications.
+
+
-## Getting Started
+## Pre-requisites
1. [Sign up](https://scalekit.com) for a Scalekit account.
2. Get your ```env_url```, ```client_id``` and ```client_secret``` from the Scalekit dashboard.
## Installation
+Install Scalekit SDK using your preferred package manager.
+
```sh
npm install @scalekit-sdk/node
#or
@@ -31,19 +34,86 @@ pnpm add @scalekit-sdk/node
## Usage
+Initialize the Scalekit client using the appropriate credentials. Refer code sample below.
+
```javascript
-import { Scalekit } from "@scalekit-sdk/node";
+import { ScalekitClient } from "@scalekit-sdk/node";
-const scalekit = new Scalekit(
+const sc = new ScalekitClient(
process.env.SCALEKIT_ENV_URL!,
process.env.SCALEKIT_CLIENT_ID!,
process.env.SCALEKIT_CLIENT_SECRET!
);
+
+// Use the sc object to interact with the Scalekit API
+const authUrl = sc.getAuthorizationUrl("https://acme-corp.com/redirect-uri", {
+ state: "state",
+ connectionId: "connection_id",
+});
+
```
+## Examples - SSO with Express.js
+
+Below is a simple code sample that showcases how to implement Single Sign-on using Scalekit SDK
+
+```javascript
+import express from "express";
+import { ScalekitClient } from "@scalekit-sdk/node";
+
+const app = express();
+
+const sc = new ScalekitClient(
+ process.env.SCALEKIT_ENV_URL!,
+ process.env.SCALEKIT_CLIENT_ID!,
+ process.env.SCALEKIT_CLIENT_SECRET!
+);
+
+const redirectUri = `${process.env.HOST}/auth/callback`;
+
+// Get the authorization URL and redirect the user to the IdP login page
+app.get("/auth/login", (req, res) => {
+ const authUrl = sc.getAuthorizationUrl(
+ redirectUri,
+ {
+ state: "state",
+ connectionId: "connection_id",
+ }
+ );
+
+ res.redirect(authUrl);
+});
+
+// Handle the callback from Scalekit
+app.get("/auth/callback", async (req, res) => {
+ const code = req.query.code as string;
+ const authResp = await sc.authenticateWithCode(code, redirectUri);
+ res.cookie("access_token", authResp.accessToken);
+ res.json(authResp.accessToken);
+});
+
+app.listen(3000, () => {
+ console.log("Server is running on port 3000");
+});
+```
+
+## Example Apps
+
+Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally.
+
+- [Express.js](https://github.com/scalekit-inc/scalekit-express-example.git)
+- [Next.js](https://github.com/scalekit-inc/scalekit-nextjs-example.git)
+
## API Reference
-See the [Scalekit API docs](https://docs.scalekit.com) for more information about the API and authentication.
+
+Refer to our [API reference docs](https://docs.scalekit.com/apis) for detailed information about all our API endpoints and their usage.
+
+## More Information
+
+- Quickstart Guide to implement Single Sign-on in your application: [SSO Quickstart Guide](https://docs.scalekit.com)
+- Understand Single Sign-on basics: [SSO Basics](https://docs.scalekit.com/best-practices/single-sign-on)
## License
+
This project is licensed under the **MIT license**.
-See the [LICENSE](LICENSE) file for more information.
\ No newline at end of file
+See the [LICENSE](LICENSE) file for more information.
diff --git a/lib/connect.js b/lib/connect.js
index a317ffc..d8de032 100644
--- a/lib/connect.js
+++ b/lib/connect.js
@@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const connect_1 = require("@connectrpc/connect");
const connect_node_1 = require("@connectrpc/connect-node");
+const core_1 = require("./core");
class GrpcConnect {
constructor(coreClient) {
this.coreClient = coreClient;
@@ -11,11 +12,11 @@ class GrpcConnect {
interceptors: [
(next) => {
return (req) => {
- req.header.set("User-Agent", this.coreClient.userAgent);
- req.header.set("x-sdk-version", this.coreClient.sdkVersion);
- req.header.set("x-api-version", this.coreClient.apiVersion);
+ req.header.set(core_1.headers['user-agent'], this.coreClient.userAgent);
+ req.header.set(core_1.headers['x-sdk-version'], this.coreClient.sdkVersion);
+ req.header.set(core_1.headers['x-api-version'], this.coreClient.apiVersion);
if (this.coreClient.accessToken) {
- req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`);
+ req.header.set(core_1.headers.authorization, `Bearer ${this.coreClient.accessToken}`);
}
return next(req);
};
diff --git a/lib/connect.js.map b/lib/connect.js.map
index 40fc456..406d3c3 100644
--- a/lib/connect.js.map
+++ b/lib/connect.js.map
@@ -1 +1 @@
-{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":";;AACA,iDAAoF;AACpF,2DAA+D;AAG/D,MAAqB,WAAW;IAE9B,YACmB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,SAAS,GAAG,IAAA,kCAAmB,EAAC;YACnC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;YAC/B,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE;gBACZ,CAAC,IAAI,EAAE,EAAE;oBACP,OAAO,CAAC,GAAG,EAAE,EAAE;wBACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;wBACvD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBAC3D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBAC3D,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;4BAChC,GAAG,CAAC,M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AU,CAAC,WAAW,EAAE,CAAC,CAAA;wBAChF,CAAC;wBACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBAClB,CAAC,CAAA;gBACH,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAwB,OAAU;QAC5C,OAAO,IAAA,6BAAmB,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AA3BD,8BA2BC"}
\ No newline at end of file
diff --git a/lib/connection.d.ts b/lib/connection.d.ts
index 3c3a8ee..8fd804a 100644
--- a/lib/connection.d.ts
+++ b/lib/connection.d.ts
@@ -1,6 +1,6 @@
import GrpcConnect from './connect';
import CoreClient from './core';
-import { GetConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
+import { GetConnectionResponse, ToggleConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
export default class ConnectionClient {
private readonly grpcConncet;
private readonly coreClient;
@@ -8,11 +8,11 @@ export default class ConnectionClient {
constructor(grpcConncet: GrpcConnect, coreClient: CoreClient);
/**
* Get a connection by id and organization id
- * @param id The connection id
* @param organizationId The organization id
+ * @param id The connection id
* @returns {Promise} The connection
*/
- getConnection(id: string, organizationId: string): Promise;
+ getConnection(organizationId: string, id: string): Promise;
/**
* List connections by domain
* @param domain The domain
@@ -25,4 +25,18 @@ export default class ConnectionClient {
* @returns {Promise} The list of connections
*/
listConnections(organizationId: string): Promise;
+ /**
+ * Enable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ enableConnection(organizationId: string, id: string): Promise;
+ /**
+ * Disable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ disableConnection(organizationId: string, id: string): Promise;
}
diff --git a/lib/connection.js b/lib/connection.js
index ea9c8ff..d0cb54d 100644
--- a/lib/connection.js
+++ b/lib/connection.js
@@ -18,11 +18,11 @@ class ConnectionClient {
}
/**
* Get a connection by id and organization id
- * @param id The connection id
* @param organizationId The organization id
+ * @param id The connection id
* @returns {Promise} The connection
*/
- getConnection(id, organizationId) {
+ getConnection(organizationId, id) {
return __awaiter(this, void 0, void 0, function* () {
return this.coreClient.connectExec(this.client.getConnection, {
id,
@@ -63,6 +63,40 @@ class ConnectionClient {
});
});
}
+ /**
+ * Enable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ enableConnection(organizationId, id) {
+ return __awaiter(this, void 0, void 0, function* () {
+ return this.coreClient.connectExec(this.client.enableConnection, {
+ id,
+ identities: {
+ case: 'organizationId',
+ value: organizationId
+ }
+ });
+ });
+ }
+ /**
+ * Disable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ disableConnection(organizationId, id) {
+ return __awaiter(this, void 0, void 0, function* () {
+ return this.coreClient.connectExec(this.client.disableConnection, {
+ id,
+ identities: {
+ case: 'organizationId',
+ value: organizationId
+ }
+ });
+ });
+ }
}
exports.default = ConnectionClient;
//# sourceMappingURL=connection.js.map
\ No newline at end of file
diff --git a/lib/connection.js.map b/lib/connection.js.map
index b013bc8..906b904 100644
--- a/lib/connection.js.map
+++ b/lib/connection.js.map
@@ -1 +1 @@
-{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F;AAG3F,MAAqB,gBAAgB;IAEnC,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,uCAAiB,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACG,aAAa,CAAC,EAAU,EAAE,cAAsB;;YACpD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,aAAa,EACzB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,uBAAuB,CAAC,MAAc;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,MAAM;iBACd;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,cAAsB;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA7DD,mCA6DC"}
\ No newline at end of file
+{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F;AAG3F,MAAqB,gBAAgB;IAEnC,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,uCAAiB,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACG,aAAa,CAAC,cAAsB,EAAE,EAAU;;YACpD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,aAAa,EACzB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,uBAAuB,CAAC,MAAc;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,MAAM;iBACd;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,cAAsB;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,cAAsB,EAAE,EAAU;;YACvD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAC5B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,iBAAiB,CAAC,cAAsB,EAAE,EAAU;;YACxD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAC7B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAnGD,mCAmGC"}
\ No newline at end of file
diff --git a/lib/constants/user.d.ts b/lib/constants/user.d.ts
index d2e3c30..40bd40d 100644
--- a/lib/constants/user.d.ts
+++ b/lib/constants/user.d.ts
@@ -1,4 +1,4 @@
-import type { IdTokenClaim, User } from '../types/user';
+import type { IdTokenClaim, User } from '../types/auth';
export declare const IdTokenClaimToUserMap: {
[k in keyof IdTokenClaim]: keyof User;
};
diff --git a/lib/core.d.ts b/lib/core.d.ts
index 717425f..7782d89 100644
--- a/lib/core.d.ts
+++ b/lib/core.d.ts
@@ -1,5 +1,12 @@
import { Axios, AxiosResponse } from "axios";
import { JWK } from 'jose';
+import { TokenResponse } from './types/auth';
+export declare const headers: {
+ "user-agent": string;
+ "x-sdk-version": string;
+ "x-api-version": string;
+ authorization: string;
+};
export default class CoreClient {
readonly envUrl: string;
readonly clientId: string;
@@ -15,12 +22,9 @@ export default class CoreClient {
/**
* Authenticate with the code
* @param {string} data Data to authenticate
- * @returns {Promise>} Returns access token and id token
+ * @returns {Promise>} Returns access token and id token
*/
- authenticate(data: string): Promise>;
+ authenticate(data: string): Promise>;
/**
* Get the JWKS from the server and store it in the client instance
* @returns {Promise} Returns nothing
diff --git a/lib/core.js b/lib/core.js
index d735bb5..2f8b3ca 100644
--- a/lib/core.js
+++ b/lib/core.js
@@ -35,12 +35,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
+exports.headers = void 0;
const connect_1 = require("@connectrpc/connect");
const axios_1 = __importStar(require("axios"));
const os_1 = __importDefault(require("os"));
const qs_1 = __importDefault(require("qs"));
const scalekit_1 = require("./types/scalekit");
const errdetails_pb_1 = require("./pkg/grpc/scalekit/v1/errdetails/errdetails_pb");
+exports.headers = {
+ "user-agent": "user-agent",
+ "x-sdk-version": "x-sdk-version",
+ "x-api-version": "x-api-version",
+ "authorization": "authorization"
+};
const tokenEndpoint = "oauth/token";
const jwksEndpoint = "keys";
class CoreClient {
@@ -55,11 +62,11 @@ class CoreClient {
this.userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os_1.default.arch()})`;
this.axios = axios_1.default.create({ baseURL: envUrl });
this.axios.interceptors.request.use((config) => {
- config.headers["User-Agent"] = this.userAgent;
- config.headers["x-sdk-version"] = this.sdkVersion;
- config.headers["x-api-version"] = this.apiVersion;
+ config.headers[exports.headers['user-agent']] = this.userAgent;
+ config.headers[exports.headers['x-sdk-version']] = this.sdkVersion;
+ config.headers[exports.headers['x-api-version']] = this.apiVersion;
if (this.accessToken) {
- config.headers["Authorization"] = `Bearer ${this.accessToken}`;
+ config.headers[exports.headers.authorization] = `Bearer ${this.accessToken}`;
}
return config;
});
@@ -78,7 +85,7 @@ class CoreClient {
/**
* Authenticate with the code
* @param {string} data Data to authenticate
- * @returns {Promise>} Returns access token and id token
+ * @returns {Promise>} Returns access token and id token
*/
authenticate(data) {
return __awaiter(this, void 0, void 0, function* () {
@@ -117,10 +124,10 @@ class CoreClient {
}
catch (error) {
if (retryLeft > 0) {
- let isUnauthenticatedError = false;
+ let isUnAuthenticatedError = false;
if (error instanceof axios_1.AxiosError) {
if (error.status == axios_1.HttpStatusCode.Unauthorized) {
- isUnauthenticatedError = true;
+ isUnAuthenticatedError = true;
}
else {
throw new Error(error.message);
@@ -129,24 +136,21 @@ class CoreClient {
// ConnectError is a custom error class that extends Error class and has a code property
if (error instanceof connect_1.ConnectError) {
if (error.code == connect_1.Code.Unauthenticated) {
- isUnauthenticatedError = true;
+ isUnAuthenticatedError = true;
}
- else {
- if (error.code == connect_1.Code.InvalidArgument) {
- const message = error.findDetails(errdetails_pb_1.ErrorInfo).map((detail) => {
- if (detail.validationErrorInfo) {
- return detail.validationErrorInfo.fieldViolations.map((fv) => {
- return `${fv.field}: ${fv.description}`;
- }).join("\n");
- }
- return error.message;
- }).join("\n");
- throw new Error(message);
- }
- throw new Error(error.message);
+ if (error.code == connect_1.Code.InvalidArgument) {
+ const messages = [error.message];
+ error.findDetails(errdetails_pb_1.ErrorInfo).forEach((detail) => {
+ if (detail.validationErrorInfo) {
+ detail.validationErrorInfo.fieldViolations.forEach((fv) => {
+ messages.push(`${fv.field}: ${fv.description}`);
+ });
+ }
+ });
+ throw new Error(messages.join("\n"));
}
}
- if (isUnauthenticatedError) {
+ if (isUnAuthenticatedError) {
yield this.authenticateClient();
return this.connectExec(fn, data, retryLeft - 1);
}
diff --git a/lib/core.js.map b/lib/core.js.map
index 9161662..a78c067 100644
--- a/lib/core.js.map
+++ b/lib/core.js.map
@@ -1 +1 @@
-{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAyD;AACzD,+CAAgF;AAEhF,4CAAoB;AACpB,4CAA6B;AAC7B,+CAA6C;AAC7C,mFAA4E;AAE5E,MAAM,aAAa,GAAG,aAAa,CAAC;AACpC,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAqB,UAAU;IAO7B,YACW,MAAc,EACd,QAAgB,EAChB,YAAoB;QAFpB,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAQ;QATxB,SAAI,GAAU,EAAE,CAAC;QACjB,gBAAW,GAAkB,IAAI,CAAC;QAElC,eAAU,GAAG,qBAAqB,CAAC;QACnC,eAAU,GAAG,UAAU,CAAC;QACxB,cAAS,GAAG,GAAG,IAAI,CAAC,UAAU,SAAS,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,YAAE,CAAC,IAAI,EAAE,GAAG,CAAC;QAMlG,IAAI,CAAC,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7C,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;YAC9C,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;YAClD,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,U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,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;wCACxD,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;oCACjD,CAAC,CAAC,CAAA;gCACJ,CAAC;4BACH,CAAC,CAAC,CAAA;4BAEF,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;wBACvC,CAAC;oBACH,CAAC;oBACD,IAAI,sBAAsB,EAAE,CAAC;wBAC3B,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;wBAChC,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;oBACnD,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;CACF;AAnHD,6BAmHC"}
\ No newline at end of file
diff --git a/lib/domain.d.ts b/lib/domain.d.ts
index e0e0e86..4dc13c4 100644
--- a/lib/domain.d.ts
+++ b/lib/domain.d.ts
@@ -1,6 +1,6 @@
import GrpcConnect from './connect';
import CoreClient from './core';
-import { CreateDomainResponse, GetDomainResponse, ListDomainResponse } from './pkg/grpc/scalekit/v1/domains/domains_pb';
+import { CreateDomainResponse, ListDomainResponse } from './pkg/grpc/scalekit/v1/domains/domains_pb';
export default class DomainClient {
private readonly grpcConncet;
private readonly coreClient;
@@ -13,17 +13,6 @@ export default class DomainClient {
* @returns {Promise} The created domain
*/
createDomain(organizationId: string, name: string): Promise;
- /**
- * Get a domain by id
- * @param {object} options The options to get a domain
- * @param {string} options.id The domain id
- * @param {string} options.organizationId The organization id
- * @returns {Promise} The domain
- */
- getDomain(options: {
- id: string;
- organizationId: string;
- }): Promise;
/**
* List domains for an organization
* @param organizationId The organization id
diff --git a/lib/domain.js b/lib/domain.js
index 09e6aed..c376a6a 100644
--- a/lib/domain.js
+++ b/lib/domain.js
@@ -35,25 +35,6 @@ class DomainClient {
});
});
}
- /**
- * Get a domain by id
- * @param {object} options The options to get a domain
- * @param {string} options.id The domain id
- * @param {string} options.organizationId The organization id
- * @returns {Promise} The domain
- */
- getDomain(options) {
- return __awaiter(this, void 0, void 0, function* () {
- const { id, organizationId } = options;
- return this.coreClient.connectExec(this.client.getDomain, {
- id,
- identities: {
- case: 'organizationId',
- value: organizationId
- }
- });
- });
- }
/**
* List domains for an organization
* @param organizationId The organization id
diff --git a/lib/domain.js.map b/lib/domain.js.map
index a01bb8e..a36ed2e 100644
--- a/lib/domain.js.map
+++ b/lib/domain.js.map
@@ -1 +1 @@
-{"version":3,"file":"domain.js","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,oFAA+E;AAG/E,MAAqB,YAAY;IAE/B,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,+BAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;MAKE;IACI,YAAY,CAAC,cAAsB,EAAE,IAAY;;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;gBACD,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI;iBACb;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;;MAME;IACI,SAAS,CAAC,OAA+C;;YAC7D,MAAM,EAAE,EAAE,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;YACvC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,SAAS,EACrB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,cAAsB;;YACtC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,WAAW,EACvB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAC;QACJ,CAAC;KAAA;CACF;AAnED,+BAmEC"}
\ No newline at end of file
+{"version":3,"file":"domain.js","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,oFAA+E;AAG/E,MAAqB,YAAY;IAE/B,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,+BAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;MAKE;IACI,YAAY,CAAC,cAAsB,EAAE,IAAY;;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;gBACD,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI;iBACb;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,cAAsB;;YACtC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,WAAW,EACvB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAC;QACJ,CAAC;KAAA;CACF;AA9CD,+BA8CC"}
\ No newline at end of file
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 5058a5c..d365322 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,5 +1,5 @@
-import Scalekit from "./scalekit";
-export { Scalekit };
-export default Scalekit;
+import ScalekitClient from "./scalekit";
+export { ScalekitClient };
+export default ScalekitClient;
export * from "./types/scalekit";
-export * from "./types/user";
+export * from "./types/auth";
diff --git a/lib/index.js b/lib/index.js
index 299c208..9a1c3ac 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -17,10 +17,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.Scalekit = void 0;
+exports.ScalekitClient = void 0;
const scalekit_1 = __importDefault(require("./scalekit"));
-exports.Scalekit = scalekit_1.default;
+exports.ScalekitClient = scalekit_1.default;
exports.default = scalekit_1.default;
__exportStar(require("./types/scalekit"), exports);
-__exportStar(require("./types/user"), exports);
+__exportStar(require("./types/auth"), exports);
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/lib/index.js.map b/lib/index.js.map
index 1556123..cc2f9d6 100644
--- a/lib/index.js.map
+++ b/lib/index.js.map
@@ -1 +1 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0DAAkC;AAEzB,mBAFF,kBAAQ,CAEE;AACjB,kBAAe,kBAAQ,CAAC;AAExB,mDAAiC;AACjC,+CAA6B"}
\ No newline at end of file
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0DAAwC;AAE/B,yBAFF,kBAAc,CAEE;AACvB,kBAAe,kBAAc,CAAC;AAE9B,mDAAiC;AACjC,+CAA6B"}
\ No newline at end of file
diff --git a/lib/organization.d.ts b/lib/organization.d.ts
index 548e1cd..3a6cd87 100644
--- a/lib/organization.d.ts
+++ b/lib/organization.d.ts
@@ -1,4 +1,4 @@
-import { PartialMessage } from '@bufbuild/protobuf';
+import { Empty, PartialMessage } from '@bufbuild/protobuf';
import GrpcConnect from './connect';
import CoreClient from './core';
import { CreateOrganizationResponse, GetOrganizationResponse, Link, ListOrganizationsResponse, UpdateOrganization, UpdateOrganizationResponse } from './pkg/grpc/scalekit/v1/organizations/organizations_pb';
@@ -9,13 +9,12 @@ export default class OrganizationClient {
constructor(grpcConncet: GrpcConnect, coreClient: CoreClient);
/**
* Create an organization with the given name. Optionally, you can provide an external id.
+ * @param {string} name The organization name
* @param {object} options The options to create an organization
- * @param {string} options.name The organization name
* @param {string} options.externalId The external id
* @returns {Promise} The created organization
*/
- createOrganization(options: {
- name: string;
+ createOrganization(name: string, options?: {
externalId?: string;
}): Promise;
/**
@@ -55,10 +54,29 @@ export default class OrganizationClient {
* @returns {Promise} The updated organization
*/
updateOrganizationByExternalId(externalId: string, organization: PartialMessage): Promise;
+ /**
+ * Delete an organization by id
+ * @param {string} organizationId The organization id
+ * @returns {Promise} Returns nothing
+ */
+ deleteOrganization(organizationId: string): Promise;
/**
* Generate admin portal link for an organization
* @param organizationId The organization id
* @returns {Promise } The admin portal link object with expiration time and location
*/
generatePortalLink(organizationId: string): Promise ;
+ /**
+ * Get admin portal links for an organization
+ * @param organizationId The organization id
+ * @returns {Promise } The admin portal link object with expiration time and location
+ */
+ getPortalLinks(organizationId: string): Promise ;
+ /**
+ * Delete admin portal link for an organization
+ * @param organizationId The organization id
+ * @param linkId The link id
+ * @returns {Promise} Returns nothing
+ */
+ deletePortalLink(organizationId: string, linkId: string): Promise;
}
diff --git a/lib/organization.js b/lib/organization.js
index 13f2089..94b97cf 100644
--- a/lib/organization.js
+++ b/lib/organization.js
@@ -18,19 +18,17 @@ class OrganizationClient {
}
/**
* Create an organization with the given name. Optionally, you can provide an external id.
+ * @param {string} name The organization name
* @param {object} options The options to create an organization
- * @param {string} options.name The organization name
* @param {string} options.externalId The external id
* @returns {Promise} The created organization
*/
- createOrganization(options) {
+ createOrganization(name, options) {
return __awaiter(this, void 0, void 0, function* () {
- const { name, externalId } = options;
return this.coreClient.connectExec(this.client.createOrganization, {
- organization: {
- displayName: name,
- externalId: externalId
- }
+ organization: Object.assign({ displayName: name }, ((options === null || options === void 0 ? void 0 : options.externalId) && {
+ externalId: options.externalId
+ }))
});
});
}
@@ -94,6 +92,18 @@ class OrganizationClient {
});
});
}
+ /**
+ * Delete an organization by id
+ * @param {string} organizationId The organization id
+ * @returns {Promise} Returns nothing
+ */
+ deleteOrganization(organizationId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ return this.coreClient.connectExec(this.client.deleteOrganization, {
+ identities: { case: "id", value: organizationId, },
+ });
+ });
+ }
/**
* Generate admin portal link for an organization
* @param organizationId The organization id
@@ -110,6 +120,33 @@ class OrganizationClient {
return response.link;
});
}
+ /**
+ * Get admin portal links for an organization
+ * @param organizationId The organization id
+ * @returns {Promise } The admin portal link object with expiration time and location
+ */
+ getPortalLinks(organizationId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const response = yield this.coreClient.connectExec(this.client.getPortalLinks, {
+ id: organizationId
+ });
+ return response.links;
+ });
+ }
+ /**
+ * Delete admin portal link for an organization
+ * @param organizationId The organization id
+ * @param linkId The link id
+ * @returns {Promise} Returns nothing
+ */
+ deletePortalLink(organizationId, linkId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ return this.coreClient.connectExec(this.client.deletePortalLink, {
+ id: organizationId,
+ linkId
+ });
+ });
+ }
}
exports.default = OrganizationClient;
//# sourceMappingURL=organization.js.map
\ No newline at end of file
diff --git a/lib/organization.js.map b/lib/organization.js.map
index 382e0ac..de788de 100644
--- a/lib/organization.js.map
+++ b/lib/organization.js.map
@@ -1 +1 @@
-{"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,sGAAiG;AAGjG,MAAqB,kBAAkB;IAErC,YACmB,WAAwB,EACxB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UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;gBACrC,YAAY;aACb,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,8BAA8B,CAAC,UAAkB,EAAE,YAAgD;;YACvG,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,UAAU,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG;gBACtD,YAAY;aACb,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,kBAAkB,CAAC,cAAsB;;YAC7C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAChD,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,EAAE,EAAE,cAAc;aACnB,CACF,CAAA;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;KAAA;CACF;AAxHD,qCAwHC"}
\ No newline at end of file
+{"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,sGAAiG;AAGjG,MAAqB,kBAAkB;IAErC,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,2CAAmB,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;MAME;IACI,kBAAkB,CAAC,IAAY,EAAE,OAAiC;;YACtE,OAAO,IAAI,CAAC,UAAU,CAAC,W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aACP,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAvKD,qCAuKC"}
\ No newline at end of file
diff --git a/lib/scalekit.d.ts b/lib/scalekit.d.ts
index b64bd47..d0cf6e7 100644
--- a/lib/scalekit.d.ts
+++ b/lib/scalekit.d.ts
@@ -1,18 +1,17 @@
import ConnectionClient from './connection';
import DomainClient from './domain';
import OrganizationClient from './organization';
-import { AuthorizationUrlOptions, CodeAuthenticationOptions } from './types/scalekit';
-import { User } from './types/user';
+import { AuthorizationUrlOptions, AuthenticationOptions, AuthenticationResponse } from './types/scalekit';
/**
* To initiate scalekit
* @param {string} envUrl The environment url
* @param {string} clientId The client id
* @param {string} clientSecret The client secret
- * @returns {Scalekit} Returns the scalekit instance
+ * @returns {ScalekitClient} Returns the scalekit instance
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
*/
-export default class Scalekit {
+export default class ScalekitClient {
private readonly coreClient;
private readonly grpcConnect;
readonly organization: OrganizationClient;
@@ -30,6 +29,8 @@ export default class Scalekit {
* @param {string} options.domainHint Domain hint parameter
* @param {string} options.connectionId Connection id parameter
* @param {string} options.organizationId Organization id parameter
+ * @param {string} options.codeChallenge Code challenge parameter in case of PKCE
+ * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
*
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
@@ -39,17 +40,13 @@ export default class Scalekit {
getAuthorizationUrl(redirectUri: string, options?: AuthorizationUrlOptions): string;
/**
* Authenticate with the code
- * @param {CodeAuthenticationOptions} options Code authentication options
- * @param {string} options.code Code
- * @param {string} options.redirectUri Redirect uri
- * @param {string} options.codeVerifier Code verifier
- * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token
+ * @param {string} code Code
+ * @param {string} redirectUri Redirect uri
+ * @param {AuthenticationOptions} options Code authentication options
+ * @param {string} options.codeVerifier Code verifier in case of PKCE
+ * @returns {Promise} Returns user, id token and access token
*/
- authenticateWithCode(options: CodeAuthenticationOptions): Promise<{
- user: Partial;
- idToken: string;
- accessToken: string;
- }>;
+ authenticateWithCode(code: string, redirectUri: string, options?: AuthenticationOptions): Promise;
/**
* Validates the access token.
*
diff --git a/lib/scalekit.js b/lib/scalekit.js
index 1599372..9b3be08 100644
--- a/lib/scalekit.js
+++ b/lib/scalekit.js
@@ -50,11 +50,11 @@ const authorizeEndpoint = "oauth/authorize";
* @param {string} envUrl The environment url
* @param {string} clientId The client id
* @param {string} clientSecret The client secret
- * @returns {Scalekit} Returns the scalekit instance
+ * @returns {ScalekitClient} Returns the scalekit instance
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
*/
-class Scalekit {
+class ScalekitClient {
constructor(envUrl, clientId, clientSecret) {
this.coreClient = new core_1.default(envUrl, clientId, clientSecret);
this.grpcConnect = new connect_1.default(this.coreClient);
@@ -73,6 +73,8 @@ class Scalekit {
* @param {string} options.domainHint Domain hint parameter
* @param {string} options.connectionId Connection id parameter
* @param {string} options.organizationId Organization id parameter
+ * @param {string} options.codeChallenge Code challenge parameter in case of PKCE
+ * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
*
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
@@ -82,24 +84,24 @@ class Scalekit {
getAuthorizationUrl(redirectUri, options) {
var _a;
const defaultOptions = {
- scopes: ['openid', 'profile']
+ scopes: ['openid', 'profile', 'email']
};
options = Object.assign(Object.assign({}, defaultOptions), options);
- const qs = qs_1.default.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ response_type: 'code', client_id: this.coreClient.clientId, redirect_uri: redirectUri, scope: (_a = options.scopes) === null || _a === void 0 ? void 0 : _a.join(" ") }, (options.state && { state: options.state })), (options.nonce && { nonce: options.nonce })), (options.loginHint && { login_hint: options.loginHint })), (options.domainHint && { domain_hint: options.domainHint })), (options.domainHint && { domain: options.domainHint })), (options.connectionId && { connection_id: options.connectionId })), (options.organizationId && { organization_id: options.organizationId })));
+ const qs = qs_1.default.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ response_type: 'code', client_id: this.coreClient.clientId, redirect_uri: redirectUri, scope: (_a = options.scopes) === null || _a === void 0 ? void 0 : _a.join(" ") }, (options.state && { state: options.state })), (options.nonce && { nonce: options.nonce })), (options.loginHint && { login_hint: options.loginHint })), (options.domainHint && { domain_hint: options.domainHint })), (options.domainHint && { domain: options.domainHint })), (options.connectionId && { connection_id: options.connectionId })), (options.organizationId && { organization_id: options.organizationId })), (options.codeChallenge && { code_challenge: options.codeChallenge })), (options.codeChallengeMethod && { code_challenge_method: options.codeChallengeMethod })));
return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}`;
}
/**
* Authenticate with the code
- * @param {CodeAuthenticationOptions} options Code authentication options
- * @param {string} options.code Code
- * @param {string} options.redirectUri Redirect uri
- * @param {string} options.codeVerifier Code verifier
- * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token
+ * @param {string} code Code
+ * @param {string} redirectUri Redirect uri
+ * @param {AuthenticationOptions} options Code authentication options
+ * @param {string} options.codeVerifier Code verifier in case of PKCE
+ * @returns {Promise} Returns user, id token and access token
*/
- authenticateWithCode(options) {
+ authenticateWithCode(code, redirectUri, options) {
return __awaiter(this, void 0, void 0, function* () {
- const res = yield this.coreClient.authenticate(qs_1.default.stringify(Object.assign({ code: options.code, redirect_uri: options.redirectUri, grant_type: scalekit_1.GrantType.AuthorizationCode, client_id: this.coreClient.clientId, client_secret: this.coreClient.clientSecret }, (options.codeVerifier && { code_verifier: options.codeVerifier }))));
- const { id_token, access_token } = res.data;
+ const res = yield this.coreClient.authenticate(qs_1.default.stringify(Object.assign({ code: code, redirect_uri: redirectUri, grant_type: scalekit_1.GrantType.AuthorizationCode, client_id: this.coreClient.clientId, client_secret: this.coreClient.clientSecret }, ((options === null || options === void 0 ? void 0 : options.codeVerifier) && { code_verifier: options.codeVerifier }))));
+ const { id_token, access_token, expires_in } = res.data;
const claims = jose.decodeJwt(id_token);
const user = {};
for (const [k, v] of Object.entries(claims)) {
@@ -110,7 +112,8 @@ class Scalekit {
return {
user,
idToken: id_token,
- accessToken: access_token
+ accessToken: access_token,
+ expiresIn: expires_in
};
});
}
@@ -136,5 +139,5 @@ class Scalekit {
});
}
}
-exports.default = Scalekit;
+exports.default = ScalekitClient;
//# sourceMappingURL=scalekit.js.map
\ No newline at end of file
diff --git a/lib/scalekit.js.map b/lib/scalekit.js.map
index a233a80..7755462 100644
--- a/lib/scalekit.js.map
+++ b/lib/scalekit.js.map
@@ -1 +1 @@
-{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../src/scalekit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAA6B;AAC7B,wDAAoC;AACpC,8DAA4C;AAC5C,2CAAyD;AACzD,kDAAgC;AAChC,sDAAoC;AACpC,kEAAgD;AAChD,+CAAiG;AAGjG,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C;;;;;;;;EAQE;AACF,MAAqB,QAAQ;IAM3B,YACE,MAAc,EACd,QAAgB,EAChB,YAAoB;QAEpB,IAAI,CAAC,UAAU,GAAG,IAAI,cAAU,CAC9B,MAAM,EACN,QAAQ,EACR,YAAY,CACb,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAW,CAChC,IAAI,CAAC,UAAU,CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAkB,CACxC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAgB,CACpC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAY,CAC5B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAA;I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AK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KAAA;CACF;AAlID,2BAkIC"}
\ No newline at end of file
+{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../src/scalekit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAA6B;AAC7B,wDAAoC;AACpC,8DAA4C;AAC5C,2CAAyD;AACzD,kDAAgC;AAChC,sDAAoC;AACpC,kEAAgD;AAChD,+CAAqH;AAGrH,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C;;;;;;;;EAQE;AACF,MAAqB,cAAc;IAMjC,YACE,MAAc,EACd,QAAgB,EAChB,YAAoB;QAEpB,IAAI,CAAC,UAAU,GAAG,IAAI,cAAU,CAC9B,MAAM,EACN,QAAQ,EACR,YAAY,CACb,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAW,CAChC,IAAI,CAAC,UAAU,CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAkB,CACxC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAgB,CACpC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAY,CAC5B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,mBAAmB,CACjB,WAAmB,EACnB,OAAiC;;QAEjC,MAAM,cAAc,GAA4B;YAC9C,MAAM,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;SACvC,CAAA;QACD,OAAO,mCACF,cAAc,GACd,OAAO,CACX,CAAA;QACD,MAAM,EAAE,GAAG,YAAW,CAAC,SAAS,iIAC9B,aAAa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AK,CAAC;YACf,CAAC;QACH,CAAC;KAAA;CACF;AA3ID,iCA2IC"}
\ No newline at end of file
diff --git a/lib/types/user.d.ts b/lib/types/auth.d.ts
similarity index 93%
rename from lib/types/user.d.ts
rename to lib/types/auth.d.ts
index 6f4d4ad..58ba70f 100644
--- a/lib/types/user.d.ts
+++ b/lib/types/auth.d.ts
@@ -54,3 +54,8 @@ export type IdTokenClaim = {
identities: IdTokenClaimIdentity[];
metadata: string | undefined;
};
+export type TokenResponse = {
+ access_token: string;
+ id_token: string;
+ expires_in: number;
+};
diff --git a/lib/types/user.js b/lib/types/auth.js
similarity index 70%
rename from lib/types/user.js
rename to lib/types/auth.js
index 33269d3..1bf0817 100644
--- a/lib/types/user.js
+++ b/lib/types/auth.js
@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-//# sourceMappingURL=user.js.map
\ No newline at end of file
+//# sourceMappingURL=auth.js.map
\ No newline at end of file
diff --git a/lib/types/auth.js.map b/lib/types/auth.js.map
new file mode 100644
index 0000000..8e51891
--- /dev/null
+++ b/lib/types/auth.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":""}
\ No newline at end of file
diff --git a/lib/types/scalekit.d.ts b/lib/types/scalekit.d.ts
index d487e71..feff268 100644
--- a/lib/types/scalekit.d.ts
+++ b/lib/types/scalekit.d.ts
@@ -1,3 +1,4 @@
+import { User } from './auth';
export declare enum GrantType {
AuthorizationCode = "authorization_code",
RefreshToken = "refresh_token",
@@ -11,16 +12,15 @@ export type AuthorizationUrlOptions = {
nonce?: string;
domainHint?: string;
loginHint?: string;
+ codeChallenge?: string;
+ codeChallengeMethod?: string;
};
-export type CodeAuthenticationOptions = {
- code: string;
- redirectUri: string;
+export type AuthenticationOptions = {
codeVerifier?: string;
};
-export type RefreshTokenAuthenticationOptions = {
- code: string;
- redirectUri: string;
-};
-export type AuthenticationOptions = {
- refreshToken: string;
+export type AuthenticationResponse = {
+ user: User;
+ idToken: string;
+ accessToken: string;
+ expiresIn: number;
};
diff --git a/lib/types/scalekit.js.map b/lib/types/scalekit.js.map
index 30b39be..888f314 100644
--- a/lib/types/scalekit.js.map
+++ b/lib/types/scalekit.js.map
@@ -1 +1 @@
-{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../../src/types/scalekit.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,qDAAwC,CAAA;IACxC,2CAA8B,CAAA;IAC9B,qDAAwC,CAAA;AAC1C,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
\ No newline at end of file
+{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../../src/types/scalekit.ts"],"names":[],"mappings":";;;AAEA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,qDAAwC,CAAA;IACxC,2CAA8B,CAAA;IAC9B,qDAAwC,CAAA;AAC1C,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
\ No newline at end of file
diff --git a/lib/types/user.js.map b/lib/types/user.js.map
deleted file mode 100644
index 07c1726..0000000
--- a/lib/types/user.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""}
\ No newline at end of file
diff --git a/package.json b/package.json
index 7fcb266..d23f50d 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "version": "1.0.3",
+ "version": "1.0.4",
"name": "@scalekit-sdk/node",
"description": "Official Scalekit Node SDK",
"main": "lib/index.js",
diff --git a/src/connect.ts b/src/connect.ts
index f121a6a..b1db374 100644
--- a/src/connect.ts
+++ b/src/connect.ts
@@ -1,7 +1,7 @@
import { ServiceType } from '@bufbuild/protobuf';
import { PromiseClient, Transport, createPromiseClient } from '@connectrpc/connect';
import { createGrpcTransport } from '@connectrpc/connect-node';
-import CoreClient from './core';
+import CoreClient, { headers } from './core';
export default class GrpcConnect {
private transport: Transport;
@@ -14,11 +14,11 @@ export default class GrpcConnect {
interceptors: [
(next) => {
return (req) => {
- req.header.set("User-Agent", this.coreClient.userAgent)
- req.header.set("x-sdk-version", this.coreClient.sdkVersion)
- req.header.set("x-api-version", this.coreClient.apiVersion)
+ req.header.set(headers['user-agent'], this.coreClient.userAgent)
+ req.header.set(headers['x-sdk-version'], this.coreClient.sdkVersion)
+ req.header.set(headers['x-api-version'], this.coreClient.apiVersion)
if (this.coreClient.accessToken) {
- req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`)
+ req.header.set(headers.authorization, `Bearer ${this.coreClient.accessToken}`)
}
return next(req)
}
diff --git a/src/connection.ts b/src/connection.ts
index d1e2891..613266b 100644
--- a/src/connection.ts
+++ b/src/connection.ts
@@ -2,7 +2,7 @@ import { PromiseClient } from '@connectrpc/connect';
import GrpcConnect from './connect';
import CoreClient from './core';
import { ConnectionService } from './pkg/grpc/scalekit/v1/connections/connections_connect';
-import { GetConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
+import { GetConnectionResponse, ToggleConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
export default class ConnectionClient {
private client: PromiseClient;
@@ -15,11 +15,11 @@ export default class ConnectionClient {
/**
* Get a connection by id and organization id
- * @param id The connection id
* @param organizationId The organization id
+ * @param id The connection id
* @returns {Promise} The connection
*/
- async getConnection(id: string, organizationId: string): Promise {
+ async getConnection(organizationId: string, id: string): Promise {
return this.coreClient.connectExec(
this.client.getConnection,
{
@@ -65,5 +65,43 @@ export default class ConnectionClient {
},
)
}
+
+ /**
+ * Enable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ async enableConnection(organizationId: string, id: string): Promise {
+ return this.coreClient.connectExec(
+ this.client.enableConnection,
+ {
+ id,
+ identities: {
+ case: 'organizationId',
+ value: organizationId
+ }
+ },
+ )
+ }
+
+ /**
+ * Disable a connection by id and organization id
+ * @param organizationId The organization id
+ * @param id The connection id
+ * @returns {Promise} The connection enable response
+ */
+ async disableConnection(organizationId: string, id: string): Promise {
+ return this.coreClient.connectExec(
+ this.client.disableConnection,
+ {
+ id,
+ identities: {
+ case: 'organizationId',
+ value: organizationId
+ }
+ },
+ )
+ }
}
diff --git a/src/constants/user.ts b/src/constants/user.ts
index e713f5c..214c2c1 100644
--- a/src/constants/user.ts
+++ b/src/constants/user.ts
@@ -1,4 +1,4 @@
-import type { IdTokenClaim, User } from '../types/user';
+import type { IdTokenClaim, User } from '../types/auth';
export const IdTokenClaimToUserMap: { [k in keyof IdTokenClaim]: keyof User } = {
"sub": "id",
diff --git a/src/core.ts b/src/core.ts
index 6471422..c77fb90 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -5,6 +5,14 @@ import os from "os";
import QueryString from "qs";
import { GrantType } from './types/scalekit';
import { ErrorInfo } from './pkg/grpc/scalekit/v1/errdetails/errdetails_pb';
+import { TokenResponse } from './types/auth';
+
+export const headers = {
+ "user-agent": "user-agent",
+ "x-sdk-version": "x-sdk-version",
+ "x-api-version": "x-api-version",
+ "authorization": "authorization"
+}
const tokenEndpoint = "oauth/token";
const jwksEndpoint = "keys";
@@ -12,7 +20,7 @@ export default class CoreClient {
public keys: JWK[] = [];
public accessToken: string | null = null;
public axios: Axios;
- public sdkVersion = `Scalekit-Node/1.0.3`;
+ public sdkVersion = `Scalekit-Node/1.0.4`;
public apiVersion = "20240430";
public userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os.arch()})`;
constructor(
@@ -22,11 +30,11 @@ export default class CoreClient {
) {
this.axios = axios.create({ baseURL: envUrl });
this.axios.interceptors.request.use((config) => {
- config.headers["User-Agent"] = this.userAgent;
- config.headers["x-sdk-version"] = this.sdkVersion;
- config.headers["x-api-version"] = this.apiVersion;
+ config.headers[headers['user-agent']] = this.userAgent;
+ config.headers[headers['x-sdk-version']] = this.sdkVersion;
+ config.headers[headers['x-api-version']] = this.apiVersion;
if (this.accessToken) {
- config.headers["Authorization"] = `Bearer ${this.accessToken}`;
+ config.headers[headers.authorization] = `Bearer ${this.accessToken}`;
}
return config;
@@ -46,10 +54,10 @@ export default class CoreClient {
/**
* Authenticate with the code
* @param {string} data Data to authenticate
- * @returns {Promise>} Returns access token and id token
+ * @returns {Promise>} Returns access token and id token
*/
- async authenticate(data: string): Promise> {
- return this.axios.post<{ access_token: string, id_token: string }>(
+ async authenticate(data: string): Promise> {
+ return this.axios.post(
tokenEndpoint,
data,
{
@@ -89,10 +97,10 @@ export default class CoreClient {
return res;
} catch (error) {
if (retryLeft > 0) {
- let isUnauthenticatedError = false;
+ let isUnAuthenticatedError = false;
if (error instanceof AxiosError) {
if (error.status == HttpStatusCode.Unauthorized) {
- isUnauthenticatedError = true;
+ isUnAuthenticatedError = true;
} else {
throw new Error(error.message);
}
@@ -100,23 +108,22 @@ export default class CoreClient {
// ConnectError is a custom error class that extends Error class and has a code property
if (error instanceof ConnectError) {
if (error.code == Code.Unauthenticated) {
- isUnauthenticatedError = true;
- } else {
- if (error.code == Code.InvalidArgument) {
- const message = error.findDetails(ErrorInfo).map((detail) => {
- if (detail.validationErrorInfo) {
- return detail.validationErrorInfo.fieldViolations.map((fv) => {
- return `${fv.field}: ${fv.description}`
- }).join("\n")
- }
- return error.message;
- }).join("\n")
- throw new Error(message);
- }
- throw new Error(error.message);
+ isUnAuthenticatedError = true;
+ }
+ if (error.code == Code.InvalidArgument) {
+ const messages = [error.message]
+ error.findDetails(ErrorInfo).forEach((detail) => {
+ if (detail.validationErrorInfo) {
+ detail.validationErrorInfo.fieldViolations.forEach((fv) => {
+ messages.push(`${fv.field}: ${fv.description}`)
+ })
+ }
+ })
+
+ throw new Error(messages.join("\n"));
}
}
- if (isUnauthenticatedError) {
+ if (isUnAuthenticatedError) {
await this.authenticateClient();
return this.connectExec(fn, data, retryLeft - 1);
}
diff --git a/src/domain.ts b/src/domain.ts
index d789e13..eb37da8 100644
--- a/src/domain.ts
+++ b/src/domain.ts
@@ -34,27 +34,6 @@ export default class DomainClient {
)
}
- /**
- * Get a domain by id
- * @param {object} options The options to get a domain
- * @param {string} options.id The domain id
- * @param {string} options.organizationId The organization id
- * @returns {Promise} The domain
- */
- async getDomain(options: { id: string, organizationId: string }): Promise {
- const { id, organizationId } = options;
- return this.coreClient.connectExec(
- this.client.getDomain,
- {
- id,
- identities: {
- case: 'organizationId',
- value: organizationId
- }
- }
- )
- }
-
/**
* List domains for an organization
* @param organizationId The organization id
diff --git a/src/index.ts b/src/index.ts
index 92d415b..8f88501 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,7 +1,7 @@
-import Scalekit from "./scalekit";
+import ScalekitClient from "./scalekit";
-export { Scalekit };
-export default Scalekit;
+export { ScalekitClient };
+export default ScalekitClient;
export * from "./types/scalekit";
-export * from "./types/user";
\ No newline at end of file
+export * from "./types/auth";
\ No newline at end of file
diff --git a/src/organization.ts b/src/organization.ts
index d440f16..3cf836b 100644
--- a/src/organization.ts
+++ b/src/organization.ts
@@ -1,4 +1,4 @@
-import { PartialMessage } from '@bufbuild/protobuf';
+import { Empty, PartialMessage } from '@bufbuild/protobuf';
import { PromiseClient } from '@connectrpc/connect';
import GrpcConnect from './connect';
import CoreClient from './core';
@@ -16,19 +16,20 @@ export default class OrganizationClient {
/**
* Create an organization with the given name. Optionally, you can provide an external id.
+ * @param {string} name The organization name
* @param {object} options The options to create an organization
- * @param {string} options.name The organization name
* @param {string} options.externalId The external id
* @returns {Promise} The created organization
*/
- async createOrganization(options: { name: string, externalId?: string }): Promise {
- const { name, externalId } = options;
+ async createOrganization(name: string, options?: { externalId?: string }): Promise {
return this.coreClient.connectExec(
this.client.createOrganization,
{
organization: {
displayName: name,
- externalId: externalId
+ ...(options?.externalId && {
+ externalId: options.externalId
+ })
}
}
)
@@ -107,6 +108,20 @@ export default class OrganizationClient {
)
}
+ /**
+ * Delete an organization by id
+ * @param {string} organizationId The organization id
+ * @returns {Promise} Returns nothing
+ */
+ async deleteOrganization(organizationId: string): Promise {
+ return this.coreClient.connectExec(
+ this.client.deleteOrganization,
+ {
+ identities: { case: "id", value: organizationId, },
+ },
+ )
+ }
+
/**
* Generate admin portal link for an organization
* @param organizationId The organization id
@@ -125,5 +140,37 @@ export default class OrganizationClient {
return response.link
}
+
+ /**
+ * Get admin portal links for an organization
+ * @param organizationId The organization id
+ * @returns {Promise } The admin portal link object with expiration time and location
+ */
+ async getPortalLinks(organizationId: string): Promise {
+ const response = await this.coreClient.connectExec(
+ this.client.getPortalLinks,
+ {
+ id: organizationId
+ },
+ )
+
+ return response.links
+ }
+
+ /**
+ * Delete admin portal link for an organization
+ * @param organizationId The organization id
+ * @param linkId The link id
+ * @returns {Promise} Returns nothing
+ */
+ async deletePortalLink(organizationId: string, linkId: string): Promise {
+ return this.coreClient.connectExec(
+ this.client.deletePortalLink,
+ {
+ id: organizationId,
+ linkId
+ },
+ )
+ }
}
diff --git a/src/scalekit.ts b/src/scalekit.ts
index cfb3c99..60184f0 100644
--- a/src/scalekit.ts
+++ b/src/scalekit.ts
@@ -6,8 +6,8 @@ import { IdTokenClaimToUserMap } from './constants/user';
import CoreClient from './core';
import DomainClient from './domain';
import OrganizationClient from './organization';
-import { AuthorizationUrlOptions, CodeAuthenticationOptions, GrantType } from './types/scalekit';
-import { IdTokenClaim, User } from './types/user';
+import { AuthorizationUrlOptions, AuthenticationOptions, GrantType, AuthenticationResponse } from './types/scalekit';
+import { IdTokenClaim, User } from './types/auth';
const authorizeEndpoint = "oauth/authorize";
@@ -16,11 +16,11 @@ const authorizeEndpoint = "oauth/authorize";
* @param {string} envUrl The environment url
* @param {string} clientId The client id
* @param {string} clientSecret The client secret
- * @returns {Scalekit} Returns the scalekit instance
+ * @returns {ScalekitClient} Returns the scalekit instance
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
*/
-export default class Scalekit {
+export default class ScalekitClient {
private readonly coreClient: CoreClient;
private readonly grpcConnect: GrpcConnect;
readonly organization: OrganizationClient;
@@ -65,6 +65,8 @@ export default class Scalekit {
* @param {string} options.domainHint Domain hint parameter
* @param {string} options.connectionId Connection id parameter
* @param {string} options.organizationId Organization id parameter
+ * @param {string} options.codeChallenge Code challenge parameter in case of PKCE
+ * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
*
* @example
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
@@ -76,7 +78,7 @@ export default class Scalekit {
options?: AuthorizationUrlOptions
): string {
const defaultOptions: AuthorizationUrlOptions = {
- scopes: ['openid', 'profile']
+ scopes: ['openid', 'profile', 'email']
}
options = {
...defaultOptions,
@@ -94,6 +96,8 @@ export default class Scalekit {
...(options.domainHint && { domain: options.domainHint }),
...(options.connectionId && { connection_id: options.connectionId }),
...(options.organizationId && { organization_id: options.organizationId }),
+ ...(options.codeChallenge && { code_challenge: options.codeChallenge }),
+ ...(options.codeChallengeMethod && { code_challenge_method: options.codeChallengeMethod })
})
return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}`
@@ -101,24 +105,28 @@ export default class Scalekit {
/**
* Authenticate with the code
- * @param {CodeAuthenticationOptions} options Code authentication options
- * @param {string} options.code Code
- * @param {string} options.redirectUri Redirect uri
- * @param {string} options.codeVerifier Code verifier
- * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token
+ * @param {string} code Code
+ * @param {string} redirectUri Redirect uri
+ * @param {AuthenticationOptions} options Code authentication options
+ * @param {string} options.codeVerifier Code verifier in case of PKCE
+ * @returns {Promise} Returns user, id token and access token
*/
- async authenticateWithCode(options: CodeAuthenticationOptions): Promise<{ user: Partial; idToken: string; accessToken: string; }> {
+ async authenticateWithCode(
+ code: string,
+ redirectUri: string,
+ options?: AuthenticationOptions,
+ ): Promise {
const res = await this.coreClient.authenticate(QueryString.stringify({
- code: options.code,
- redirect_uri: options.redirectUri,
+ code: code,
+ redirect_uri: redirectUri,
grant_type: GrantType.AuthorizationCode,
client_id: this.coreClient.clientId,
client_secret: this.coreClient.clientSecret,
- ...(options.codeVerifier && { code_verifier: options.codeVerifier })
+ ...(options?.codeVerifier && { code_verifier: options.codeVerifier })
}))
- const { id_token, access_token } = res.data;
+ const { id_token, access_token, expires_in } = res.data;
const claims = jose.decodeJwt(id_token);
- const user: Partial = {};
+ const user = {};
for (const [k, v] of Object.entries(claims)) {
if (IdTokenClaimToUserMap[k]) {
user[IdTokenClaimToUserMap[k]] = v;
@@ -128,7 +136,8 @@ export default class Scalekit {
return {
user,
idToken: id_token,
- accessToken: access_token
+ accessToken: access_token,
+ expiresIn: expires_in
}
}
diff --git a/src/types/user.ts b/src/types/auth.ts
similarity index 93%
rename from src/types/user.ts
rename to src/types/auth.ts
index 692aba0..0306155 100644
--- a/src/types/user.ts
+++ b/src/types/auth.ts
@@ -56,4 +56,10 @@ export type IdTokenClaim = {
updated_at: string | undefined;
identities: IdTokenClaimIdentity[];
metadata: string | undefined;
+}
+
+export type TokenResponse = {
+ access_token: string;
+ id_token: string;
+ expires_in: number;
}
\ No newline at end of file
diff --git a/src/types/scalekit.ts b/src/types/scalekit.ts
index 45c615b..3aeeebf 100644
--- a/src/types/scalekit.ts
+++ b/src/types/scalekit.ts
@@ -1,3 +1,5 @@
+import { User } from './auth';
+
export enum GrantType {
AuthorizationCode = 'authorization_code',
RefreshToken = 'refresh_token',
@@ -12,19 +14,17 @@ export type AuthorizationUrlOptions = {
nonce?: string;
domainHint?: string;
loginHint?: string;
+ codeChallenge?: string;
+ codeChallengeMethod?: string;
}
-export type CodeAuthenticationOptions = {
- code: string;
- redirectUri: string;
- codeVerifier?: string;
-}
-
-export type RefreshTokenAuthenticationOptions = {
- code: string;
- redirectUri: string;
+export type AuthenticationOptions = {
+ codeVerifier?: string;
}
-export type AuthenticationOptions = {
- refreshToken: string;
+export type AuthenticationResponse = {
+ user: User;
+ idToken: string;
+ accessToken: string;
+ expiresIn: number;
}
\ No newline at end of file