Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Obe Lahnkara
    @Oberothton_twitter
    Greetings all. I've been trying to setup Sharepoint authentication in Node.js, and despite trying several different methods (node-sp-auth, pnpjs) I'm having all kinds of errors. on the node-sp-auth side, I keep getting an 'invalid argument' error from my type2message response, despite using what i think are the correct credentialoptions. PnP isn't working either, 'cannot read property filter of undefined' and honestly I'm not even sure about the nature of this error. if i'm using Sharepoint On-Prem 2013, where I normally log in automatically with AD, what's the proper library and credential options to use to get the form digest for POST requests?
    Andrew Koltyakov
    @koltyakov
    @Oberothton_twitter, you can node-sp-auth for authentication in on-prem, there are no other alternatives in Node.js, at least I don't know about such. The simplest way of consuming the API without caring too much about headers and digest is PnPjs. With node-sp-auth it can authenticate to on-prem as well. pnp-auth simplifies binding auth fetch client to PnPjs.
    As you experience authentication issues while node-sp-auth supports NTLM&NTLM2, that means that your environment configured with different authentication or auth parameters are provided incorrectly. I'd suggest troubleshooting with this helper repo first.
    Obe Lahnkara
    @Oberothton_twitter
    can pnp not authenticate on-prem on its own? because I've been trying to use it and keep getting some kind of deeply nested json endpoints filter error I don't understand. Meanwhile, I cloned and ran your troubleshooter using the NTLM creds I was before (which should still be the correct domain name, user, password)
    === Error ===
    Error: Invalid argument
    at Object.decodeType2Message (C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\node_modules\node-ntlm-client\lib\ntlm.js:62:9)
    at C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\node_modules\node-sp-auth\lib\src\auth\resolvers\OnpremiseUserCredentials.js:40:35
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\index.js:22:24
    Andrew Koltyakov
    @koltyakov
    What’s the version of Node.js? The latest node-sp-auth update requires at least 10.19.
    Are you sure, your environment is NTLM? But not ADFS or something else? Can it be a mixed auth?

    can pnp not authenticate on-prem on its own?

    Sure thing, no.

    Andrew Koltyakov
    @koltyakov
    Also, what’s the finger print of username/domain? Should be 1) username: john@contoso.com, domain: omitted; 2) username: contoso\john, domain: omitted, 3) username: john, domain: contoso
    However, messing up with creds format would end up with incorrect username and password. So it’s something else.
    Obe Lahnkara
    @Oberothton_twitter
    i've been doing username, password, domain
    it should be NTLM, that's what was used on a C# script i saw used to connect to this SP site @koltyakov
    and i'm on node 14.4
    Obe Lahnkara
    @Oberothton_twitter
    ok i got it
    did some debugging w troubleshooter and established a connection
    now what? do i just copy the private.uat into my credential Options
    ?
    Andrew Koltyakov
    @koltyakov
    What was the issue?
    Obe Lahnkara
    @Oberothton_twitter
    incorrect formatting of sharepoint url
    i'm loading the urls from an external list in a module and noticed i typed them as http instead of https
    edited that in credentialOptions and now i can query the digest perfectly
    Andrew Koltyakov
    @koltyakov
    Cool, happy coding!
    Obe Lahnkara
    @Oberothton_twitter
    and to you!
    Obe Lahnkara
    @Oberothton_twitter
    how do i delete a list item using sp-request? setting X-HTTP-Method to DELETE and setting url to _api/web/lists/getByTitle('Holiday')/items({ID}) doesnt seem to work
    i'm getting a 200 response but the item doesn't delete
    Obe Lahnkara
    @Oberothton_twitter
    @koltyakov sorry for ping but ^do you know how to do this?
    Andrew Koltyakov
    @koltyakov
    This works for me:
    const { AuthConfig } = require('node-sp-auth-config');
    const { create } = require('sp-request');
    
    (async () => {
    
      const { siteUrl, authOptions } = await new AuthConfig().getContext();
      const spr = create(authOptions);
    
      const digest = await spr.requestDigest(`${siteUrl}`);
      const res = await spr.post(`${siteUrl}/_api/web/lists/getByTitle('MyList')/items(1)`, {
        headers: {
          'X-RequestDigest': digest,
          'X-HTTP-Method': 'DELETE',
          'IF-MATCH': '*'
        }
      });
    
      console.log(res.statusCode, res.statusMessage);
    
    })().catch(console.warn);
    Obe Lahnkara
    @Oberothton_twitter
    spr.requestDigest(site).then(digest => {
    console.log(url);
    const headers = {
    'X-RequestDigest': digest,
    'X-HTTP-Method': 'DELETE',
    'IF-MATCH': '*'
    };
    spr.get(url).then(response => {
    let deleteUrl = ${site}/_api/web/lists/getByTitle('Holiday')/items(${response.body.d.results[0].ID});
                        spr.post(deleteUrl, { headers }).then(response => {
                            console.log(response.statusCode);
                        })
    this doesn't work for me. Strange.
    Obe Lahnkara
    @Oberothton_twitter
    doubly strange is upon execution i still receive a 200 OK response, which should mean the record is deleted, yet its not?
    Andrew Koltyakov
    @koltyakov
    Are you sure you aren’t deleting something else? ;D
    Obe Lahnkara
    @Oberothton_twitter
    i log the url after selecting the IDs and they seem to match the ids as seen in sharepoint, but maybe (i'm /very/ new to sharepoint lol)
    Obe Lahnkara
    @Oberothton_twitter
    it suddenly works now
    not sure why exactly haha
    Khanis Anthony K
    @khanisak

    hi guys, im new on sharepoint.
    im try to create sharepoint webpart with sharepoint framework.

    Can we call microsoft graph api on localhost workbench?

    Andrew Koltyakov
    @koltyakov
    Yes, you can, but got to create and configure AAD App Registration with redirect URI and some other none trivial things. So it's easier to run serve mode and debug a webpart on SharePoint page, so you can just use a default client ID.
    mctoastus
    @mctoastus
    Hi @koltyakov, a month ago i had a question. You told me to add something to the code.
    After doing that i get the following error:
    Error is: HTTPError: Response code 415 (Unsupported Media Type)
    Andrew Koltyakov
    @koltyakov
    @mctoastus what's the endpoint? The resource should obviously support the requested content type otherwise 415 is expected as the server can't resolve what to return.
    mctoastus
    @mctoastus
    If u mean what i want to access with the word endpoint, im trying to access sharepoint.
    Here is my code:
    https://i.imgur.com/snN1kyE.png
    Andrew Koltyakov
    @koltyakov
    image.png
    mctoastus
    @mctoastus
    Oh my god... hahaha
    mctoastus
    @mctoastus
    Mhm now it gives me a 400 (Bad Request) Error..
    Bruno Naibert
    @bruno-naibert
    Hello, I have a problem when trying to download a folder with images from sharepoint using sppull, what will it be?
    image.png
    Andrew Koltyakov
    @koltyakov
    Auth connected. Please make sure, that the auth strategy and creds are correct.
    Looks that the environment's strategy is not NTLM but something else.
    The simplest way to troubleshoot is https://github.com/koltyakov/node-sp-auth-troubleshoot
    Bruno Naibert
    @bruno-naibert
    I'll try that. But as I just want to get the path / URL of the images, without having to download them all, I would like to know if you have any more viable alternative? My initial plan would be to download all files in the same structure as the library and with Node.Js scan the folders and files on my computer to get only the URL / Path.
    Andrew Koltyakov
    @koltyakov
    I'd suggest PnPjs. But you have to have at least some understanding of what is SharePoint REST API.
    With REST, obviously, you can request a list/library and get metadata, filter only images, etc.
    ankitsaraswat27
    @ankitsaraswat27
    Hello, I am getting this error
    Access to XMLHttpRequest at 'https://waconafd.officeapps.live.com/apc/trans.gif?b320ab775852cec633df8395c6a55814' from origin 'https://abcd.sharepoint.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    2 replies
    bradcurtis
    @bradcurtis
    I am looking to authenticate with a smart card. I was wondering if that is possible?
    1 reply
    Clint Lechner
    @clechner77
    @koltyakov I've been meaning to say something for a while, it looks like you have react listed twice in your default app.json. I assume one should be a dev version but they are both prod. Same path...
    Andrew Koltyakov
    @koltyakov
    @clechner77 thanks! It's a bug with presets. Fixed, will publish an update shortly.
    RickEvry
    @rickevry
    Hi, anyone managed to authenticate with MFA? I get "Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access"