Search code examples
c#oauth-2.0onedrive

OneDrive SDK showing empty White window for OAuth


I am coding against the Microsoft.OneDrive.SDK and I have also included the Microsoft.OneDrive.SDK.Authentication. The issue I am having is that I have a console application which opens just a white window where it clearly is prompting me to log in.

Code:

using System;
using System.Threading.Tasks;
using Microsoft.OneDrive.Sdk;
using Microsoft.OneDrive.Sdk.Authentication;

namespace SecondTake_OneDrive_SDK
{
class Program
{
    [STAThread]
    static void Main()
    {
        RunTask().Wait();
    }

    static async Task RunTask(OneDriveClient oneDriveClient = null)
    {
        Task authTask = null;
        if (oneDriveClient == null)
        {
            var msaAuthenticationProvider = new MsaAuthenticationProvider("CLIENT_ID",null, "https://login.live.com/oauth20_desktop.srf", new[] { "onedrive.readonly", "wl.signin" }, null, new CredentialVault("CLIENT_ID));
            authTask =  msaAuthenticationProvider.AuthenticateUserAsync();
        }
        try
        {
            await authTask;
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }
}

Solution

  • Digging through the source code, it looks like the default ui for getting auth details is a Windows Form:

    This is a bit new to me, but another post on the subject of running Windows Forms from a console app seems to call Application.EnableVisualStyles(); as the first line in Main().

    Perhaps this will allow your console app to draw things properly.