koltyakov / sp-rest-proxy

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

Unauthorized errror. #46

Closed hmendezm closed 6 years ago

hmendezm commented 6 years ago

HI guys

first at all, thanks very much for doing this project. it is very helpful for sharepoint developing. I did all steps to setup the sp-res-proxy and I get the lessage below. I am not sure what is the problems. I check my credentials and they are ok.

{ "readyState": 4, "responseText": "401 - undefined", "status": 401, "statusText": "Unauthorized" }

I have the followin

const RestProxy = require('sp-rest-proxy');
const path = require('path');
const settings = {
    // Location for SharePoint instance mapping and credentials
    configPath: path.join(__dirname, '/config/private.conf.json'),
    // Local server port
    port: 8081,
    // Root folder for static content
    staticRoot: path.join(__dirname, '/static')
};

const restProxy = new RestProxy(settings);
restProxy.serve();

private.conf.json

{
  "siteUrl": "https://site.ttttt.yyy.uuu",
  "strategy": "OnpremiseUserCredentials",
  "username": "my username",
  "domain": "domain of the username",
  "password": "c73fae4a9117c442c6a63b9bbdb7f3755aa8e3f22326c4160a257fb2bbec31ce253481008028a5141712266a25fb354c3ZMmTNBCBjYiyARRvjfm2JDaDiMidqvRHND1FlUTwSU="
}

package.json

 "scripts": {
...
 "server2": "node ./server.js",
...
}

The dev Machine is the same domain of the development Sharepoint 2013 server. However Dev Machine and Development Sharepoint server are two separated machines.

I really need to put this to work. any help is really appreciated.

Best, Hmendezm

koltyakov commented 6 years ago

Hi and thank you for the interest using the lib!

  1. Please make sure that the creds and site URL are correct, you can also try username in the following format "username@domain.com" and omit separate domain parameter.

  2. The password hash is valid only on the machine it was generated, if private.json was copied on another machine password should be updated.

  3. There is a chance that domain uses NTLMv2/Kerberos which are not supported.

  4. Can be different auth strategy.

hmendezm commented 6 years ago

Thanks for a quick reply. I tried with the username@domain.com and it is not working either. I have generated the hash in the same machine. I had not copied the file from somewhere else. Let me see If I can use other auth strategy. best, Hmendezm

koltyakov commented 6 years ago

Can you check which NTML compatibility level is configured on SP server? https://technet.microsoft.com/en-us/library/cc960646.aspx?f=255&MSPPError=-2147217396

hmendezm commented 6 years ago

I checked the NTML compatibility and I found out the following

"Send NTLNv2 response only. Refuse LM & NTML." is there a workaround for this?

Best regards Hmendezm

koltyakov commented 6 years ago

I'm afraid not. Only by introducing another auth strategy to SP server, i.e. AddIn's, FBA or ADFS. As it's a dev environment, maybe it's not an issue, or downgrading to NTLM v. 1 (not sure if changing registery key is an option).

hmendezm commented 6 years ago

ok. I will try with Addin to see how goes. Angular 5 and Addins? do you have an example of using sp-rest-proxy with addins?

thanks very much for your help. best hmendezm

koltyakov commented 6 years ago

I've never experimented with NTLMv2 by myself, by guys involved in the creation of auth lib are sure that it's technically not possible. If it's possible to grant me a test access to the env with NTMLv2 and the issue you are experiencing I could take a look, maybe fresh look will help. Or at least I also will be sure that it's technically not possible and why.

If Add-Ins are configured, it should be "straightforward" (UPD: Actually the configuration is not the simplest one), you generate clientId/realm/rsaPrivateKeyPath/etc, register AddIn and grant it corresponding level access, then authenticates using add-in creds. Read more about. I worked with AddIns only with SPO.

koltyakov commented 6 years ago

Angular 5 and Addins?

Add-Ins in this schema are used only for proxy and assets deployment. And you're ended up with SPO which can be deployed to SP into assets doc lib and enabled on the page, i.e. using CEWP.

hmendezm commented 6 years ago

I was trying to setup an angular project that the developer can debug and test without have to deploy to the SharePoint environment. Similar to Sharepoint framework. We are using Sp 2013 for now so we do not have Sharepoint framework for now. So the idea is the developer can run the application locally and get data using restapi and in the same time be able to breakpoint the code in visual studio code.

anyway, thanks for the help again best, hmendezm

koltyakov commented 6 years ago

can debug and test without have to deploy to the SharePoint environment

Sure thing, that's why sp-rest-proxy is created for. =)

koltyakov commented 6 years ago

Closing this one. Feel free to reopen if questions remain.