Skip to content

Instantly share code, notes, and snippets.

@OJ7
Created September 27, 2023 18:06
Show Gist options
  • Save OJ7/f718cc7f93e5d5e58b847d03b22561ef to your computer and use it in GitHub Desktop.
Save OJ7/f718cc7f93e5d5e58b847d03b22561ef to your computer and use it in GitHub Desktop.
(WIP) JS conversion of psn-account-id.py
import axios, { AxiosRequestConfig } from "axios";
import PromptSync from "prompt-sync";
import endianess from 'endianness'
const CLIENT_ID = "ba495a24-81218c-472342b-b1122d-ff231c1b5745";
const CLIENT_SECRET = "mvai123ZkRsAsI1IBkY";
const LOGIN_URL = `https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize?service_entity=urn:service-entity:psn&response_type=code&client_id=${CLIENT_ID}&redirect_uri=https://remoteplay.dl.playstation.net/remoteplay/redirect&scope=psn:clientapp&request_locale=en_US&ui=pr&service_logo=ps&layout_type=popup&smcid=remoteplay&prompt=always&PlatformPrivacyWs1=minimal&`;
const TOKEN_URL =
"https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/token";
async function main() {
console.log();
console.log("########################################################");
console.log(" Script to determine PSN AccountID");
console.log(" thanks to grill2010");
console.log(" (This script will perform network operations.)");
console.log("########################################################");
console.log();
console.log("➡️ Open the following URL in your Browser and log in:");
console.log();
console.log(LOGIN_URL);
console.log();
console.log(
'➡️ After logging in, when the page shows "redirect", copy the URL from the address bar and paste it here:'
);
// const code_url_s = input('> '); // TODO get input
// const codeURL = "https://remoteplay.dl.playstation.net/remoteplay/redirect?code=NRI7yd&cid=a3bb65c1-bf20-4808-ba0f-9c37c80c3c28";
// const prompt = PromptSync();
// const codeURL = prompt("");
// const searchParams = new URL(codeURL).searchParams;
// const code: string = searchParams.get("code") || "OHgUgV";
const code = 'yrw7kK'
if (!code || code.length === 0) {
throw new Error("☠️ URL did not contain code parameter");
}
console.log("🌏 Requesting OAuth Token");
const requestConfig: AxiosRequestConfig = {
auth: {
username: CLIENT_ID,
password: CLIENT_SECRET,
},
};
const params = new URLSearchParams();
params.append("grant_type", "authorization_code");
params.append("code", code);
params.append(
"redirect_uri",
"https://remoteplay.dl.playstation.net/remoteplay/redirect"
);
try {
// const response = await axios.post(TOKEN_URL, params, {
// ...requestConfig,
// headers: {
// "Content-Type":
// "application/x-www-form-urlencoded;charset=ascii",
// },
// });
// console.log(
// "⚠️ WARNING: From this point on, output might contain sensitive information in some cases!"
// );
// const tokenJSON = response.data;
// const token = tokenJSON.access_token;
// if (!token) {
// throw new Error(
// `☠️ 'access_token' is missing in response JSON:\n${tokenJSON}`
// );
// }
// console.log("🌏 Requesting Account Info");
// const accountRequest = await axios.get(
// `${TOKEN_URL}/${token}`,
// requestConfig
// );
// const accountInfo = accountRequest.data;
// console.log("🥦 Received Account Info:");
// console.log(accountInfo);
// if (!accountInfo["user_id"]) {
// throw new Error(`'user_id' is missing in response or not a string`);
// }
// const userId = +accountInfo["user_id"];
const userId = '26207600777061302621';
const toBytes = Buffer.from(userId, 'hex');
const byte64Encoded = [];
const decoded = String.fromCharCode(...[102, 111, 111])
console.log(userId);
// const userIdBase64 = base64.b64encode(userId.to_bytes(8, 'little')).decode();
// console.log();
// console.log('🍙 This is your AccountID:');
// console.log(userIdBase64);
} catch (error: any) {
console.error(
`☠️ Request failed with error:\n${JSON.stringify(error)}`
);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment