Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken);
        if (!string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) &&
            !string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret))
        {
            AuthMultiView.ActiveViewIndex = 1;

            if (!IsPostBack)
            {
                if (auth.CompleteAuthenticate())
                {
                    AuthMultiView.SetActiveView(SignedInView);
                    screenNameLabel.Text = auth.ScreenName;
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        IOAuthCredentials credentials = new InMemoryCredentials();
        string            authString  = Session[OAuthCredentialsKey] as string;

        if (authString == null)
        {
            credentials.ConsumerKey    = ConfigurationManager.AppSettings["twitterConsumerKey"];
            credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];

            Session[OAuthCredentialsKey] = credentials.ToString();
        }
        else
        {
            credentials.Load(authString);
        }

        auth = new SignInAuthorizer
        {
            Credentials = new InMemoryCredentials
            {
                ConsumerKey    = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]
            },
            PerformRedirect = authUrl => Response.Redirect(authUrl)
        };

        if (!Page.IsPostBack)
        {
            if (!string.IsNullOrWhiteSpace(credentials.ConsumerKey) &&
                !string.IsNullOrWhiteSpace(credentials.ConsumerSecret))
            {
                AuthMultiView.ActiveViewIndex = 1;

                if (auth.CompleteAuthorization(Request.Url))
                {
                    AuthMultiView.SetActiveView(SignedInView);
                    screenNameLabel.Text = auth.ScreenName;
                }
            }
        }
    }