Skip to content

Instantly share code, notes, and snippets.

@piglovesyou
Last active July 3, 2022 10:23
Show Gist options
  • Save piglovesyou/8fef7f51216f5f9e21f54e4a5b134256 to your computer and use it in GitHub Desktop.
Save piglovesyou/8fef7f51216f5f9e21f54e4a5b134256 to your computer and use it in GitHub Desktop.
auth.getMobileSession fails
import fetch from 'node-fetch'
import crypto from 'crypto'
import {strictEqual, deepStrictEqual} from 'assert'
function md5(string: string) {
return crypto.createHash('md5').update(string, 'utf8').digest("hex");
}
export async function main() {
const url = new URL(`https://ws.audioscrobbler.com/2.0/`)
const method = `auth.getMobileSession`
const username = 'xxx@gmail.com'
const password = 'xxx'
const api_key = 'xxx'
const api_secret = 'xxx'
const api_sig = md5([
'api_key', api_key,
'method', method,
'password', password,
'username', username,
api_secret,
].join(''))
const payload = {
method,
username,
password,
api_key,
api_sig,
format: 'json',
}
const body = new URLSearchParams(payload).toString()
const json = await fetch(url.href, {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body,
}).then(e => e.json())
deepStrictEqual(json,
{
"message": "Authentication Failed - You do not have permissions to access the service",
"error": 4
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment