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

How to access SharePoint Online from gulp-spsave #34

Closed
ahamedfazil opened this issue Jun 29, 2018 · 17 comments
Closed

How to access SharePoint Online from gulp-spsave #34

ahamedfazil opened this issue Jun 29, 2018 · 17 comments

Comments

@ahamedfazil
Copy link

Hi,
I am using gulp-spsave to deploy my js bundle into SharePoint. It works find in on-premise. But when I tried to upload my bundle into SharePoint online it gives me following error.

Error: getaddrinfo ENOTFOUND login.microsoftonline.com login.microsoftonline.com:443

Does gulp-spsave supports SharePoint online?

@s-KaiNet
Copy link
Owner

s-KaiNet commented Jun 29, 2018

Hi, do you work behind firewall or proxy or something like that?

@ahamedfazil
Copy link
Author

Yes we use proxy for npm, git. Do I need to setup proxy for gulp? If yes could guide or give me some reference

FYI, If I use

Connect-PnPOnline -URL

PowerShell command to connect to my SharePoint online site then it works fine.

@s-KaiNet
Copy link
Owner

Please read this comment, I believe this is something you are looking for.

@ahamedfazil
Copy link
Author

Thank you Sergei 👍 but my issue is not fully resolved.
Now i get the following error, after adding proxy in my gulp file.

spsave: Error: Unable to resolve namespace authentiation type. Type received: Unknown
at request.post.then.userRealm (C:\myproj\node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCredentials.js:100:19)

Below you can find the script which I use in my gulp file

`const gulp = require("gulp");
const spsave = require("gulp-spsave");
const argv = require("minimist")(process.argv.slice(2));
const { credentials } = require("./webpack/webpack.env");

const environment = argv.env || "test";
process.env.https_proxy = "http://####:####";
process.env.http_proxy = "http://####:####";
const coreOptions = {
siteUrl: "https://####.sharepoint.com/sites/####/",
notification: true,
folder: "SiteAssets",
flatten: true
};
const creds = credentials[environment];
gulp.task("default", () => {
gulp.src("webpack/dist/**").pipe(spsave(coreOptions, creds));
});`

And my gulp version is

"gulp": "^3.9.1",
"gulp-spsave": "^3.1.0",

@s-KaiNet
Copy link
Owner

Do you use any third party authentication providers?

@ahamedfazil
Copy link
Author

No, there's no third-party authentication.

@s-KaiNet
Copy link
Owner

If you put console.log(userRealm); at line #90 in file at node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCredentials.js, what will it print?

@ahamedfazil
Copy link
Author

ah it helped me 👍 Well, I just found its referring to wrong login name. Now i gave the right user name.

Output from the Console after providing right username

{ State: 4,
UserState: 1,
Login: '###@abcd.onmicrosoft.com',
NameSpaceType: 'Managed',
DomainName: 'abcd.onmicrosoft.com',
FederationBrandName: '#####',
CloudInstanceName: 'microsoftonline.com' }

Now I end up with another error, :(

spsave: RequestError: Error: tunneling socket could not be established, statusCode=407
at new RequestError (C:\myproj\node_modules\request-promise-core\lib\errors.js:14:15)

@s-KaiNet
Copy link
Owner

Try to set proxy via command line like below:

>npm config set proxy http://proxyhost:proxyport
>npm config set https-proxy http://proxyhost:proxyport

@ahamedfazil
Copy link
Author

Its still the same, I got the same error.
Here is the complete error description,

spsave: RequestError: Error: tunneling socket could not be established, statusCode=407
at new RequestError (C:\myproj\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\myproj\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\myproj\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\myproj\node_modules\request\request.js:186:22)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at Request.onRequestError (C:\myproj\node_modules\request\request.js:878:8)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at ClientRequest.onConnect (C:\myproj\node_modules\tunnel-agent\index.js:168:23)
at Object.onceWrapper (events.js:319:30)
at emitThree (events.js:136:13)
at ClientRequest.emit (events.js:217:7)
at Socket.socketOnData (_http_client.js:472:11)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:594:20)
From previous event:
at OnlineUserCredentials.postToken (C:\myproj\node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCredentials.js:164:24)
at getSecurityToken.then.xmlResponse (C:\myproj\node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCredentials.js:48:25)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
Unhandled rejection RequestError in plugin 'gulp-spsave'
Message:
Error: tunneling socket could not be established, statusCode=407

@ahamedfazil
Copy link
Author

Hi Sergi,

The issue has been resolved. I just provided my credentials in the proxy
like below.

http://USERID:PASSWORD@proxyhost:proxyport

Thank you for your support and help. I really appreciate it 💯

One more thing, I face the same below issue when I try to access SharePoint Online site using sp-rest-proxy for local development. Please let me know if you have any solution for this

Error: getaddrinfo ENOTFOUND login.microsoftonline.com login.microsoftonline.com:443

@s-KaiNet
Copy link
Owner

It theory it should work. @koltyakov do you know anything about it?

@koltyakov
Copy link

Hey @ahamedfazil,

The same approach definitely works with any Node.js library which lives behind a corporate proxy and should talk to a network resource. So yes, sp-rest-proxy should be able reaching SPO from a local area network which is configured using network proxy if a Node.js process is configured to use the last. Just be sure that http_proxy and http_proxys environment variables are there before sp-rest-proxy server starts.

@ahamedfazil
Copy link
Author

Hi @koltyakov

I don't see the error while connecting to my SPO through sp-rest-proxy

image

But when i access, I get the error. For example i am accessing through the browser i get the following error

image

Thank you in advance.

@koltyakov
Copy link

I do not think you have added:

process.env.https_proxy = "http://####:####";
process.env.http_proxy = "http://####:####";
// or whatever setting you ended up your environment works

configuration at the beginning of the script which starts the proxy. Of course, Node.js process knowing nothing about network environment won't be using your network settings.

@koltyakov
Copy link

koltyakov commented Jun 30, 2018

Also, I would recommend adding sp-rest-proxy as a dev dependency to your frontend solution but not cloning the repository. Then:

image

@ahamedfazil
Copy link
Author

After adding corporate proxy in SP-rest-proxy/src/server.ts

image

it worked like a charm 👍 Now I can access data from SPO for my local dev as well.
@s-KaiNet & @koltyakov thank you so much guys for your help 💯

I am closing this issue, since it resolved my problem 👍

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

3 participants