admin管理员组文章数量:1318321
I'm attempting to connect to SharePoint using PnP JS in a Node.js server with username and password authentication, but I am encountering the following error:
I have confirmed that the environment variables (SITE_URL
, USERNAME
, PASSWORD
) are set correctly by logging them to the console. I am using the UserCredentialsFetchClient for authentication, but I have also tried the AdalFetchClient and SPFetchClient with no success.
Things I've tried:
Verified that the environment variables are correctly loaded.
Ensured the URL format (
process.env.SITE_URL
) is correct.Tried different authentication clients (AdalFetchClient, SPFetchClient).
Checked if the SharePoint site is accessible with the provided credentials.
What am I missing or doing wrong?
Any help or suggestions on how to resolve the URL parsing issue or how to correctly authenticate using username and password with PnP JS in Node.js would be greatly appreciated.
import { sp } from '@pnp/sp-commonjs';
import nodejsCommonjs from "@pnp/nodejs-commonjs";
import dotenv from 'dotenv';
dotenv.config();
const { UserCredentialsFetchClient } = nodejsCommonjs;
// Setup PnP JS with username/password authentication
sp.setup({
sp: {
fetchClientFactory: () => {
return new UserCredentialsFetchClient(
process.env.SITE_URL,
process.env.USERNAME,
process.env.PASSWORD
);
},
},
});
// Function to check PnP connection
export const checkConnection = async () => {
try {
const web = await sp.web.select('Title')();
console.log("web...", web);
console.log(`Connected to SharePoint site: ${web.Title}`);
return { success: true, siteTitle: web.Title };
} catch (error) {
console.error('Error connecting to SharePoint:', error.message);
return { success: false, error: error.message };
}
};
// Test the connection
checkConnection().then((result) => {
if (result.success) {
console.log('PnP connection successful:', result.siteTitle);
} else {
console.log('PnP connection failed:', result.error);
}
});
本文标签:
版权声明:本文标题:Error connecting to SharePoint using PnP JS in Node.js with Username and Password Authentication: Failed to parse URL - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742046414a2417812.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论