OneDrive / onedrive-sdk-csharp

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

AuthenticationCancelled thrown #158

Closed ViktorBergman closed 8 years ago

ViktorBergman commented 8 years ago

Using the latest 2.0 package I cannot sign in into OneDrive for Consumer:

string[] scopes = new string[] { "onedrive.appfolder", "offline_access", "wl.signin","onedrive.readonly" };
var msaAuthProvider = new MsaAuthenticationProvider("XXXX", "https://login.live.com/oauth20_desktop.srf", scopes);
await msaAuthProvider.AuthenticateUserAsync();
return new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider);

AuthenticationCancelled is immediately thrown although no user interface is even presented that supposedly would cancel the authentication?

(edited for readability)

mhomde commented 8 years ago

Yeah, I'm having the same problem, there's more in this issue

https://github.com/OneDrive/onedrive-sdk-dotnet-msa-auth-adapter/issues/3#issuecomment-242955155

davideloper commented 8 years ago

The same problem on my side (Microsoft.Graph.ServiceException, Code: authenticationCancelled).

edandersen commented 8 years ago

Same problem here. Completely blocking updating to the 2.0.0 package.

davideloper commented 8 years ago

So, anyone knows the solution (except downgrading SDK version)? Does Microsoft know for this problem?

cdmayer commented 8 years ago

I'm able to reproduce locally. Investigating...

cdmayer commented 8 years ago

I suspect there is a packaging issue, but am having trouble verifying. Can someone that is hitting this issue check this: what version of Microsoft.IdentityModel.Clients.ActiveDirectory do you have installed? If >3.0, can you try downgrading to 2.21.xx and try again? Please let me know the results.

cdmayer commented 8 years ago

Also helpful would be if someone hitting this issue were to post their complete code (at least the relevant parts). I am unable to reproduce locally, even after setting up a fresh environment.

mhomde commented 8 years ago

Have you tried compiling a windows store app in release mode with .net native and optimizations enabled? (anniversary update) I found it worked most times when I run the same code in debug mode

cdmayer commented 8 years ago

Targeting .NET Native does cause some issues, but this is no surprise since there is no serialization configuration, as is required (https://msdn.microsoft.com/en-us/library/dn600638(v=vs.110).aspx).

@ViktorBergman @davideloper @edandersen Are you building in Debug or Release mode?

mhomde commented 8 years ago

Yeah, unfortunately not much choice if you want to publish through the store :)

davideloper commented 8 years ago

Tried to build in Release mode - the error still exists. So, I' m developing UWP app, VS 2015, I 've installed Microsoft.IdentityModel.Clients.ActiveDirectory and tried with both versions (3.xx, 2.13.xx), with no success. Basicly, I think, I do not need this package. The code: var msaAuthenticationProvider = new MsaAuthenticationProvider(CLIENT_ID, "https://login.live.com/oauth20_desktop.srf", new[] { "onedrive.readonly", "wl.signin", "wl.offline_access" }); await msaAuthenticationProvider.AuthenticateUserAsync();

dpaulino commented 8 years ago
Task authTask = null; 

if (oneDriveClient == null)
{
  var msaAuthProvider = new MsaAuthenticationProvider(clientId, returnUrl, scopes);
  oneDriveClient = new OneDriveClient(baseUrl, msaAuthProvider);
  authTask = msaAuthProvider.AuthenticateUserAsync();
  AuthProvider = msaAuthProvider;
}
try
{
  await authTask;
}
catch (ServiceException e)
{
  Debug.WriteLine(e);
}

I am having the exact same exception. Above is my code. This code was taken almost exactly from the official UWP sample. No changes in user interface on the app during debugging either.

Nuget packages installed: Microsoft.OnedriveSDK v2.0.0, and Microsoft.OneDriveSdk.Authentication v1.0.1

davideloper commented 8 years ago

Any news here @cdmayer ? Thanks in advance.

cdmayer commented 8 years ago

