Skip to content

Instantly share code, notes, and snippets.

@basst85
Last active December 16, 2024 14:23
Show Gist options
  • Save basst85/ef5dae992f75ca4773a75f0249583bc1 to your computer and use it in GitHub Desktop.
Save basst85/ef5dae992f75ca4773a75f0249583bc1 to your computer and use it in GitHub Desktop.
Get refresh_token for Lidl Plus API
/**
* Get refresh_token for Lidl Plus API
*
* By: Bastiaan Steinmeier, https://github.com/basst85
*
*/
const { Issuer, generators } = require('openid-client');
const puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors');
const iPhone = devices['iPhone X'];
const urlparse = require('url');
const req = require('request');
let login_email = 'Your Lidl Plus login e-mail';
let login_password = 'Your password';
Issuer.discover('https://accounts.lidl.com')
.then(function (openidIssuer) {
const nonce = generators.nonce();
const code_verifier = generators.codeVerifier();
const code_challenge = generators.codeChallenge(code_verifier);
const client = new openidIssuer.Client({
client_id: 'LidlPlusNativeClient',
redirect_uris: ['com.lidlplus.app://callback'],
response_types: ['code']
});
const loginurl = client.authorizationUrl({
scope: 'openid profile offline_access lpprofile lpapis',
code_challenge,
code_challenge_method: 'S256'
});
//loginurl = loginurl + '&Country=NL&language=NL-NL';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.emulate(iPhone);
await page.goto(loginurl);
await page.click('#btn_continue_login', {waitUntil: 'networkidle0'});
await page.click('#EmailPhone', {waitUntil: 'networkidle0'});
await page.keyboard.type(login_email, {waitUntil: 'networkidle0'});
await page.click('#btn_submit_email', {waitUntil: 'networkidle0'});
await new Promise(r => setTimeout(r, 2000));
await page.click('#Password', {waitUntil: 'networkidle0'});
await page.keyboard.type(login_password, { waitUntil: 'networkidle0'});
page.on('request', request => {
if (request.isNavigationRequest() && request.resourceType() === 'document') {
if(request._url.includes('com.lidlplus.app://callback')){
var url_parts = urlparse.parse(request._url, true);
var query = url_parts.query;
var tokenurl = 'https://accounts.lidl.com/connect/token';
var headers = {
'Authorization': 'Basic TGlkbFBsdXNOYXRpdmVDbGllbnQ6c2VjcmV0',
'Content-Type' : 'application/x-www-form-urlencoded'
};
var form = { grant_type: 'authorization_code', code: query.code, redirect_uri: 'com.lidlplus.app://callback', code_verifier: code_verifier };
req.post({ url: tokenurl, form: form, headers: headers, json:true }, function (e, r, body) {
console.log('Access token:\n', body.access_token, '\n');
console.log('Refresh token:\n', body.refresh_token);
});
}
}
request.continue().catch((err) => {});
});
const response = await page.click('#btn_submit_password', {waitUntil: 'networkidle0'});
await browser.close();
})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment