//[EnableCors(origins: "*", headers: "*", methods: "*")] public async Task <ActionResult> BeginAsync(string rowId, string url, string publisher, string media) { //var auth = new MvcSignInAuthorizer string pathurl = ""; if (!string.IsNullOrEmpty(rowId) && !string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(publisher) && !string.IsNullOrEmpty(media)) { string[] CurrentUrl = Request.Url.ToString().Split('?'); var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["consumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"] } }; // string twitterCallbackUrl = Request.Url.ToString().Replace("Begin", "Complete"); string twitterCallbackUrl = CurrentUrl[0].Replace("Begin", "Complete"); // auth.Callback = new Uri(twitterCallbackUrl); await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl + "?rowId=" + rowId + "&CRMUrl=" + url + "&PublisherName=" + publisher + "&SocialMediaType=" + media)); pathurl = "https://api.twitter.com/oauth/authorize?oauth_token=" + auth.Parameters["oauth_token"] + ""; return(Json(pathurl, JsonRequestBehavior.AllowGet)); } else { pathurl = "Error"; return(Json(pathurl, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> BeginAsync() { //var auth = new MvcSignInAuthorizer var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["consumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"] } }; string twitterCallbackUrl = Request.Url.ToString().Replace("Begin", "Complete"); return(await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl))); }
public async Task <ActionResult> Begin() { //var auth = new MvcSignInAuthorizer var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore(HttpContext.Session) { ConsumerKey = configuration["Twitter:ConsumerKey"], ConsumerSecret = configuration["Twitter:ConsumerSecret"] } }; string twitterCallbackUrl = Request.GetDisplayUrl().Replace("Begin", "Complete"); return(await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl))); }
public async Task <IActionResult> BeginAsync() { //var auth = new MvcSignInAuthorizer var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore(HttpContext.Session) { ConsumerKey = twitterKeys.TwitterConsumerKey, ConsumerSecret = twitterKeys.TwitterConsumerSecret } }; string callingUrl = Url.Action(nameof(CompleteAsync), "OAuth", new { }, Request.Scheme); return(await auth.BeginAuthorizationAsync(new Uri(callingUrl))); }
// // GET: /Account/LogOn public async Task <ActionResult> LogOn(bool complete = false) { //return View(); if (!Request.IsAuthenticated) { if (complete) { var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore() }; await auth.CompleteAuthorizeAsync(Request.Url); FormsAuthentication.SetAuthCookie(auth.CredentialStore.ScreenName, true); PostworthyUser pm = UsersCollection.Single(auth.CredentialStore.ScreenName, force: true, addIfNotFound: true); if (string.IsNullOrEmpty(pm.AccessToken) && string.IsNullOrEmpty(pm.OAuthToken)) { pm.AccessToken = auth.CredentialStore.OAuthTokenSecret; pm.OAuthToken = auth.CredentialStore.OAuthToken; UsersCollection.Save(); } return(RedirectToAction("Index", new { controller = "Home", action = "Index", id = UrlParameter.Optional })); } else { //var auth = new MvcSignInAuthorizer var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["TwitterCustomerKey"], ConsumerSecret = ConfigurationManager.AppSettings["TwitterCustomerSecret"] } }; string twitterCallbackUrl = Request.Url.ToString() + "?complete=true"; return(await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl))); } } else { return(RedirectToAction("Index", new { controller = "Home", action = "Index", id = UrlParameter.Optional })); } }
/// <summary> /// Get Twitter login uri async /// </summary> /// <param name="redirectUri"></param> /// <returns></returns> private async Task <ActionResult> GetTwitterLoginUriAsync(Uri redirectUri, int uid) { var userResponse = userService.GetUser(new GetUserRequest(uid)); var user = userResponse.User; var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore { ConsumerKey = user.Account.TwitterAPIKey, ConsumerSecret = user.Account.TwitterAPISecret, OAuthToken = null, OAuthTokenSecret = null } }; return(await auth.BeginAuthorizationAsync(redirectUri)); ; }
public async Task <ActionResult> Begin() { //var auth = new MvcSignInAuthorizer var auth = new MvcAuthorizer { CredentialStore = new SessionStateCredentialStore(HttpContext.Session) { ConsumerKey = Environment.GetEnvironmentVariable("TwitterConsumerKey"), ConsumerSecret = Environment.GetEnvironmentVariable("TwitterConsumerSecret") } }; // to pass parameters that you can read in Complete(), via Request.QueryString, when Twitter returns //var parameters = new Dictionary<string, string> { { "my_custom_param", "val" } }; //string twitterCallbackUrl = Request.GetDisplayUrl().Replace("Begin", "Complete"); //return await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl), parameters); string twitterCallbackUrl = Request.GetDisplayUrl().Replace("Begin", "Complete"); return(await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl))); }