OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
295 stars 145 forks source link

Authentication Problem / Failed #244

Open usane opened 6 years ago

usane commented 6 years ago

Hi,

I am trying to develop console application which automatically uploads files to share our customers. However, I run into following two issues.

One is that OneDrive API requires browser user interaction for authentication. Although I passed to application id and password, getting from Application Registration Portal, when authentication request.

Following is request uri I passed. (https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&client_secret={client_secret}&scope={scope}&response_type=token&redirect_uri={redirect_uri})

I don't know why it requires additional log-in process, and I would like to know how I can avoid this process. Sure, I've googled by this issue and found some post there are no fully automatic authentication but these posts are out-dated... Is there any up-to-date state? Still manual procedure required? (If so, why???)

Another is the authentication itself. I just copied and pasted the example code described at this project page, It throws Microsoft.Graph.ServiceException

Following is the source I tried. (I gave up automatic auth)

var authProvider = new MsaAuthenticationProvider(id, redirection, new string[] { "Files.ReadWrite.All"}); await authProvider.AuthenticateUserAsync(); client = new OneDriveClient(authProvider); var rootItem = await client.Drive.Request().GetAsync(); // Excpetion arose!

I checked authProvider.IsAuthenticated is true and CurrentAccountSession attribute has AcessToken. However I cann't make any request.

Following is full message of the exception: Microsoft.Graph.ServiceException이(가) 발생했습니다. HResult=0x80131500 메시지=Code: unauthenticated Throw site: 4f37.717b Message: Authentication failed

StackTrace: at Microsoft.Graph.HttpProvider.d19.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.BaseRequest.d36.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.BaseRequest.d32`1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.DriveRequest.d6.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at KMLizer.Util.CloudDrive.OneDrive.d__6.MoveNext() in ~OneDrive.cs:line 44

I cannot guess and find the problem...

Can anyone give me an advice?

Thanks in advance.