public static XDocument GetUserInfo(int userid, string accessToken) { var endpoint = new MessageReceivingEndpoint("http://api.twitter.com/1/users/show.xml?user_id=" + userid, HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest); IncomingWebResponse response = TwitterSignIn.PrepareAuthorizedRequestAndSend(endpoint, accessToken); var doc = XDocument.Load(XmlReader.Create(response.GetResponseReader())); return(doc); }
/// <summary> /// Prepares a redirect that will send the user to Twitter to sign in. /// </summary> /// <param name="forceNewLogin">if set to <c>true</c> the user will be required to re-enter their Twitter credentials even if already logged in to Twitter.</param> /// <returns>The redirect message.</returns> /// <remarks> /// Call <see cref="OutgoingWebResponse.Send"/> or /// <c>return StartSignInWithTwitter().<see cref="MessagingUtilities.AsActionResult">AsActionResult()</see></c> /// to actually perform the redirect. /// </remarks> public static OutgoingWebResponse StartSignInWithTwitter(bool forceNewLogin) { var redirectParameters = new Dictionary <string, string>(); if (forceNewLogin) { redirectParameters["force_login"] = "******"; } Uri callback = MessagingUtilities.GetRequestUrlFromContext().StripQueryArgumentsWithPrefix("oauth_"); var request = TwitterSignIn.PrepareRequestUserAuthorization(callback, null, redirectParameters); return(TwitterSignIn.Channel.PrepareResponse(request)); }
/// <summary> /// Prepares a redirect that will send the user to Twitter to sign in. /// </summary> /// <param name="forceNewLogin">if set to <c>true</c> the user will be required to re-enter their Twitter credentials even if already logged in to Twitter.</param> /// <returns>The redirect message.</returns> /// <remarks> /// Call <see cref="OutgoingWebResponse.Send"/> or /// <c>return StartSignInWithTwitter().<see cref="MessagingUtilities.AsActionResult">AsActionResult()</see></c> /// to actually perform the redirect. /// </remarks> public static OutgoingWebResponse StartSignInWithTwitter(bool forceNewLogin, Uri callback) { Contract.Requires(callback != null); var redirectParameters = new Dictionary <string, string>(); if (forceNewLogin) { redirectParameters["force_login"] = "******"; } var request = TwitterSignIn.PrepareRequestUserAuthorization(callback, null, redirectParameters); return(TwitterSignIn.Channel.PrepareResponse(request)); }
/// <summary> /// Checks the incoming web request to see if it carries a Twitter authentication response, /// and provides the user's Twitter screen name and unique id if available. /// </summary> /// <param name="screenName">The user's Twitter screen name.</param> /// <param name="userId">The user's Twitter unique user ID.</param> /// <returns> /// A value indicating whether Twitter authentication was successful; /// otherwise <c>false</c> to indicate that no Twitter response was present. /// </returns> public static bool TryFinishSignInWithTwitter(out string screenName, out int userId) { screenName = null; userId = 0; var response = TwitterSignIn.ProcessUserAuthorization(); if (response == null) { return(false); } screenName = response.ExtraData["screen_name"]; userId = int.Parse(response.ExtraData["user_id"]); return(true); }
/// <summary> /// Checks the incoming web request to see if it carries a Twitter authentication response, /// and provides the user's Twitter screen name and unique id if available. /// </summary> /// <param name="screenName">The user's Twitter screen name.</param> /// <param name="userId">The user's Twitter unique user ID.</param> /// <returns> /// A value indicating whether Twitter authentication was successful; /// otherwise <c>false</c> to indicate that no Twitter response was present. /// </returns> public static bool TryFinishSignInWithTwitter(out string screenName, out int userId) { screenName = null; userId = 0; var response = TwitterSignIn.ProcessUserAuthorization(); if (response == null) { return(false); } XDocument xml = VerifyCredentials(TwitterSignIn, response.AccessToken); XPathNavigator nav = xml.CreateNavigator(); screenName = nav.SelectSingleNode("/user/screen_name").Value; userId = int.Parse(nav.SelectSingleNode("/user/id").Value); return(true); }
protected override void beforeEach() { theUrl = "login/test"; theRequest = new TwitterLoginRequest(); theSignIn = new TwitterSignIn(); MockFor <IFubuRequest>().Stub(x => x.Get <TwitterSignIn>()).Return(theSignIn); MockFor <IUrlRegistry>().Stub(x => x.UrlFor(theSignIn)).Return(theUrl); ClassUnderTest.Write(MimeType.Html.Value, theRequest); var html = MimeType.Html.ToString(); theTag = MockFor <IOutputWriter>() .GetArgumentsForCallsMadeOn(x => x.Write(Arg <string> .Is.Same(html), Arg <string> .Is.NotNull)) [0][1].As <string>(); }
public OutgoingWebResponse StartSignInWithTwitter(Uri callback = null) { if (callback == null) { callback = MessagingUtilities .GetRequestUrlFromContext() .StripQueryArgumentsWithPrefix("oauth_"); } var request = TwitterSignIn .PrepareRequestUserAuthorization(callback, null, null); return (TwitterSignIn .Channel .PrepareResponse(request)); }
/// <summary> /// Checks the incoming web request to see if it carries a Twitter authentication response, /// and provides the user's Twitter screen name and unique id if available. /// </summary> /// <param name="screenName">The user's Twitter screen name.</param> /// <param name="userId">The user's Twitter unique user ID.</param> /// <returns> /// A value indicating whether Twitter authentication was successful; /// otherwise <c>false</c> to indicate that no Twitter response was present. /// </returns> public static bool TryFinishSignInWithTwitter(out string screenName, out int userId) { screenName = null; userId = 0; var response = TwitterSignIn.ProcessUserAuthorization(); if (response == null) { return(false); } screenName = response.ExtraData["screen_name"]; userId = int.Parse(response.ExtraData["user_id"]); // If we were going to make this LOOK like OpenID even though it isn't, // this seems like a reasonable, secure claimed id to allow the user to assume. OpenId.Identifier fake_claimed_id = string.Format(CultureInfo.InvariantCulture, "http://twitter.com/{0}#{1}", screenName, userId); return(true); }