mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-03-21 18:04:10 -05:00
Add a command to get a NookLink user token
This commit is contained in:
parent
39bfc8ab39
commit
ed91f2d085
|
|
@ -7,3 +7,4 @@ export * as dumpNewspapers from './dump-newspapers.js';
|
|||
export * as keyboard from './keyboard.js';
|
||||
export * as reactions from './reactions.js';
|
||||
export * as postReaction from './post-reaction.js';
|
||||
export * as userToken from './user-token.js';
|
||||
|
|
|
|||
53
src/cli/nooklink/user-token.ts
Normal file
53
src/cli/nooklink/user-token.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import createDebug from 'debug';
|
||||
import type { Arguments as ParentArguments } from '../nooklink.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getUserToken } from '../../common/auth/nooklink.js';
|
||||
|
||||
const debug = createDebug('cli:nooklink:user-token');
|
||||
|
||||
export const command = 'user-token';
|
||||
export const desc = 'Get the player\'s NookLink user authentication token';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
}).option('token', {
|
||||
describe: 'Nintendo Account session token',
|
||||
type: 'string',
|
||||
}).option('islander', {
|
||||
describe: 'NookLink user ID',
|
||||
type: 'string',
|
||||
}).option('json', {
|
||||
describe: 'Output raw JSON',
|
||||
type: 'boolean',
|
||||
}).option('json-pretty-print', {
|
||||
describe: 'Output pretty-printed JSON',
|
||||
type: 'boolean',
|
||||
});
|
||||
}
|
||||
|
||||
type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
|
||||
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
const storage = await initStorage(argv.dataPath);
|
||||
|
||||
const usernsid = argv.user ?? await storage.getItem('SelectedUser');
|
||||
const token: string = argv.token ||
|
||||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {nooklinkuser, data} = await getUserToken(storage, token, argv.islander, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
if (argv.json || argv.jsonPrettyPrint) {
|
||||
const result = {
|
||||
auth_token: data.token.token,
|
||||
expires_at: data.token.expireAt,
|
||||
user_id: data.user,
|
||||
};
|
||||
|
||||
console.log(JSON.stringify(result, null, argv.jsonPrettyPrint ? 4 : 0));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(data.token.token);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user