icloud.js icon indicating copy to clipboard operation
icloud.js copied to clipboard

Photos getAlbums fails with 'AUTHENTICATION_FAILED'

Open cdloh opened this issue 9 months ago • 2 comments

Just attempting to use the library based off one of the examples.

const input = require("input");
const { default: iCloud } = require('icloudjs');

module.exports = (async () => {
	const username = process.env.VSCODE_INSPECTOR_OPTIONS ? "" : await input.text("Username");
	const password = username ? await input.password("Password") : null;
	const icloud = new iCloud({
		username: username,
		password: password,
		saveCredentials: false,
		trustDevice: false
	});
	await icloud.authenticate();
	console.log(icloud.status);
	if (icloud.status === "MfaRequested") {
		const mfa = await input.text("MFA Code");
		await icloud.provideMfaCode(mfa);
	}
	await icloud.awaitReady;
	console.log(icloud.status);
	console.log("Hello, " + icloud.accountInfo.dsInfo.fullName);

	const photosService = icloud.getService("photos");
	const albums = await photosService.getAlbums();
	console.log("All your album names: ", Array.from(albums.keys()).join(", "));

	if (require.main === module) {
		console.log("Entering REPL, icloud is available as 'icloud'");
		require("node:repl").start().context.icloud = icloud;
	}
	return icloud;
})();

And getAlbums fails with


TypeError: Cannot read properties of undefined (reading 'map')
    at iCloudPhotosService.getAlbums (SNIP/node_modules/icloudjs/build/services/photos.js:196:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async PRIVATE/icloud/index.js:24:17

Checking the code this fetch is failing.

The response JSON is showing 'AUTHENTICATION_FAILED' however earlier in the code it would appear I am successfully authenticated as the code does output the correct fullname in the console.log

Not sure if related but the PCS check is failing too


[icloud] Could not get PCS state: Error: checkPCS: response code 422
    at iCloudService.checkPCS (/ /icloudjs/build/index.js:306:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async iCloudService._getiCloudCookies (/ /icloudjs/build/index.js:266:25)

cdloh avatar May 08 '25 16:05 cdloh

Hm, that's interesting - I haven't seen that one before, do you have ADP enabled on your account? I can't reproduce it, at least on an account with ADP disabled.

foxt avatar May 10 '25 12:05 foxt

No ADP isn't available in my region.

cdloh avatar May 12 '25 10:05 cdloh