Browse Source

Add @ssttevee method of authentication (from pull request #43)

Godzil 5 years ago
parent
commit
ab35bb4439
2 changed files with 25 additions and 0 deletions
  1. 4 0
      src/interface/IConfig.d.ts
  2. 21 0
      src/my_request.ts

+ 4 - 0
src/interface/IConfig.d.ts

@@ -23,12 +23,16 @@ interface IConfig {
   retry?: number;
   // Login options
   logUsingApi?: boolean;
+  logUsingCookie?: boolean;
   crSessionUrl?: string;
   crDeviceType?: string;
   crAPIVersion?: string;
   crLocale?: string;
   crSessionKey?: string;
   crLoginUrl?: string;
+  // Third method, injecting data from cookies
+  crUserId?: string;
+  crUserKey?: string;
   // Generated values
   crDeviceId?: string;
   crSessionId?: string;

+ 21 - 0
src/my_request.ts

@@ -16,6 +16,8 @@ const cookieStore = require('tough-cookie-file-store');
 // tslint:disable-next-line:no-var-requires
 const cloudscraper = require('cloudscraper');
 
+const CR_COOKIE_DOMAIN = 'http://crunchyroll.com';
+
 let isAuthenticated = false;
 let isPremium = false;
 
@@ -265,6 +267,25 @@ function authenticate(config: IConfig, done: (err: Error) => void)
         });
       });
     }
+    else if (config.logUsingCookie)
+    {
+      j.setCookie(request.cookie('c_userid=' + config.crUserId + '; Domain=crunchyroll.com; HttpOnly; hostOnly=false;'),
+                  CR_COOKIE_DOMAIN);
+      j.setCookie(request.cookie('c_userkey=' + config.crUserKey + '; Domain=crunchyroll.com; HttpOnly; hostOnly=false;'),
+                  CR_COOKIE_DOMAIN);
+
+      checkIfUserIsAuth(config, (errCheckAuth2) =>
+      {
+        if (isAuthenticated)
+        {
+          return done(null);
+        }
+        else
+        {
+          return done(errCheckAuth2);
+        }
+      });
+    }
     else
     {
       log.error('This method of login is currently unsupported...\n');