Skip to content

Allow authenticating auth routes with existing token instead of requiring a clientId and clientSecret #58

@colin-oos

Description

@colin-oos

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @boxcast/boxcast-sdk-js@2.0.2 for the project I'm working on. I wanted to be able to use the sdk in node.js but I am using OAuth tokens rather than a clientId:clientSecret pair to authenticate. Currently your SDK only accepts a clientId and clientSecret to authenticate and generate a token, however since I already have a token I want to be able to just pass my existing token as the first argument. I expect this would be something others would need to be able to do as well so I decided to create this issue for further review.

Here is the diff that solved my problem:

diff --git a/node_modules/@boxcast/boxcast-sdk-js/src/api/auth_routes.ts b/node_modules/@boxcast/boxcast-sdk-js/src/api/auth_routes.ts
index 13600b7..1714ae3 100644
--- a/node_modules/@boxcast/boxcast-sdk-js/src/api/auth_routes.ts
+++ b/node_modules/@boxcast/boxcast-sdk-js/src/api/auth_routes.ts
@@ -21,7 +21,13 @@ export default class AuthenticatedRoutes {
     STATE.lastAuthToken = null;
   }
 
-  async authenticate(clientId, clientSecret) {
+  async authenticate(clientId, clientSecret?) {
+    if (clientId && !clientSecret) {
+      STATE.lastAuthToken = clientId;
+      return {
+        access_token: clientId,
+      }
+    }
     try {
       const body = new URLSearchParams({
         'grant_type': 'client_credentials',

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions