Esempio n. 1
0
        //#########################################################################################################

        protected void AuthorizeContext()
        {
            var credential = new SingleUserInMemoryCredentialStore();

            try
            {
                using (StreamReader sr = new StreamReader(new FileStream("twitterKey.txt", FileMode.Open)))
                {
                    credential.ConsumerKey       = sr.ReadLine();
                    credential.ConsumerSecret    = sr.ReadLine();
                    credential.AccessToken       = sr.ReadLine();
                    credential.AccessTokenSecret = sr.ReadLine();


                    sr.Close();
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("트위터 키 파일을 찾을 수 없습니다.");
            }
            catch (EndOfStreamException)
            {
                Console.WriteLine("트위터 키 파일을 읽을 수 없습니다.");
            }

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = credential,
            };

            auth.AuthorizeAsync().Wait();

            m_twitterCtx = new TwitterContext(auth);
        }
Esempio n. 2
0
        public TwitterClient(SingleUserInMemoryCredentialStore credentials)
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = credentials
            };

            context = new TwitterContext(auth);
        }
Esempio n. 3
0
 public TwitterAuthorizer(IOptions <AppKeyConfig> appKeys) : base()
 {
     CredentialStore = new SingleUserInMemoryCredentialStore
     {
         ConsumerKey       = appKeys.Value.TwitterConsumerKey,
         ConsumerSecret    = appKeys.Value.TwitterConsumerSecret,
         AccessToken       = appKeys.Value.TwitterAccessToken,
         AccessTokenSecret = appKeys.Value.TwitterAccessTokenSecret
     };
 }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false)
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddCors();
            services.AddRazorPages();

            services.AddControllersWithViews(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                config.Filters.Add(new AuthorizeFilter(policy));
            });

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = true;
                options.Password.RequireUppercase       = true;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromMinutes(5);

                options.LoginPath         = "/Identity/Account/Login";
                options.AccessDeniedPath  = "/Identity/Account/AccessDenied";
                options.SlidingExpiration = true;
            });

            TwitterCredentials = Configuration.GetSection("Twitter").Get <SingleUserInMemoryCredentialStore>();
        }
Esempio n. 5
0
        public ICredentialStore RetrieveCredentials()
        {
            NameValueCollection oAuthConfiguration = ConfigurationManager.GetSection("OAuthConfiguration") as NameValueCollection;

            ICredentialStore result = new SingleUserInMemoryCredentialStore()
            {
                ConsumerKey       = oAuthConfiguration["ConsumerKey"],
                ConsumerSecret    = oAuthConfiguration["ConsumerSecret"],
                AccessToken       = oAuthConfiguration["AccessToken"],
                AccessTokenSecret = oAuthConfiguration["AccessTokenSecret"]
            };

            return(result);
        }
        private IAuthorizer GetTwitterAuthorizer()
        {
            // See https://apps.twitter.com/app/7876905/keys for secrets.
            Contract.Ensures(Contract.Result <IAuthorizer>() != null);
            var credentialStore = new SingleUserInMemoryCredentialStore
            {
                ConsumerKey       = "scS2r4sCihglH0IGOE9mtp9vN",
                ConsumerSecret    = "Lg4jPGNhJ4uivCR0m36AUztexZ2EZWxfh8pGEO3IQQJwDWRQlF",
                AccessToken       = "24472612-twnsStRgRLtTf0Q4hRj8AsOUxXRN2YFrSwqQUmNly",
                AccessTokenSecret = "qiaJOmhWxh5PcTZAdkjLQNzP5DFu78DZtD9e7PEGQqK9q"
            };

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = credentialStore
            };

            return(auth);
        }
        private static ICredentialStore GetCredentialStore(Job job)
        {
            var employer  = Storage.Employers.Find(x => x.Id == job.EmployerId);
            var stateName = Storage.States.Find(x => x.Id == employer.StateId).Name;

            var consumerKey       = stateName + "ConsumerKey";
            var consumerSecret    = stateName + "ConsumerSecret";
            var accessToken       = stateName + "AccessToken";
            var accessTokenSecret = stateName + "AccessTokenSecret";

            var credentialStore = new SingleUserInMemoryCredentialStore()
            {
                ConsumerKey       = ConfigurationManager.AppSettings[consumerKey],
                ConsumerSecret    = ConfigurationManager.AppSettings[consumerSecret],
                AccessToken       = ConfigurationManager.AppSettings[accessToken],
                AccessTokenSecret = ConfigurationManager.AppSettings[accessTokenSecret]
            };

            return(credentialStore);
        }