diff --git a/crunchy.ts b/crunchy.ts index 673fd54..37e97ad 100644 --- a/crunchy.ts +++ b/crunchy.ts @@ -101,6 +101,9 @@ export default class Crunchy implements ServiceClass { password: argv.password ?? await shlp.question('[Q] PASSWORD ') }); } + else if (argv.token) { + await this.loginWithToken(argv.token); + } else if(argv.cmsindex){ await this.refreshToken(); await this.getCmsData(); @@ -289,6 +292,29 @@ export default class Crunchy implements ServiceClass { }); } + public async loginWithToken(refreshToken: string) { + const authData = new URLSearchParams({ + 'refresh_token': refreshToken, + 'grant_type': 'refresh_token', + 'scope': 'offline_access' + }).toString(); + const authReqOpts: reqModule.Params = { + method: 'POST', + headers: api.beta_authHeaderMob, + body: authData + }; + const authReq = await this.req.getData(api.beta_auth, authReqOpts); + if(!authReq.ok || !authReq.res){ + console.error('Token Authentication failed!'); + return; + } + this.token = JSON.parse(authReq.res.body); + this.token.expires = new Date(Date.now() + this.token.expires_in); + yamlCfg.saveCRToken(this.token); + await this.getProfile(false); + await this.getCMStoken(true); + } + public async refreshToken(ifNeeded = false, silent = false) { if(!this.token.access_token && !this.token.refresh_token || this.token.access_token && !this.token.refresh_token){ await this.doAnonymousAuth(); diff --git a/modules/module.app-args.ts b/modules/module.app-args.ts index 7e7629e..5b38564 100644 --- a/modules/module.app-args.ts +++ b/modules/module.app-args.ts @@ -17,6 +17,7 @@ let argvC: { forceMuxer: AvailableMuxer|undefined; username: string|undefined, password: string|undefined, + token: string|undefined, silentAuth: boolean, skipSubMux: boolean, downloadArchive: boolean, diff --git a/modules/module.args.ts b/modules/module.args.ts index f9d01df..4272389 100644 --- a/modules/module.args.ts +++ b/modules/module.args.ts @@ -673,6 +673,18 @@ const args: TAppArg[] = [ default: false } }, + { + name: 'token', + describe: 'Allows you to login with your token (Example on crunchy is Refresh Token/etp-rt cookie)', + docDescribe: true, + group: 'auth', + service: ['crunchy'], + type: 'string', + usage: '${token}', + default: { + default: undefined + } + }, { name: 'forceMuxer', describe: 'Force the program to use said muxer or don\'t mux if the given muxer is not present',