LiveAuthClient broken?

779 views Asked by At

It seems very much that the current version of LiveAuthClient is either broken or something in my setup/configuration is. I obtained LiveSDK version 5.4.3499.620 via Package Manager Console.

I'm developing an ASP.NET application and the problem is that the LiveAuthClient-class seems to not have the necessary members/events for authentication so it's basically unusable.

IntelliSense auto-complete

Notice that InitializeAsync is misspelled aswell.

What's wrong?

UPDATE:

I obtained another version of LiveSDK which is for ASP.NET applications but now I get the exception "Could not find key with id 1" everytime I try either InitializeSessionAsync or ExchangeAuthCodeAsync.

https://github.com/liveservices/LiveSDK-for-Windows/issues/3

I don't think this is a proper way to fix the issue but I don't have other options at the moment.

1

There are 1 answers

1
Jared On

I'm a little late to the party, but since I stumbled across this trying to solve what I assume is the same problem (authenticating users with Live), I'll describe how I got it working.

First, the correct NuGet package for an ASP.NET project is LiveSDKServer.

Next, getting user info is a multi-step process:

  1. Send the user to Live so they can authorize your app to access their data (the extent of which is determined by the "scopes" you specify)
  2. Live redirects back to you with an access code
  3. You then request user information using the access code

This is described fairly well in the Live SDK documentation, but I'll include my very simple working example below to put it all together. Managing tokens, user data, and exceptions is up to you.

public class HomeController : Controller
{
    private const string ClientId = "your client id";
    private const string ClientSecret = "your client secret";
    private const string RedirectUrl = "http://yourdomain.com/home/livecallback";

    [HttpGet]
    public ActionResult Index()
    {
        // This is just a page with a link to home/signin
        return View();
    }

    [HttpGet]
    public RedirectResult SignIn()
    {
        // Send the user over to Live so they can authorize your application.
        // Specify whatever scopes you need.
        var authClient = new LiveAuthClient(ClientId, ClientSecret, RedirectUrl);
        var scopes = new [] { "wl.signin", "wl.basic" };
        var loginUrl = authClient.GetLoginUrl(scopes);
        return Redirect(loginUrl);
    }

    [HttpGet]
    public async Task<ActionResult> LiveCallback(string code)
    {
        // Get an access token using the authorization code
        var authClient = new LiveAuthClient(ClientId, ClientSecret, RedirectUrl);
        var exchangeResult = await authClient.ExchangeAuthCodeAsync(HttpContext);
        if (exchangeResult.Status == LiveConnectSessionStatus.Connected)
        {
            var connectClient = new LiveConnectClient(authClient.Session);
            var connectResult = await connectClient.GetAsync("me");
            if (connectResult != null)
            {
                dynamic me = connectResult.Result;
                ViewBag.Username = me.name; // <-- Access user info
            }
        }

        return View("Index");
    }
}