Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Name and Password Authentication Issue - Non-whitespace before first tag #113

Open
amarj27 opened this issue Jul 18, 2022 · 0 comments

Comments

@amarj27
Copy link

amarj27 commented Jul 18, 2022

I am trying to authenticate to an SP Online site with user name and password but I get this error - Non-whitespace before first tag. On looking at the stack trace and debugging, it looks like the error is coming from the getSamlAssertion method of the AdfsHelper.js file. The method is trying to send a request to and gets a 404 not found response and that is what causes the Non-whitespace before first tag.

(async () => {

const data = await spauth.getAuth('https://[companydomain].sharepoint.com/sites/[sitename]/', {
username: '[username]@[companyname].com',
password: '[password]',
online: true
});

// Optional window and viewport dimentions config
const width = 1920;
const height = 1080;

const browser = await puppeteer.launch();

console.log('starting main');
const page = await browser.newPage();

await page.setExtraHTTPHeaders(data.headers);

await page.setViewport({ width, height });

await page.goto('https://[companydomain].sharepoint.com/sites/[sitename]/SitePages/[pagename]', { waitUntil: 'networkidle0' });

// Save a screenshot of SharePoint page as PDF
await page.pdf({ path: 'sp.pdf', format: 'A4' });

await browser.close();

})()
.catch(console.warn);

AdfsHelper.js -
class AdfsHelper {
static getSamlAssertion(credentials) {
const adfsHost = url.parse(credentials.adfsUrl).host;
const usernameMixedUrl = https://${adfsHost}/adfs/services/trust/13/usernamemixed;
const samlBody = template(AdfsSamlWsfed_1.template)({
to: usernameMixedUrl,
username: credentials.username,
password: credentials.password,
relyingParty: credentials.relyingParty
});
return config_1.request.post(usernameMixedUrl, { // usernameMixedUrl => 'https://saml.iam.[companyname].com/adfs/services/trust/13/usernamemixed'
body: samlBody,
resolveBodyOnly: true,
headers: {
'Content-Length': samlBody.length.toString(),
'Content-Type': 'application/soap+xml; charset=utf-8'
}
})
.then(xmlResponse => { //Response is '404 not found. \n'
const doc = new xmldoc.XmlDocument(xmlResponse); // This is where the Non-whitespace before first tag error comes up from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant