Exemplo n.º 1
0
        public void Read_NotThrowsException_StateIsValid()
        {
            var accessTokenKey = new AccessTokenTableEntity
            {
                TokenId = "normal",
            };
            var accessTokenRepository = new AccessTokenRepository(TestEnvironment.DBSettings);
            var accessToken           = accessTokenRepository.Read(accessTokenKey);

            Assert.IsNotNull(accessToken);
        }
Exemplo n.º 2
0
        public void Update_NotThrowsException_StateIsValid()
        {
            var accessTokenKey = new AccessTokenTableEntity
            {
                TokenId = "normal",
            };
            var accessTokenRepository = new AccessTokenRepository(TestEnvironment.DBSettings);
            var accessToken           = accessTokenRepository.Read(accessTokenKey);

            accessToken.UpdateTime = DateUtil.Now;
            Assert.IsTrue(accessTokenRepository.Update(accessToken));
        }
Exemplo n.º 3
0
        public override void OnNavigatedTo()
        {
            // Set the Defaults
            RevertFileDiscoveryFrequencyCommand.Execute(null);

            // Refresh the File Access Tokens
            var accessTokens = AccessTokenRepository.GetAll();

            foreach (var token in accessTokens)
            {
                FileAccessTokens.Add(token);
            }
        }
Exemplo n.º 4
0
            public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
            {
                const string TOKENNAME = "access_token";

                var query = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query);

                if (!string.IsNullOrWhiteSpace(query[TOKENNAME]))
                {
                    var token = query[TOKENNAME];

                    this.tokenRepo = new AccessTokenRepository();
                    var authToken = tokenRepo.GetAuthToken(token);

                    if (authToken != null && authToken.Expiration > DateTime.Now)
                    {
                        if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
                        {
                            return;
                        }

                        //User repository
                        var user = userRepo.GetUser(authToken.UserID);

                        if (user == null)
                        {
                            return;
                        }

                        var username = user.Name;
                        var password = user.Password;

                        if (!WebSecurity.Initialized)
                        {
                            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                        }

                        if (WebSecurity.Login(username, password))
                        {
                            var principal = new GenericPrincipal(new GenericIdentity(username), null);
                            Thread.CurrentPrincipal = principal;
                            return;
                        }
                    }
                }
                HandleUnauthorized(actionContext);
            }
        void ApproveRequestForAccess(string tokenString)
        {
            DevDefined.OAuth.Storage.Basic.RequestToken requestToken = RequestTokenRepository.GetToken(tokenString);

            var accessToken = new DevDefined.OAuth.Storage.Basic.AccessToken
            {
                ConsumerKey = requestToken.ConsumerKey,
                Realm       = requestToken.Realm,
                Token       = Guid.NewGuid().ToString(),
                TokenSecret = Guid.NewGuid().ToString(),
                UserName    = HttpContext.Current.User.Identity.Name,
                //ExpireyDate = DateTime.Now.AddMinutes(1),
                Roles = new string[] {}
            };

            AccessTokenRepository.SaveToken(accessToken);

            requestToken.AccessToken = accessToken;

            RequestTokenRepository.SaveToken(requestToken);
        }
Exemplo n.º 6
0
        public void Create_NotThrowsException_StateIsValid()
        {
            var now         = DateUtil.Now;
            var accessToken = new AccessTokenTableEntity
            {
                TokenId       = new string('X', 100),
                Name          = new string('X', 100),
                Description   = new string('X', 400),
                ApplicationId = Guid.NewGuid(),
                PrincipalType = PrincipalType.Application.ToString(),
                PrincipalId   = Guid.NewGuid(),
                Scopes        = new string('X', 8000),
                Status        = AccessTokenStatus.NORMAL.ToString(),
                ExpiryTime    = DateTimeOffset.MaxValue,
                CreateTime    = DateTimeOffset.MaxValue,
                UpdateTime    = DateTimeOffset.MaxValue,
            };
            var accessTokenRepository = new AccessTokenRepository(TestEnvironment.DBSettings);

            accessTokenRepository.Create(accessToken);
        }
Exemplo n.º 7
0
        void ApproveRequestForAccess(string tokenString)
        {
            RequestToken requestToken = RequestTokenRepository.GetToken(tokenString);

            var accessToken = new AccessToken
            {
                ConsumerKey = requestToken.ConsumerKey,
                Realm       = requestToken.Realm,
                Token       = Guid.NewGuid().ToString(),
                TokenSecret = Guid.NewGuid().ToString(),
                UserName    = HttpContext.Current.User.Identity.Name,
                ExpireyDate = DateTime.Now.AddMinutes(1)
            };

            AccessTokenRepository.SaveToken(accessToken);

            requestToken.AccessToken = accessToken;

            requestToken.Verifier = UnguessableGenerator.GenerateUnguessable();

            RequestTokenRepository.SaveToken(requestToken);
        }
Exemplo n.º 8
0
        public async void RemoveFileAccessToken(FileAccessToken token)
        {
            ContentDialog removeDialog = new ContentDialog
            {
                Title             = "Remove File Access Token?",
                Content           = "By doing this, the application will no longer have access to these directories and their children. As a result the directories and their files will be removed from your Themes and will require resetting up themes which use them. Are you sure you want to remove this File Access Token from the App?",
                PrimaryButtonText = "Remove",
                CloseButtonText   = "Cancel"
            };

            ContentDialogResult result = await removeDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                // Remove from the Lists
                FileAccessTokens.Remove(token);

                // Delete the Directory
                AccessTokenRepository.RemoveAndCommit(token.ID);

                // Update the Cache
                RefreshFileCacheCommand.Execute(null);
            }
        }
 public AccessTokenController()
 {
     repositorio = new AccessTokenRepository(new SistemaContext());
 }
Exemplo n.º 10
0
 public ApiAuthorizeAttribute(bool perUser = true)
 {
     this.perUser   = perUser;
     this.tokenRepo = new AccessTokenRepository();
 }
Exemplo n.º 11
0
 public BaseBiz()
 {
     db = new NetkaCommitmentContext();
     oAccessTokenRepository = new AccessTokenRepository();
     oAccessLogRepository   = new AccessLogRepository();
 }
Exemplo n.º 12
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add and configure Carter
            services.AddCarter((options) =>
            {
                options.OpenApi.DocumentTitle = this.appConfig.CarterOptions.OpenApi.DocumentTitle;
                options.OpenApi.ServerUrls    = new[]
                {
                    "http://localhost:8090/api/v1",
                    "https://expcap.xyz/api/v1",
                    "https://expcap2.xyz/api/v1",
                };

                options.OpenApi.Securities = new Dictionary <string, OpenApiSecurity>
                {
                    {
                        "TokenAuthorization",
                        new OpenApiSecurity
                        {
                            Type = OpenApiSecurityType.apiKey,
                            Name = "ExperienceCapture-Access-Token",
                            In   = OpenApiIn.cookie,
                        }
                    },
                };
            });

            // Add custom serialization logic for Enums
            BsonSerializer.RegisterSerializer(new EnumSerializer <ExportOptions>(BsonType.String));
            BsonSerializer.RegisterSerializer(new EnumSerializer <RoleOptions>(BsonType.String));

            // Add repositories based on Mongo
            string mongoUrl = $"mongodb://{AppConfiguration.Mongo.ConnectionString}:{AppConfiguration.Mongo.Port}";
            var    client   = new MongoClient(mongoUrl);
            var    db       = client.GetDatabase("ec");

            var signUpRepo = new SignUpTokenRepository(db);

            services.AddSingleton <IRepository <SignUpTokenSchema> >(signUpRepo);

            var accessRepo = new AccessTokenRepository(db);

            services.AddSingleton <IRepository <AccessTokenSchema> >(accessRepo);

            var claimRepo = new ClaimTokenRepository(db);

            services.AddSingleton <IRepository <ClaimTokenSchema> >(claimRepo);

            var sessionRepo = new SessionRepository(db);

            services.AddSingleton <IRepository <SessionSchema> >(sessionRepo);

            var captureRepo = new CapturesRepository(db);

            services.AddSingleton <IRepository <BsonDocument> >(captureRepo);

            var personRepo = new PersonRepository(db);

            services.AddSingleton <IRepository <PersonSchema> >(personRepo);

            // Add Threading
            var threader = new ExportThreader();

            services.AddSingleton <IThreadExtra>(threader);

            // Add time
            var date = new DateProvider();

            services.AddSingleton <IDateExtra>(date);

            // Add Minio
            string minioUsername = "******";
            string minioPassword = "******";

            string minioHost = $"{AppConfiguration.Minio.ConnectionString}:{AppConfiguration.Minio.Port}";
            var    os        = new MinioClientExtra(minioHost, minioUsername, minioPassword);

            services.AddSingleton <IMinioClient>(os);

            // Add environment
            var env = ConfigureAppEnvironment.FromEnv();

            services.AddSingleton <IAppEnvironment>(env);

            // Add logging
            var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var logger        = loggerFactory.CreateLogger <Program>();

            services.AddSingleton <ILogger>(logger);
        }