Investigating with high priority. To be clear, I am investigating issues that arise during authentication when .NET Native is enabled (this usually happens by default for Release builds). Will report back when I have news.

davideloper commented 8 years ago

Is 'm not sure if this is really the problem. In app properties I have Active (debug) Configuration selected, and checkbox Compile with .NET Native tool chain unchecked. Should we try with some other settings or build properties?

cdmayer commented 8 years ago

You can see the latest in this branch: https://github.com/OneDrive/onedrive-sdk-dotnet-msa-auth-adapter/tree/async-updates

It would appear that if you build the branch that I linked (above) and reference the binaries directly from your project, everything should work. I am running into issues where packing it into a Nuget package still does not work. For now, please try cloning the above branch, building the binaries, and referencing them directly. Meanwhile, we are still working on getting this fully resolved internally.

mhomde commented 8 years ago

The error doesn't happen to be related to this? http://stackoverflow.com/questions/38321069/json-serialization-error-when-updating-user-in-azure-ad-via-graph

Marccnl commented 8 years ago

I'm developing an UWP application and am experiencing the same problem but found that this only occurs when i run the app on my laptop. When i deploy it to my phone the login popup does show and it works as expected, either in debug or in release mode.

ViktorBergman commented 8 years ago

Probably OT but I'm finding it hard to be convinced as to why the breaking changes in 2.0 is worth upgrading. So, can anyone give us the elevator pitch for upgrading to 2.0?

cdmayer commented 8 years ago

Sorry for the delay all, but I am still working on the solution here.

@ViktorBergman, V2 was refactored to work with Graph.Core, which centralized things like AuthenticationProvider and other components that any SDK/library accessing Graph (really, OData API) would need. V1 was almost an exact duplicate of the Graph.Core components (and in reality the latter was based on the former), and we didn't want to maintain two versions of the same code, so V2 was born.

For now, there is no big reason to move to V2. You can keep using V1 as-is and it will be fine. However, moving forward all new features and non-critical bugfixes will only target V2, so at some point it will be natural to move over to V2. Once these authentication issues are resolved, there should be little reason not to move over anyway because the code changes are minimal. If you disagree strongly, I would love to hear why!

cdmayer commented 8 years ago

@mhomde I don't believe that is related. Do you have reason to believe it is?

cdmayer commented 8 years ago

I have a candidate fix in this branch: https://github.com/OneDrive/onedrive-sdk-dotnet-msa-auth-adapter/tree/async-updates

Please try cloning this branch, building the binaries, then referencing them directly from your project (in place of the Nuget package). It solves the authenticationCancelled issue on .NET Native for me, so I would love some verification.

cdmayer commented 8 years ago

New binaries are signed and uploaded to NuGet. Please try installing 1.0.2 of the Auth Adapter and let me know if it fixes your issue.

dpaulino commented 8 years ago

@cdmayer thanks. going to try this soon and report back

Marccnl commented 8 years ago

works for me, thanks!

mhomde commented 8 years ago

Hmm, I still seem to have the same problem when compiling for .Net Native on desktop

davideloper commented 8 years ago

Works for me too, thanks. I had to remove OneDrive sdk and OneDrive.Authentication and add them back to project.

cdmayer commented 8 years ago

@mhomde can you try uninstalling the old package installing the new one? Make sure it's 1.0.2.

If you are still having issues, please try adding this code where you invoke AuthenticateAsync:

            try
            {
                result = await authUi.AuthenticateAsync(requestUri, callbackUri);
            }
            catch (ServiceException ex)
            {
                var message = ex.Error.Code + ": " + ex.Error.Message;
                throw;
            }

Then insert a break point at the throw line and tell me the value of message.

mhomde commented 8 years ago

Sorry for delay, wanted to publish through the store to make sure, and it seems to work https://www.microsoft.com/store/apps/9nblggh51jvk

Good job fixing the bug, thanks! Lots of cool possibilities with the OneDrive SDK, only thing I'm missing is real-time notifications