Authenticating with Microsoft using AngleSharp

327 views Asked by At

I'm trying to use AngleSharp to authenticate with login.microsoftonline.com so that I can gather data from site(s) using them as a SSO provider.

The code I've got so far: -

var config = Configuration.Default
    .WithJs()
    .WithCss()
    .WithDefaultLoader()
    .WithDefaultCookies();

IBrowsingContext browsingContext = BrowsingContext.New(config);

browsingContext.OpenAsync(@"http://login.microsoftonline.com/").Wait();

(browsingContext.Active.QuerySelector("input[name = 'loginfmt']") as IHtmlInputElement).Value = @"username";
(browsingContext.Active.QuerySelector("form") as IHtmlFormElement).SubmitAsync().Wait();
(browsingContext.Active.QuerySelector("input[name = 'passwd']") as IHtmlInputElement).Value = @"password";
(browsingContext.Active.QuerySelector("form") as IHtmlFormElement).SubmitAsync().Wait();

// Further code then using the cookie(s) once authenticated...

Essentially, 'input[name = 'loginfmt']' resolves to nothing using this code, though that works fine in the browser... Upon inspection of the 'active' document (and its children), it seems to be just full of JavaScript and no sight of the form anywhere..?

0

There are 0 answers