koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

Error 500 #30

Closed dinogit closed 7 years ago

dinogit commented 7 years ago

Hi,

I have problem when trying to get request from Sharepoint. I did git clone project, built it, serve it and added credentials. After that I get this : error

Error point to script.js:58.

Thanks in advance and thanks for creating this plugin.

koltyakov commented 7 years ago

Hi there @dinogit,

Can you try using relative URLs starting with '/'? E.g. '/_api/web' not '_api/web'.

dinogit commented 7 years ago

Hi @koltyakov

tried that first, it didn't work

image

How can I check if authentication succeeded?

koltyakov commented 7 years ago

I've just checked _api and /_api both works for me, I even forgot that this was taken into account. =)

You can check if auth works by creating authCheck.js in project's root folder with:

const AuthConfig = require('node-sp-auth-config').AuthConfig;
const spauth = require('node-sp-auth');

const authConfig = new AuthConfig({
    configPath: './config/private.json'
});

authConfig.getContext()
    .then(context => {
        return spauth.getAuth(context.siteUrl, context.authOptions);
    })
    .then(options => {
        console.log(options);
    })
    .catch(error => {
        console.log(error);
    });

and running:

node ./authCheck

If auth is ok, then there should be something like this:

image

or an error if something wrong with the creds or network or something. E.g.:

image

koltyakov commented 7 years ago

What auth type are you using, what is the version of SharePoint? I can see that it's on-premises, some auth could have been provided wrong.

dinogit commented 7 years ago

hm... got same message

sp-rest-proxy master ✗ 4d ◒ ➜ node ./authCheck
TypeError: callback is not a function
    at Object.parseType2Message (/Users/dino/Sites/sp-rest-proxy/node_modules/httpntlm/ntlm.js:116:3)
    at request.then (/Users/dino/Sites/sp-rest-proxy/node_modules/node-sp-auth/lib/src/auth/resolvers/OnpremiseUserCredentials.js:36:33)
    at tryCatcher (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/dino/Sites/sp-rest-proxy/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)

It Sharepoint 2013, authentication is handled by Forefront TMG

koltyakov commented 7 years ago

Hmm, I'm not sure that node-sp-auth (authentication module) works with TMG. What a coincidence! I was going to test it with TMG upcoming days on one of the projects and environment access to which I do not have yet.

@dinogit, could you please try On-Demand and FBA scenarios? To do it, just rename ./config/private.json to something else and run the proxy or authCheck again and chose these strategies:

image

FBA is likely won't work (it would be crazy, but please try it too). On-Demand auth should open a browser window in electron for input. On-Demand auth can't work with NTLM, but when using TMG... maybe there a tiny chance. =)

If nothing of these won't work, stay tuned!

@s-KaiNet, just wondering, have you ever had a chance to test node-sp-auth with TMG? If none of existing auth scenarios don't work probably I'll create PR, as for my task I got a lot of work with environment behind TMG.

dinogit commented 7 years ago

Hi @koltyakov

I have test it and it's not working, receiving sam error.

Thank you very much for your time tonight and looking forward to see progress with environment behind TMG.

s-KaiNet commented 7 years ago

The only option which might work is ondemand scenario.
At least it works for this configuration, so that's a big chance it will work for TMG.
@dinogit have you tried on-demand option?

koltyakov commented 7 years ago

@s-KaiNet, thanks! We will know it for sure tomorrow when I got to get my hands dirty with TMG on the project I mentioned above.

dinogit commented 7 years ago

hi @s-KaiNet , when using on-demand option, after successful login and hitting submit button, it displays "Loading..." and just stays like that. There are no errors in console.

s-KaiNet commented 7 years ago

Where does it display loading? Can you please post a screen?

dinogit commented 7 years ago

image

koltyakov commented 7 years ago

Hey guys,

I've figured out and implemented new auth strategy for SharePoint (or actually any website) behind Forefront TMG reverse proxy.

Created a PR https://github.com/s-KaiNet/node-sp-auth/pull/17 to node-sp-auth project, hope the merge process will be smooth.

koltyakov commented 7 years ago

Hey @dinogit,

Can you try newly added auth scenario for SharePoint behind TMG?

To do it you should update node-sp-auth and node-sp-auth-config by:

Deleting node_modules folder and yarn.lock or package-lock.json (to avoid possible packages collisions),

and running

npm i node-sp-auth node-sp-auth-config --save-dev

inside a project.

Or it's even better to install sp-rest-proxy 2.4.0 - it contains updated dependencies.

Then delete or rename ./config/private.json, run node ./authCheck and choose Forefront TMG authentication:

image

Auth cookie should be in the following format:

image

I was managed to run few tests with proxy and a new auth method on the environment I have. Everything worked for me. Hope the same on your end. =)

dinogit commented 7 years ago

Hi @koltyakov

It's working 🥇 Thank you very much, you are the awesome

koltyakov commented 7 years ago

It's an issue in @types/request-promise declarations, just can be ignored.

dinogit commented 7 years ago

Hi @koltyakov I have updated yarn and it's working