C# 缺少LiveSDK 5.6 LiveAuthClient.LoginAsync方法

C# 缺少LiveSDK 5.6 LiveAuthClient.LoginAsync方法,c#,wpf,desktop-application,onenote,live-sdk,C#,Wpf,Desktop Application,Onenote,Live Sdk,我正在尝试创建用于检索OneNote页面的集成测试。当尝试使用LiveSDK 5.6 LiveAuthClient时,我的编译器甚至没有看到任何名为LiveAuthClient.LoginAsync(strin[])的方法,该方法在这里的多个答案(例如)中提到,以及:| 有什么想法吗 我肯定我错过了一些明显的东西 似乎确实存在一个名为GetLoginUrl()的方法 我引用了错误的LiveSDK吗 我安装了LiveSDK 5.6 NuGet软件包,该项目是一个.NET 4.5类库项目我认为只有W

我正在尝试创建用于检索OneNote页面的集成测试。当尝试使用LiveSDK 5.6 LiveAuthClient时,我的编译器甚至没有看到任何名为LiveAuthClient.LoginAsync(strin[])的方法,该方法在这里的多个答案(例如)中提到,以及:|

有什么想法吗

我肯定我错过了一些明显的东西

似乎确实存在一个名为GetLoginUrl()的方法

我引用了错误的LiveSDK吗


我安装了LiveSDK 5.6 NuGet软件包,该项目是一个.NET 4.5类库项目

我认为只有Windows应用商店应用程序才支持使用LiveSDK的桌面应用程序的登录工作流。您可能需要下拉到REST API以进行自动测试。

我认为带有Live SDK的桌面应用程序不支持登录工作流,而只支持Windows应用商店应用程序。您可能需要下拉到REST API进行自动测试。

我设法让它工作,但不得不使用GetLoginUrl(),而不是使用Selenium使用测试帐户登录到Windows live并批准权限请求,然后使用查询字符串(..?code=xx.xxx)中的代码重定向权限请求我使用它调用AuthClient.ExchangeAuthCodeAsync,并获取包含AccessToken+RefreshToken的会话,对于所有其他测试,我可以使用该刷新标记:-),因为它的有效期为一年

    [Test]
    public async void TryAuthoriseWithMsLiveLibrary()
    {
        var authClient = new LiveAuthClient(OneNoteApiConfig.ClientID);

        var result = await authClient.InitializeAsync(OneNoteApiConfig.Scopes);

        var getLoginUrl = authClient.GetLoginUrl(OneNoteApiConfig.Scopes);
        Console.WriteLine("\r\nGetLoginUrl = " + getLoginUrl);

        // New selenium Driver
        _driver = new FirefoxDriver();

        //Set wait to 2 seconds by defualt
        _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));

        // Go to the url provided by auth client
        _driver.Navigate().GoToUrl(getLoginUrl);

        // Try find the accept button, if automatically directed to the "Grant Permission page", otherwise try find the Login/Passwd and login first
        try
        {
            _driver.FindElementById("idBtn_Accept");
        }
        catch (NoSuchElementException)
        {
            var un = _driver.FindElementByName("login"); // Login TextBox
            var pw = _driver.FindElementByName("passwd"); // Password TextBox
            var signIn = _driver.FindElementByName("SI"); // Sign-In Button

            un.SendKeys(OneNoteTestConfig.WindowsLiveUsername);
            pw.SendKeys(OneNoteTestConfig.WindowsLivePassword);
            signIn.Submit();
        }
        // Find a click the idBtn_Accept, if not found straight away, will implictly wait 2 seconds as set baove
        var button = _driver.FindElementById("idBtn_Accept");
        button.Click();

        // Try wait until the client is successfully redirected to the url with the code
        try
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
            wait.Until(d => d.Url.StartsWith("https://login.live.com/oauth20_desktop.srf"));
            //example https://login.live.com/oauth20_desktop.srf?code=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&lc=1033
        }
        catch (WebDriverTimeoutException)
        {
            Console.WriteLine(_driver.Url);
            throw;
        }

        Console.WriteLine("\r\nUrl = " + _driver.Url);

        // Retrieve code from query string (?code=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&...)
        var code = MsLiveAuthHelper.GetSessionCodeFromRedirectedUrl(_driver.Url);

        code.Should().NotBeNull();
        Console.WriteLine("\r\ncode = " + code);

        // Try get open a session using retrieved code.
        // From my uynderstanding you can only do this once with the code, as it expired after
        // and need to use the refresh token from this point, or re-request a code using above procedure
        var session = await authClient.ExchangeAuthCodeAsync(code);

        session.Should().NotBeNull();
        session.AccessToken.Should().NotBeNullOrWhiteSpace();

        Console.WriteLine("\r\nLiveConnectSession.AccessToken = " + session.AccessToken);
        Console.WriteLine("\r\nLiveConnectSession.AuthenticationToken = " + session.AuthenticationToken);
        Console.WriteLine("\r\nLiveConnectSession.Expires = " + session.Expires);
        Console.WriteLine("\r\nLiveConnectSession.RefreshToken = " + session.RefreshToken);
    }
对于我的其他测试,
resh.refreshttoken
,并有一个
testrefreshttokenhandler:IRefreshTokenHandler
,我将其保存在:

public class TestRefreshTokenHandler : IRefreshTokenHandler
{
    public Task SaveRefreshTokenAsync(RefreshTokenInfo tokenInfo)
    {
        return Task.Factory.StartNew(() =>
        {
            Console.WriteLine("------------------------");

            Console.WriteLine("\r\nUserID = " + tokenInfo.UserId);
            Console.WriteLine("\r\nRefresh Token = " + tokenInfo.RefreshToken);

            Console.WriteLine("\r\n------------------------");
        });
    }

