Esempio n. 1
0
        public void Table_CreateResourceToken_ReturnsExpectedStartDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            // Calculate the expected start time give or take 4 seconds.
            DateTime startRangeBegin = DateTime.UtcNow - TimeSpan.FromMinutes(5) - TimeSpan.FromSeconds(2);
            DateTime startRangeEnd   = startRangeBegin + TimeSpan.FromSeconds(2);

            // Now convert these into strings using the SAS format.
            string startRangeBeginString = this.DateTimeToSASDateString(startRangeBegin);
            string startRangeEndString   = this.DateTimeToSASDateString(startRangeEnd);

            // Get the actual begin time from the SAS token.
            SASParts parts     = new SASParts(token.Uri);
            string   beginning = parts.Value("st");

            // Make sure it is within the range.
            Assert.IsTrue(string.CompareOrdinal(beginning, startRangeBeginString) >= 0 && string.CompareOrdinal(beginning, startRangeEndString) <= 0);
        }
Esempio n. 2
0
        //public YouTubeRequest CreateRequest()
        //{
        //    YouTubeRequestSettings settings = new YouTubeRequestSettings("example app", "AI39si7jQY5Bd6hNDeXn7DhWp3Fpyf_xs5Q7K2VhZAheGI05_Nis7DDi97NONfMAgyjmJm6cAxQpJ4TzxZaOkne1vzjZ7t1HCQ", "*****@*****.**", "Test123@1");
        //    return new YouTubeRequest(settings);
        //}

        public ResourceToken WriteFileSimple(string FileName, string UserToken)
        {
            //Create token using webservices
            //FileInfo f = new FileInfo(filepath);
            ResourceToken objToken = objClient.GetWriteFileSimple("File", FileName, "", UserToken);

            return(objToken);
        }
Esempio n. 3
0
        private object ResolveIfToken(object resource)
        {
            ResourceToken token = resource as ResourceToken;

            if (token == null)
            {
                return(resource);
            }
            return(token.Resource);
        }
Esempio n. 4
0
        public void Blob_CreateResourceToken_WithProcessPermissions_IgnoresProcessPermissions()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("r", parts.Value("sp"));
        }
Esempio n. 5
0
        //chk
        ////Here Response Means Pass the "Page.Response"
        //public void DownloadFile(string url, string fileName, HttpResponse Response)
        //{
        //    //Create a stream for the file
        //    Stream stream = null;

        //    //This controls how many bytes to read at a time and send to the client
        //    int bytesToRead = 10000;

        //    // Buffer to read bytes in chunk size specified above
        //    byte[] buffer = new Byte[bytesToRead];

        //    // The number of bytes read
        //    try
        //    {

        //        //Create a WebRequest to get the file
        //        HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(url);

        //        //Create a response for this request
        //        HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

        //        if (fileReq.ContentLength > 0)
        //            fileResp.ContentLength = fileReq.ContentLength;

        //        //Get the Stream returned from the response
        //        stream = fileResp.GetResponseStream();

        //        //Indicate the type of data being sent
        //        Response.ContentType = "application/octet-stream";
        //        Response.BufferOutput = true;
        //        //Name the file
        //        Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        //        Response.AddHeader("Content-Length", fileResp.ContentLength.ToString());



        //        int length;
        //        do
        //        {
        //            // Verify that the client is connected.
        //            if (Response.IsClientConnected)
        //            {
        //                // Read data into the buffer.
        //                length = stream.Read(buffer, 0, bytesToRead);

        //                // and write it out to the response's output stream
        //                Response.OutputStream.Write(buffer, 0, length);

        //                // Flush the data
        //                Response.Flush();


        //                //Clear the buffer
        //                buffer = new Byte[bytesToRead];
        //            }
        //            else
        //            {
        //                // cancel the download if client has disconnected
        //                length = -1;
        //            }
        //        } while (length > 0); //Repeat until no data is read

        //        Response.Clear();
        //    }
        //    catch (Exception ex)
        //    {
        //        Response.Clear();
        //    }
        //    finally
        //    {
        //        if (stream != null)
        //        {
        //            //Close the input stream
        //            stream.Close();
        //        }
        //    }

        //}

        //Here Type means - For messages(Attachment) - For Files (File)
        //Parent Id means - For messages(MessageMasterId) - For Files (UserId (or) FolderId)
        public string GetFileUrl(string relId, string UserToken)
        {
            string fileurl = "";

            try
            {
                ResourceToken RToken = objClient.GetReadFile(relId, UserToken);
                fileurl = RToken.Url;
            }
            catch (Exception fileurlnotavailble)
            {
                string exceptionmessage = fileurlnotavailble.Message;
            }
            return(fileurl);
        }
Esempio n. 6
0
        public void Table_CreateResourceToken_WithAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("aud", parts.Value("sp"));
        }
