Beispiel #1
0
        private static BaseAuthenticationInfo LocateLinkedinResponse()
        {
            var    authorization = new WebOAuthAuthorization(LinkedinTokenManager, null);
            string accessToken;

            try
            {
                accessToken = authorization.CompleteAuthorize();
            }
            catch (Exception ex)
            {
                return(null);
            }
            if (accessToken != null)
            {
                authorization = new WebOAuthAuthorization(LinkedinTokenManager, accessToken);
                LinkedInService service = new LinkedInService(authorization);
                var             profile = service.GetCurrentUser(ProfileType.Public);
                var             info    = new LinkedinAuthenticationInfo();
                info.FirstName  = profile.FirstName;
                info.LastName   = profile.LastName;
                info.Identifier = profile.Id;
                info.UserName   = profile.Name;
                info.Provider   = providerModule.GetProvider("LinkedIn");
                return(info);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken);

        if (!Page.IsPostBack)
        {
            // try to complete a pending authorization in case there is one.
            string accessToken = auth.CompleteAuthorize();
            if (accessToken != null)
            {
                // Store the access token in session state so we can get at it across page refreshes.
                // In a real app, you'd want to associate this access token with the user that is
                // logged into your app at this point.
                InMemoryTokenManager.AccessToken = accessToken;

                // Clear away the OAuth message so that users can refresh the page without problems.
                Response.Redirect(Page.Request.Path);
            }
        }

        if (string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) || string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret))
        {
            // The user needs to set up the web.config file to include Twitter consumer key and secret.
            PrivateDataMultiView.SetActiveView(SetupTwitterConsumer);
        }
        else if (auth.CachedCredentialsAvailable)
        {
            auth.SignOn(); // acquire the screen name, and ensure the access token is still valid.
            screenNameLabel.Text = auth.ScreenName;
            PrivateDataMultiView.SetActiveView(ViewPrivateUpdates);
            updateBox.Focus();
        }
        else
        {
            PrivateDataMultiView.SetActiveView(AuthorizeTwitter);
        }

        twitterCtx = auth.CachedCredentialsAvailable ? new TwitterContext(auth) : new TwitterContext();

        var tweets =
            from tweet in twitterCtx.Status
            where tweet.Type == (auth.CachedCredentialsAvailable ? StatusType.Friends : StatusType.Public)
            select tweet;

        TwitterListView.DataSource = tweets;
        TwitterListView.DataBind();

        // demonstrate serialization

        var serializableUser =
            (from user in twitterCtx.User
             where user.Type == UserType.Show &&
             user.ScreenName == "JoeMayo"
             select user)
            .FirstOrDefault();

        // if you have ASP.NET state server turned on
        // this will still work because User is serializable
        Session["SerializableUser"] = serializableUser;
    }