    public Task<RefreshTokenInfo> RetrieveRefreshTokenAsync()
    {
        Console.WriteLine("RetrieveRefreshTokenAsync()");
        return Task.FromResult(new RefreshTokenInfo(OneNoteTestConfig.OneNoteRefreshToken));
    }
}

希望这对别人有帮助

我设法让它工作,但不得不使用GetLoginUrl(),而不是使用Selenium使用测试帐户登录Windows live并批准权限请求,然后使用查询字符串(..?code=xx.xxx)中的代码重定向权限请求,我使用该字符串调用AuthClient.ExchangeAuthCodeAsync,获取一个包含AccessToken+RefreshToken的会话,对于所有其他测试,我可以使用该刷新标记:-),因为它的有效期为一年

    [Test]
    public async void TryAuthoriseWithMsLiveLibrary()
    {
        var authClient = new LiveAuthClient(OneNoteApiConfig.ClientID);

        var result = await authClient.InitializeAsync(OneNoteApiConfig.Scopes);

        var getLoginUrl = authClient.GetLoginUrl(OneNoteApiConfig.Scopes);
        Console.WriteLine("\r\nGetLoginUrl = " + getLoginUrl);

        // New selenium Driver
        _driver = new FirefoxDriver();

        //Set wait to 2 seconds by defualt
        _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));

        // Go to the url provided by auth client
        _driver.Navigate().GoToUrl(getLoginUrl);

        // Try find the accept button, if automatically directed to the "Grant Permission page", otherwise try find the Login/Passwd and login first
        try
        {
            _driver.FindElementById("idBtn_Accept");
        }
        catch (NoSuchElementException)
        {
            var un = _driver.FindElementByName("login"); // Login TextBox
            var pw = _driver.FindElementByName("passwd"); // Password TextBox
            var signIn = _driver.FindElementByName("SI"); // Sign-In Button

            un.SendKeys(OneNoteTestConfig.WindowsLiveUsername);
            pw.SendKeys(OneNoteTestConfig.WindowsLivePassword);
            signIn.Submit();
        }
        // Find a click the idBtn_Accept, if not found straight away, will implictly wait 2 seconds as set baove
        var button = _driver.FindElementById("idBtn_Accept");
        button.Click();

        // Try wait until the client is successfully redirected to the url with the code
        try
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
            wait.Until(d => d.Url.StartsWith("https://login.live.com/oauth20_desktop.srf"));
            //example https://login.live.com/oauth20_desktop.srf?code=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&lc=1033
        }
        catch (WebDriverTimeoutException)
        {
            Console.WriteLine(_driver.Url);
            throw;
        }

        Console.WriteLine("\r\nUrl = " + _driver.Url);

        // Retrieve code from query string (?code=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&...)
        var code = MsLiveAuthHelper.GetSessionCodeFromRedirectedUrl(_driver.Url);

        code.Should().NotBeNull();
        Console.WriteLine("\r\ncode = " + code);

        // Try get open a session using retrieved code.
        // From my uynderstanding you can only do this once with the code, as it expired after
        // and need to use the refresh token from this point, or re-request a code using above procedure
        var session = await authClient.ExchangeAuthCodeAsync(code);

        session.Should().NotBeNull();
        session.AccessToken.Should().NotBeNullOrWhiteSpace();

        Console.WriteLine("\r\nLiveConnectSession.AccessToken = " + session.AccessToken);
        Console.WriteLine("\r\nLiveConnectSession.AuthenticationToken = " + session.AuthenticationToken);
        Console.WriteLine("\r\nLiveConnectSession.Expires = " + session.Expires);
        Console.WriteLine("\r\nLiveConnectSession.RefreshToken = " + session.RefreshToken);
    }
对于我的其他测试,
resh.refreshttoken
,并有一个
testrefreshttokenhandler:IRefreshTokenHandler
,我将其保存在:

public class TestRefreshTokenHandler : IRefreshTokenHandler
{
    public Task SaveRefreshTokenAsync(RefreshTokenInfo tokenInfo)
    {
        return Task.Factory.StartNew(() =>
        {
            Console.WriteLine("------------------------");

            Console.WriteLine("\r\nUserID = " + tokenInfo.UserId);
            Console.WriteLine("\r\nRefresh Token = " + tokenInfo.RefreshToken);

            Console.WriteLine("\r\n------------------------");
        });
    }

    public Task<RefreshTokenInfo> RetrieveRefreshTokenAsync()
    {
        Console.WriteLine("RetrieveRefreshTokenAsync()");
        return Task.FromResult(new RefreshTokenInfo(OneNoteTestConfig.OneNoteRefreshToken));
    }
}

希望这对别人有帮助

经过进一步的调查,再加上一点尝试+错误+运气,我成功地让它工作了,但不得不使用GetLoginUrl(),而不是使用Selenium使用测试帐户登录到Windows live并批准权限请求,然后使用查询字符串中的代码(..?code=xx.xxx)重定向权限请求我使用它调用AuthClient.ExchangeAuthCodeAsync,并获取包含AccessToken+RefreshToken的会话,对于所有其他测试,我可以使用该刷新标记:-),因为它的有效期为一年。查看我将要发布的答案。做进一步的调查,再加上一点尝试+错误+运气,我设法让它工作,但不得不使用GetLoginUrl(),而不是使用Selenium使用测试帐户登录Windows live并批准权限请求,然后使用查询字符串(..?code=xx.xxx)中的代码重定向权限请求我使用它调用AuthClient.ExchangeAuthCodeAsync,并获取包含AccessToken+RefreshToken的会话,对于所有其他测试,我可以使用该刷新标记:-),因为它的有效期为一年。请看我将要发布的答案。