I am trying to implement Login with twitter in my ASP.NET webforms application. I want to implement it similar to how the javascript api works for Google+ and Facebook (open a popup on the website without redirecting from the website). I have implemented this for ASP.NET MVC using DotNetOpenAuth.AspNet.Clients.TwitterClient class using the following code:

public ActionResult TwitterLogin()
    TwitterClient client = GetTwitterClientObj();
    UrlHelper helper = new UrlHelper(this.ControllerContext.RequestContext);
    var result = helper.Action("TwitterLoginCallBack", "Account", null, "http");
    client.RequestAuthentication(this.HttpContext, new Uri(result));
    return new EmptyResult();

//This function will be called after user is authenticated by twitter
public ActionResult TwitterLoginCallBack(string returnUrl)
    TwitterClient client = GetTwitterClientObj();
    var result = client.VerifyAuthentication(this.HttpContext);
    return RedirectToAction("TwitterLoginPopup", new { isLoginSuccessful = result.IsSuccessful, twitterId = result.ProviderUserId, screenName = result.UserName });// Calling another function and passing the retrieved data

private TwitterClient GetTwitterClientObj()
    return new TwitterClient(ConfigurationManager.AppSettings["twitterConsumerKey"], ConfigurationManager.AppSettings["twitterConsumerSecret"]);

window.open javascript code for to call TwitterLogin action method mentioned above:

$("#loginWithTwitter").click(function () {
        var screenLeft = 0, screenTop = 0;
        if (typeof window.screenLeft !== 'undefined') {
            screenLeft = window.screenLeft;
            screenTop = window.screenTop;
        } else if (typeof window.screenX !== 'undefined') {
            screenLeft = window.screenX;
            screenTop = window.screenY;
        var left = screenLeft + ($(window).width() - 600) / 2;
        var top = screenTop + ($(window).height() - 600) / 2;
        var myPopup = window.open(baseurl + 'TwitterLogin', "popupWindow", "width=600, height=600, scrollbars=yes, left=" + left + ", top=" + top);

The above code works fine in the MVC application but I want to implement this exact functionality in a WebForms application. I have found examples with other third party libraries but they redirect the user from current website to twitter.com which I do not want. Any other way to implement this functionality in a WebForms application?

Related posts

Recent Viewed