bartt / ghost-webdav-storage-adapter

A WebDAV storage adapter for the Ghost publishing platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

401 Unauthorized with OneDrive

mattguide opened this issue · comments

I am trying to use this adapter with OneDrive, but I am struggling with a 401 Unauthorized error. I am able to login fine with WebDav and create folders, etc. using my PC, so my settings are good. I created /ghost-assets/ and also created 2019/09 folders when I thought maybe the adapter wasn't able to create them. Nothing is getting me past it. Is this an issue specific to OneDrive/Webdav?

My config file looks like this:
"storage": {
"active": "webdav",
"webdav": {
"url": "https://d.docs.live.net/my_CID/",
"username": "xxxxx@outlook.com",
"password": "xxxxx",
"pathPrefix": "/ghost-assets/",
"storagePathPrefix": ""
}
}

Did a DEBUG=* ghost run to get the output:

webdav save - /ghost-assets/2019/09 - {"fieldname":"file","originalname":"IMG_5602 - IMG_5605.jpg","encoding":"7bit","mimetype":"image/jpeg","destination":"/tmp","filename":"a3d8d728dabd02e1578c0b6998f 267f2","path":"/tmp/a3d8d728dabd02e1578c0b6998f267f2_processed","size":3516905,"name":"IMG_5602 - IMG_5605.jpg","type":"image/jpeg","ext":".jpg"} +0ms
webdav exists - /ghost-assets/2019/09/IMG_5602---IMG_5605.jpg +1ms
webdav ensureDir_ - /ghost-assets/2019/09 - 2019,09 +11ms
webdav exists - /ghost-assets/2019 +0ms
webdav save - /ghost-assets/2019/09 - {"fieldname":"file","originalname":"IMG_5602 - IMG_5605.jpg","encoding":"7bit","mimetype":"image/jpeg","destination":"/tmp","filename":"a3d8d728dabd02e1578c0b6998f 267f2","path":"/tmp/a3d8d728dabd02e1578c0b6998f267f2","size":3516905,"name":"IMG_5602 - IMG_5605_o.jpg","type":"image/jpeg","ext":".jpg"} +1ms
webdav exists - /ghost-assets/2019/09/IMG_5602---IMG_5605_o.jpg +1ms
webdav ensureDir_ - /ghost-assets/2019/09 - 2019,09 +0ms
webdav exists - /ghost-assets/2019 +0ms
webdav exists - /ghost-assets/2019/09/IMG_5602---IMG_5605.jpg: false +86ms
webdav exists - /ghost-assets/2019/09/IMG_5602---IMG_5605_o.jpg: false +1ms
webdav exists - /ghost-assets/2019: false +3ms
webdav ensureDir_ - /ghost-assets/2019: Error: Invalid response: 401 Unauthorized +68ms
webdav save - /ghost-assets/2019/09 - {"fieldname":"file","originalname":"IMG_5602 - IMG_5605.jpg","encoding":"7bit","mimetype":"image/jpeg","destination":"/tmp","filename":"a3d8d728dabd02e1578c0b6998f 267f2","path":"/tmp/a3d8d728dabd02e1578c0b6998f267f2_processed","size":3516905,"name":"IMG_5602 - IMG_5605.jpg","type":"image/jpeg","ext":".jpg"}: Error: Invalid response: 401 Unauthorized +0ms
express:router : /ghost/api/canary/admin/images/upload/ +400ms
express:router : /ghost/api/canary/admin/images/upload/ +1ms
ghost:error-handler Error: Invalid response: 401 Unauthorized
ghost:error-handler at handleResponseCode (/var/www/ghost/versions/2.31.0/node_modules/webdav/dist/response.js:7:15)
ghost:error-handler at tryCatcher (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/util.js:16:23)
ghost:error-handler at Promise._settlePromiseFromHandler (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:517:31)
ghost:error-handler at Promise._settlePromise (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:574:18)
ghost:error-handler at Promise._settlePromise0 (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:619:10)
ghost:error-handler at Promise._settlePromises (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:699:18)
ghost:error-handler at _drainQueueStep (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:138:12)
ghost:error-handler at _drainQueue (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:131:9)
ghost:error-handler at Async._drainQueues (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:147:5)
ghost:error-handler at Immediate.Async.drainQueues [as _onImmediate] (/var/www/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:17:14)
ghost:error-handler at runCallback (timers.js:705:18)
ghost:error-handler at tryOnImmediate (timers.js:676:5)
ghost:error-handler at processImmediate (timers.js:658:5)
ghost:error-handler at process.topLevelDomainCallback (domain.js:126:23) +0ms
express:router : /ghost/api/canary/admin/images/upload/ +1ms
compression no compression: size below threshold +4s
[2019-09-20 03:46:01] ERROR "POST /ghost/api/canary/admin/images/upload/" 500 407ms

Invalid response: 401 Unauthorized

commented

Are the username and password correct? If yes, have you tried adding the port name to the URL (eg. https://d.docs.live.net:1234/my_CID/)?

The latter was one error preventing me from connecting: without the port, it would either try to make requests using HTTP GET or something (which would be invalid) or reject davs:// as a valid prefix if I tried using that. https://hostname:port was the format that worked for me. This may be happening in your case, because it's finding that the folders exist and only throwing an error when you try to create a new file.

Thanks for the reply. I am using port 443 in WinSCP to test the connection and it work; it does not work through this storage adapter.

After digging into OneDrive Personal with web applications, it sounds like I would need to use Microsoft Graph (https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/?view=odsp-graph-online) and OAuth 2.0. I do see the base NodeJS has support for OAuth, but I am unable to find on the Azure portal how to create the API tokens I need for my personal OneDrive.

I don't know if OAuth is required, since access still works through Windows and WinSCP and other programs, but it sounds like the way it should be handled for something like this use case.

commented

Hmm...in that case you might have to customize this adapter to work with OAuth.

I haven't used OneDrive, so I can't help there, but perhaps you could try testing with some other WebDAV server? That way you'll know for sure that the issue is with OneDrive and not with some other config settings. It seems strange that writing files should fail when checking for their existence happens successfully.

@mattguide, ghost-webdav-storage-adapter supports Basic Auth only. Make sure you can use Basic Auth with OneDrive. Please re-open when there is an issue with Basic Auth support in ghost-webdav-storage-adapter.

@mattguide, ghost-webdav-storage-adapter supports Basic Auth only. Make sure you can use Basic Auth with OneDrive. Please re-open when there is an issue with Basic Auth support in ghost-webdav-storage-adapter.

Agree on close. After investigating, it is not an issue with the plugin--more FYI for anyone looking to implement with OneDrive. Thank you.