Exemplo n.º 1
0
        private string BuildToken(FileEntity file)
        {
            var tokenModel = new DriveToken()
            {
                Header = new DefaultJwtHeader()
                {
                    Algorithm = SecurityAlgorithms.HmacSha256
                },
                Payload = new MvcIdentityPayload()
                {
                    Actor    = file.RelativePath,
                    Issuer   = Startup.Configuration.GetSection("JWT:Issuer").Value,
                    Audience = Startup.Configuration.GetSection("JWT:Audience").Value,
                    Name     = file.RelativePath,
                    Role     = DriveToken.Roles.Download,
                    Subject  = DriveToken.Subjects.ConsoleLogin,
                    IssuedAt = DateTime.Now,
                    Expires  = DateTime.Now.AddHours(12)
                }
            };

            var key = new SymmetricSecurityKey(Startup.Configuration.GetSection("JWT:SecureKey")
                                               .Value.ToHash <MD5>()
                                               );

            return(tokenModel.Sign(key));
        }
Exemplo n.º 2
0
        private string BuildToken(User user)
        {
            var tokenModel = new DriveToken()
            {
                Header = new DefaultJwtHeader()
                {
                    Algorithm = SecurityAlgorithms.HmacSha256
                },
                Payload = new MvcIdentityPayload()
                {
                    Actor    = user.Id,
                    Issuer   = Startup.Configuration.GetSection("JWT:Issuer").Value,
                    Audience = Startup.Configuration.GetSection("JWT:Audience").Value,
                    Name     = user.Id,
                    Role     = user.IsAdmin ? DriveToken.Roles.Administrator : DriveToken.Roles.Default,
                    Subject  = DriveToken.Subjects.ConsoleLogin,
                    IssuedAt = DateTime.Now,
                    Expires  = DateTime.Now.AddDays(7)
                }
            };

            var key = new SymmetricSecurityKey(Startup.Configuration.GetSection("JWT:SecureKey")
                                               .Value.ToHash <MD5>()
                                               );

            return(tokenModel.Sign(key));
        }
Exemplo n.º 3
0
        public string CompleteOAuthFlow(AuthorizationParameters parameters)//AuthorizationParameters parameters)
        {
            try
            {
                DriveRestClient restClient = new DriveRestClient(AppConstants.GoogleDriveClientId, AppConstants.GoogleDriveClientSecret, googledriveRedirectUrl.ToString());

                DriveToken token = restClient.GetTokenfromCode(parameters.Code);

                Storage.GoogleDrive.Token = token;
                return("OAuth succeeded");
            }
            catch (Exception ex)// ActiveDirectoryAuthenticationException ex)
            {
                return("OAuth failed. " + ex.ToString());
            }
        }
Exemplo n.º 4
0
        public IActionResult Download(
            [FromQuery] string path,
            [FromQuery] string token)
        {
            DriveToken tokenInfo = VerifyToken(token);

            if (tokenInfo.Payload.Actor != tokenInfo.Payload.Name &&
                tokenInfo.Payload.Actor != path)
            {
                throw new PermissionsException();
            }

            string fullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], path);

            var fileEntity = FileEntity.FromPath(fullPath);

            var file = fileEntity.FileInfo.Open(
                System.IO.FileMode.Open,
                System.IO.FileAccess.Read,
                System.IO.FileShare.Read);

            return(File(file, fileEntity.ContentType, System.IO.Path.GetFileName(path), true));
        }