private void setKey() { var appCredentials = new TwitterCredentials("R4OCY4qm2RJPisvX9rlXhF7mc", textKey.Text); authenticationContext = AuthFlow.InitAuthentication(appCredentials); Process.Start(authenticationContext.AuthorizationURL); textPin.Enabled = true; }
public ActionResult TwitterAuth() { var appCreds = new ConsumerCredentials(MyCredentials.CONSUMER_KEY, MyCredentials.CONSUMER_SECRET); var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth"; var authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); return(new RedirectResult(authenticationContext.AuthorizationURL)); }
private void button1_Click(object sender, EventArgs e) { appCredentials = new TwitterCredentials("LunW98nTNR2EnAaJLuVXvZZAY", "LQXZ4JgwJn07097PXv6MHEmreVXz943yZbBXYJTM0IVPz5ZsOA"); // Инициализируем процесс аутентификации и сохраняем соответствующий «AuthenticationContext». authenticationContext = AuthFlow.InitAuthentication(appCredentials); Process.Start(authenticationContext.AuthorizationURL); }
//public IActionResult Logout() => Auth.SetCredentials(null); public ActionResult TwitterAuth() { var appCreds = new ConsumerCredentials(_key, _secret); var redirectURL = "http://" + Request.Host.Value + "/Home/ValidateTwitterAuth"; var authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); return(new RedirectResult(authenticationContext.AuthorizationURL)); }
public Token CreateTokenFromPin(string pin) { var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pin, authenticationContext); return(new Token { Key = userCredentials.AccessToken, Secret = userCredentials.AccessTokenSecret }); }
/// <summary> /// Action for redirecting user to twiiter auth page. /// </summary> public ActionResult TwitterAuth() { var appCreds = AuthenticationHelper.GetCreds(); var redirectURL = "http://" + Request.Url.Authority + "/TwitterAuth/ValidateTwitterAuth"; var authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); return(new RedirectResult(authenticationContext.AuthorizationURL)); }
public String sendTweet(String NewTweet) { var userCreds = AuthFlow.CreateCredentialsFromVerifierCode(Session["verifierCode"], Container.authorizationId); var user = Tweetinvi.User.GetAuthenticatedUser(userCreds); user.PublishTweet(NewTweet); return("sent!"); }
public TwitterAuthService(BapesTwitterBotContext context, TwitterAppSettings appSettings) { _context = context; var appCredentials = new TwitterCredentials(appSettings.Key, appSettings.Secret); _authenticationContext = AuthFlow.InitAuthentication(appCredentials); }
private void Authorize(string AuthCode) { var UserCredentials = AuthFlow.CreateCredentialsFromVerifierCode(AuthCode, AuthenticationContext); Auth.SetCredentials(UserCredentials); var AuthenticatedUser = Tweetinvi.User.GetAuthenticatedUser(); Console.WriteLine("Connected to Twitter"); }
public TwitterCredentials ActivatePIN(string pin) { TwitterCredentials = (TwitterCredentials)AuthFlow.CreateCredentialsFromVerifierCode(pin, AuthenticationContext); Auth.SetCredentials(TwitterCredentials); SetTwitterTokens(TwitterCredentials.AccessToken, TwitterCredentials.AccessTokenSecret, false); return(TwitterCredentials); }
protected bool AuthenticateImpl(HttpRequestMessage request) { if (m_authFlow != AuthFlow.Obtained) { if (!ExternalAuth) { var host = m_authPath; //GetHost(request.RequestUri.AbsoluteUri); var authUriString = GetAuthUriString(host); HttpClient authClient = new HttpClient(); HttpRequestMessage authReq = new HttpRequestMessage() { RequestUri = new Uri(authUriString), Method = HttpMethod.Post }; authReq.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); List <KeyValuePair <string, string> > authReqContent = BuildAuthRequestContent(); authReq.Content = new FormUrlEncodedContent(authReqContent); authReq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); var authResponse = authClient.SendAsync(authReq).Result; if (authResponse.StatusCode == System.Net.HttpStatusCode.OK) { var content = authResponse.Content.ReadAsStringAsync().Result; AuthDataDeserializeImpl(content); m_authFlow = AuthFlow.Obtained; } else { var reason = SdkAuthException.Reason.Common; ErrorImpl = new SdkAuthException(reason, authResponse.ReasonPhrase); m_authFlow = AuthFlow.ObtainAccessTokenPending; return(false); } } else { m_authFlow = AuthFlow.ObtainAccessTokenPending; return(false); } } else { if (IsAccessTokenExpired()) { if (ExternalAuth) { ErrorImpl = new SdkAuthException(SdkAuthException.Reason.TokenExpired, "Externally provided authorization token expired."); } m_authFlow = AuthFlow.ObtainAccessTokenPending; return(false); } } return(true); }
protected void loginButton_Click(object sender, EventArgs e) { var appCreds = new ConsumerCredentials(consumerKey, consumerSecret); var redirect = $"http://{Request.Url.Authority}"; var authenticationContext = AuthFlow.InitAuthentication(appCreds, redirect); HttpContext.Current.Response.Redirect(authenticationContext.AuthorizationURL); }
public TwitterApiCredentials ValidateTwitterAuth(string authId, string verifierCode) { var credentials = AuthFlow.CreateCredentialsFromVerifierCode(verifierCode, authId); return(new TwitterApiCredentials { AccessToken = credentials.AccessToken, AccessTokenSecret = credentials.AccessTokenSecret }); }
private void continueLogin() { var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(textPin.Text, authenticationContext); Auth.SetCredentials(userCredentials); registry.Write("consumerSecret", userCredentials.ConsumerSecret); registry.Write("accessSecret", userCredentials.AccessTokenSecret); this.DialogResult = DialogResult.OK; this.Close(); }
public ActionResult TwitterLogin() { var appCreds = new ConsumerCredentials(TwitterConsumerKey, TwitterConsumerSecret); // Specify the url you want the user to be redirected to var redirectURL = "http://127.0.0.1:64663/home/twittercallback"; _authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); return(new RedirectResult(_authenticationContext.AuthorizationURL)); }
public IActionResult AuthenticateTwitter() { var coreTwitterCredentials = new ConsumerCredentials( config.TwitterConfiguration.Consumer_Key , config.TwitterConfiguration.Consumer_Secret); var callbackURL = "http://" + Request.Host.Value + "/Home/ValidateOAuth"; var authenticationContext = AuthFlow.InitAuthentication(coreTwitterCredentials, callbackURL); return(new RedirectResult(authenticationContext.AuthorizationURL)); }
public void FinishUserAuthentication(string pinCode) { // With this pin code it is now possible to get the credentials back from Twitter var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext); // Use the user credentials in your application Auth.SetCredentials(userCredentials); m_authorized = true; //FullTwitterSample(); }
public async Task <IActionResult> ValidateAuth() { // 認証後のリダイレクトURLにパラメータがついているのでそれを保持 if (!(Request.Query.ContainsKey("oauth_verifier") && Request.Query.ContainsKey("authorization_id"))) { return(this.RedirectToAction("Login")); } var verifierCode = Request.Query["oauth_verifier"]; var authorizationId = Request.Query["authorization_id"]; // 承認IDと検証者コードから資格情報を取得 var userCreds = AuthFlow.CreateCredentialsFromVerifierCode(verifierCode, authorizationId); var user = Tweetinvi.User.GetAuthenticatedUser(userCreds); // セッションに資格情報を保持 this.HttpContext.Session.Put("UserCreds", userCreds); var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.Name), new Claim("FullName", user.ScreenName), new Claim(ClaimTypes.Role, "Administrator"), new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(userCreds)), // 資格情報をクレーム }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { //AllowRefresh = <bool>, // Refreshing the authentication session should be allowed. // 認証クッキーの有効時間。CookieAuthenticationOptions.ExpireTimeSpan をオーバーライドする ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(15), // false の場合はブラウザを閉じた時点でクッキーは消える IsPersistent = true, //IssuedUtc = <DateTimeOffset>, // The time at which the authentication ticket was issued. //RedirectUri = <string> // The full path or absolute URI to be used as an http // redirect response value. }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToAction("Index", "Home")); }
/// <summary> /// 인증 과정을 거친뒤 TweetInvi 내부에 Credentials을 적용시킵니다. /// </summary> /// <param name="credentials">트위터의 자격 정보입니다.</param> /// <returns></returns> public void CredentialsCertification(TwitterCredentials credentials) { var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(credentials.PINNumber, _context); if (userCredentials == null) { throw new CredentialsTypeException("PINNumber가 잘못 입력되었습니다."); } Auth.SetCredentials(userCredentials); }
public string UserAuthentication() { string consumerKey = "GzWUY0oTfH4AMZdnMqrm0wcde"; string consumerSecret = "QfuQ7YgmLTmvQguuw3siKrwzPCiQ9EW7NleCvhxdRrjSKhfZww"; // Create a new set of credentials for the application. var appCredentials = new TwitterCredentials(consumerKey, consumerSecret); // Init the authentication process and store the related `AuthenticationContext`. authenticationContext = AuthFlow.InitAuthentication(appCredentials); return(authenticationContext.AuthorizationURL); }
public ActionResult TwitterAuth() { //var appCredentials = new TwitterCredentials("7qDmmaoHHfR4r5ktwLdeYBCOZ", "8c1Dl5shUvLRO8P3KuQPo2EzbMIWns5ZgbqjM6TgmxiFYA2gLK"); //var authenticationContext1 = AuthFlow.InitAuthentication(appCredentials); var appCreds = new ConsumerCredentials(MyCredentials.CONSUMER_KEY, MyCredentials.CONSUMER_SECRET); var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth"; //var redirectURL = "http://127.0.0.1:5000/"; var authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); return(new RedirectResult(authenticationContext.AuthorizationURL)); }
//функция авторизации в Twitter по пингоду public bool Auth(string pinCode) { // With this pin code it is now possible to get the credentials back from Twitter var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext); if (userCredentials is null) { return(false); } // Use the user credentials in your application Tweetinvi.Auth.SetCredentials(userCredentials); return(true); }
public IAuthenticationContext Authenticate() { //todo: test settings var appCredentials = new TwitterCredentials(settings.Value.ConsumerKey, settings.Value.ConsumerSecret); Auth.SetUserCredentials( settings.Value.ConsumerKey, settings.Value.ConsumerSecret, settings.Value.AccessToken, settings.Value.TokenSecret); return(AuthFlow.InitAuthentication(appCredentials)); }
private void buttonAuthorize_Click(object sender, EventArgs e) { // Create a new set of credentials for the application. string CKey = Properties.Settings.Default.ConsumerKey; string CSecret = Properties.Settings.Default.ConsumerSecret; TwitterCredentials appCredentials = new TwitterCredentials(CKey, CSecret); // Init the authentication process and store the related `AuthenticationContext`. Program.AuthenticationContext = AuthFlow.InitAuthentication(appCredentials); // Go to the URL so that Twitter authenticates the user and gives him a PIN code. Process.Start(Program.AuthenticationContext.AuthorizationURL); }
public void AddUser(string username, string pin) { var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pin, _authenticationContext); _context.TwitterUsers.Add(new TwitterUser { Username = username, AccessToken = userCredentials.AccessToken, AccessTokenSecret = userCredentials.AccessTokenSecret }); _context.SaveChanges(); }
/// <summary> /// Le indica a twitter que va a hacer una consulta de crendenciales. Esta consulta va a generar un PIN en caso de que sea correcto /// y el usuario tiene que digitar el pin. /// </summary> public void RequestForCredentials() { var appCredentials = new TwitterCredentials("CONSUMER-KEY", "CONSUMER-SECRET"); //GET THE CONSUMER INFORMATION ON THE TWITTER APP MANAGEMENT authenticationContext = AuthFlow.InitAuthentication(appCredentials); //This opens a web-browser and asks to the twitter client //to accept the terms, and twitter gives a code and the user // have to introduce it on the app (use the AuthByPin(String pin) method ) //Thats the PIN for auth the user and then get the data Process.Start(authenticationContext.AuthorizationURL); }
public string RequestAuth() { // Create a new set of credentials for the application. var appCredentials = new TwitterCredentials(conKey, conSecret); // Init the authentication process and store the related `AuthenticationContext`. authenticationContext = AuthFlow.InitAuthentication(appCredentials); // Go to the URL so that Twitter authenticates the user and gives him a PIN code. if (authenticationContext is null) { return(""); } return(authenticationContext.AuthorizationURL); }
private void TwitterAuthenticatorMethod() { try { authenticationContext = AuthFlow.InitAuthentication(_appCredentials); TwitterWebView.NavigationStarting += TwitterWebViewNavigationStarting; TwitterWebView.DOMContentLoaded += TwitterWebViewDomContentLoaded; TwitterWebView.Navigate(new Uri(authenticationContext.AuthorizationURL)); } catch (Exception e) { Debug.WriteLine(e); } }
private void button1_Click(object sender, EventArgs e) { textbox_consumertoken.Enabled = false; textbox_consumersecret.Enabled = false; var applicationCredentials = new ConsumerCredentials(textbox_consumertoken.Text, textbox_consumersecret.Text); authenticationContext = AuthFlow.InitAuthentication(applicationCredentials); System.Diagnostics.Process.Start(authenticationContext.AuthorizationURL); button_request.Enabled = false; textbox_usertoken.Enabled = true; }
// Simple sign in button. Redirects user to page that checks authentication. protected void btnSignIn_Click(object sender, System.Web.UI.ImageClickEventArgs e) { IAuthenticationContext authenticationContext; // App credentials; Key + Secret. These should be queried from a database, but I couldn't access my database so they're visible here. It's bad I know. var appCreds = new ConsumerCredentials("eF3RYgI97aNmDambiGsYT3W0q", "uTjmvgNematqGeqwU7O5yZHlTpiRwwtqrsevLNnA1Pi3TsRe4m"); // Set URL to redirect to after authentication var redirectURL = "http://" + Request.Url.Authority + "/TwitterAuth.aspx"; // Authentication context, used when signing in with Twitter. This will also be stored to session variable for later use authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); Session["authCtx"] = authenticationContext; // Redirect to Twitter authentication Response.Redirect(authenticationContext.AuthorizationURL); }