From ab35bb44399c799dbee0d45203e2e033e4afc4d3 Mon Sep 17 00:00:00 2001 From: Godzil Date: Wed, 1 Aug 2018 02:07:21 +0100 Subject: [PATCH] Add @ssttevee method of authentication (from pull request #43) --- src/interface/IConfig.d.ts | 4 ++++ src/my_request.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/interface/IConfig.d.ts b/src/interface/IConfig.d.ts index e332ac9..973b484 100644 --- a/src/interface/IConfig.d.ts +++ b/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; diff --git a/src/my_request.ts b/src/my_request.ts index 477ff19..91ef1d7 100644 --- a/src/my_request.ts +++ b/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');