mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-14 21:40:05 -05:00
SplatNet 3 authentication
This commit is contained in:
@@ -2,6 +2,7 @@ export * as users from './users.js';
|
||||
export * as nso from './nso.js';
|
||||
export * as splatnet2 from './splatnet2.js';
|
||||
export * as nooklink from './nooklink.js';
|
||||
export * as splatnet3 from './splatnet3.js';
|
||||
export * as pctl from './pctl.js';
|
||||
export * as androidZncaApiServerFrida from './android-znca-api-server-frida.js';
|
||||
export * as util from './util.js';
|
||||
|
||||
@@ -59,7 +59,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
// This means the other user had already sent this user a friend request,
|
||||
// so sending them a friend request just accepted theirs
|
||||
const friends = await nso.getFriendList();
|
||||
const friend = friends.result.friends.find(f => f.nsaId === nsa_id);
|
||||
const friend = friends.friends.find(f => f.nsaId === nsa_id);
|
||||
|
||||
if (friend) {
|
||||
console.log('You are now friends with %s.', friend.name);
|
||||
|
||||
29
src/cli/splatnet3.ts
Normal file
29
src/cli/splatnet3.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import process from 'node:process';
|
||||
import createDebug from 'debug';
|
||||
import type { Arguments as ParentArguments } from '../cli.js';
|
||||
import { Argv, YargsArguments } from '../util/yargs.js';
|
||||
import * as commands from './splatnet3/index.js';
|
||||
|
||||
const debug = createDebug('cli:splatnet3');
|
||||
|
||||
export const command = 'splatnet3 <command>';
|
||||
export const desc = 'SplatNet 3';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
for (const command of Object.values(commands)) {
|
||||
// @ts-expect-error
|
||||
yargs.command(command);
|
||||
}
|
||||
|
||||
return yargs.option('znc-proxy-url', {
|
||||
describe: 'URL of Nintendo Switch Online app API proxy server to use',
|
||||
type: 'string',
|
||||
default: process.env.ZNC_PROXY_URL,
|
||||
}).option('auto-update-session', {
|
||||
describe: 'Automatically obtain and refresh the SplatNet 3 access token',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
});
|
||||
}
|
||||
|
||||
export type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
2
src/cli/splatnet3/index.ts
Normal file
2
src/cli/splatnet3/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * as user from './user.js';
|
||||
export * as token from './token.js';
|
||||
51
src/cli/splatnet3/token.ts
Normal file
51
src/cli/splatnet3/token.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import createDebug from 'debug';
|
||||
import type { Arguments as ParentArguments } from '../splatnet3.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getBulletToken } from '../../common/auth/splatnet3.js';
|
||||
import { SplatNet3CliTokenData } from '../../api/splatnet3.js';
|
||||
|
||||
const debug = createDebug('cli:splatnet3:token');
|
||||
|
||||
export const command = 'token';
|
||||
export const desc = 'Get the authenticated Nintendo Account\'s SplatNet 3 user data and access 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('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 {splatnet, data} = await getBulletToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
if (argv.json || argv.jsonPrettyPrint) {
|
||||
const result: SplatNet3CliTokenData = {
|
||||
bullet_token: data.bullet_token.bulletToken,
|
||||
expires_at: data.expires_at,
|
||||
language: data.bullet_token.lang,
|
||||
version: data.version,
|
||||
};
|
||||
|
||||
console.log(JSON.stringify(result, null, argv.jsonPrettyPrint ? 4 : 0));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(data.bullet_token.bulletToken);
|
||||
}
|
||||
33
src/cli/splatnet3/user.ts
Normal file
33
src/cli/splatnet3/user.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import createDebug from 'debug';
|
||||
import type { Arguments as ParentArguments } from '../splatnet3.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getBulletToken } from '../../common/auth/splatnet3.js';
|
||||
|
||||
const debug = createDebug('cli:splatnet3:user');
|
||||
|
||||
export const command = 'user';
|
||||
export const desc = 'Get the authenticated Nintendo Account\'s player record';
|
||||
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
||||
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 {splatnet, data} = await getBulletToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
Reference in New Issue
Block a user