Esempio n. 7
0
        public void Blob_CreateResourceToken_WithReadAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("rw", parts.Value("sp"));
        }
        public void Queue_CreateResourceToken_WithReadAndProcessPermissions_ReturnsCorrectAccess()
        {
            AzureQueueBroker broker = new AzureQueueBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "queue", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("rp", parts.Value("sp"));
        }
Esempio n. 9
0
        private object TokenToResource(object resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            ResourceToken token = resource as ResourceToken;

            if (token == null)
            {
                throw new ArgumentException("Resource token was of unexpected type '" + resource.GetType() + "'");
            }

            return(token.Resource);
        }
Esempio n. 10
0
        public void Table_CreateResourceToken_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual(null, parts.Value("se"));
        }
Esempio n. 11
0
        public void Table_CreateResourceToken_ReturnsCorrectHostPath()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("https://test.table.core.windows.net/table", parts.HostName);
        }
Esempio n. 12
0
        public void Blob_CreateResourceAsync_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual(null, parts.Value("se"));
        }
Esempio n. 13
0
        public void Table_CreateResourceToken_WithExpirationDate_ReturnsCorrectExpirationDate()
        {
            // Setup
            DateTime         expiration = new DateTime(2199, 3, 12, 1, 2, 3, DateTimeKind.Utc);
            AzureTableBroker broker     = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read, Expiration = expiration
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("2199-03-12T01%3A02%3A03Z", parts.Value("se"));
        }
Esempio n. 14
0
        public IList GetResourceTokens(string since, string parentId, string objType, string userToken)
        {
            IList ResourceToken = new ArrayList();

            Relation[] arrRel = objClient.GetChildren(since, objType, parentId, userToken);
            foreach (Relation item in arrRel)
            {
                try
                {
                    ResourceToken RToken = objClient.GetReadFile(item.Id, userToken);

                    ResourceToken.Add(RToken);
                }
                catch (Exception photonotfound) {
                    string photonotfoundexceptiodetail = photonotfound.Message;
                }
            }
            return(ResourceToken);
        }
Esempio n. 15
0
        //Parent Id means - For messages(MessageMasterId) - For Files (UserId (or) FolderId)
        public MyFile WriteFile(string FileName, Stream FileContent, string ParentId, string UserToken)
        {
            //Create token using webservices
            //FileInfo f = new FileInfo(filepath);
            ResourceToken objToken = objClient.GetWriteFile("File", FileName, "", UserToken);

            //Uploading the File to Amazon Url
            UploadFile(FileContent, objToken.Url, objClient.GetMimeType(FileName));

            //Set status in web services
            objClient.SetWriteSuccess(objToken.ContentId, UserToken);

            //Updating content info in webservices
            FileInfo objInfo = new FileInfo(FileName);
            Dictionary <string, string> DicProperties = new Dictionary <string, string>();

            DicProperties.Add("Name", objInfo.Name);
            //*****object type should be set based on file content type....*//
            MyFile file = objClient.AddFile(objToken.ContentId, FileName, ParentId, "pdf", JsonConvert.SerializeObject(DicProperties), UserToken);

            return(file);
        }
Esempio n. 16
0
        //Parent Id means - For messages(MessageMasterId) - For Files (UserId (or) FolderId)
        public ResourceToken GetFileName(string relId, string UserToken)
        {
            ResourceToken RToken = objClient.GetReadFile(relId, UserToken);

            return(RToken);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Setup the client
            services.AddIdentity <ApplicationUser, IdentityRole>().AddEntityFrameworkStores <ApplicationDbContext>().AddDefaultTokenProviders();

            services.AddIdentityServer()
            // .AddTemporarySigningCredential() // Can be used for testing until a real cert is available
            .AddDeveloperSigningCredential()
            .AddInMemoryClients(Config.GetClients())
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            // .AddInMemoryApiResources(Config.GetApis())
            .AddSigningCredential(new X509Certificate2(Path.Combine(".", "certs", "IdentityServer4Auth.pfx"), "Lespaul10"))
            .AddInMemoryApiResources(ResourceToken.GetAllResources())
            .AddAspNetIdentity <ApplicationUser>();

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = "Guess",
                    ValidAudience    = "What",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Lespaul10")),
                    ClockSkew        = TimeSpan.Zero                              // remove delay of token when expire
                };
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });

                c.DescribeAllEnumsAsStrings();
                c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"API.xml"));
            });
            services.AddMvc();

            //StructureMap Container
            var container = new Container();

            container.Configure(config =>
            {
                config.Scan(_ =>
                {
                    // Registering to allow for Interfaces to be dynamically mapped
                    _.AssemblyContainingType(typeof(Startup));
                    //List assemblys here
                    _.Assembly("API");
                    _.Assembly("Logic");
                    _.Assembly("Models");
                    _.WithDefaultConventions();
                });
                config.Populate(services);
            });

            return(container.GetInstance <IServiceProvider>());
        }