OneDrive / onedrive-sdk-python

OneDrive SDK for Python! https://dev.onedrive.com
MIT License
1.08k stars 189 forks source link

Authentication #205

Closed DougMortonGit closed 1 year ago

DougMortonGit commented 1 year ago

I'm really hoping your SDK can help me with what I need to do, which is to list all files in a OneDrive folder with hrefs which will allow downloads. I'm thinking I could use links like: Download This link works. What I want to do is present a page listing all the files and "insert" the resid once I get it through your program.

Basically, I copied your code samples and went thru the app registration and when the code execution gets to this line: _client.auth_provider.authenticate(code, redirect_uri, clientsecret) I don't get an error (I used to get invalid_client and invalid_grant) but I got past that and don't see anything to indicate the Authentication failed or succeeded.

Once that line is executed, I try to run: _rootfolder = client.item(drive='me', id='root').children.get() and I get this error: "unauthenticated - Authentication failed"

I'm new to Microsoft App Registration and Authentication and may be misunderstanding some very simple concepts.

First, are the values of 'me' and 'root' correct? I've tried with the GUID of the main folder and it still errors.

Another thing I notice is that when I run the site on localhost, I don't get a timeout on the authentication, which I do when I try to authenticate on the live site. This makes me suspect that the Authentication is not working but I can't see where to get any kind of status.

I've set my redirect_uri to 'http://localhost:8080/'. I wonder if this is correct since when I do the code paste operation it says localhost refuses to connect. http://localhost:8080/?code=M.C105_SN1.2.a94a758a-2e19-0ba9-e2e5-1c5fce047015

My scopes are _['User.Read', 'offlineaccess', 'Files.Read.All', 'onedrive.readwrite', 'onedrive.readonly', 'onedrive.appfolder'] which may be too many but nothing's complaining at this point.

At any rate, I've spent at least two full days trying to get this to work. I'm sure it's some dumb thing I'm missing but I can't find it. I will deeply appreciate any help or guidance. Frankly, I'd be open to some compensating you for your time. I need to get this working.

Thanks, Doug

DougMortonGit commented 1 year ago

I finally figured it out after several painful days. I'm always baffled by Microsoft's obtuse approach to certain things. After a long while and multiple blind experiments, I realized that I had to register the app under my business account and expose the API properly. However, I tried so many things that I'm not 100% certain that was it.

What made the final difference was using the GetAuthCodeServer version of your code sample and getting the redirect_uri and scopes just right: redirect_uri = 'http://localhost:8080/' scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

I'm still not super-comfortable with this and exactly how I wound up getting it work - which is the problem with a multi-day mysterious issue. At any rate, I'm now transversing my OneDrive file system like crazy.

Thanks for your good work here.

D