├── .gitattributes ├── .gitignore ├── Curse.RestProxy.Tests ├── Authentication │ └── TokenIdentityTests.cs ├── Controllers │ ├── AddOnControllerDescriptionTests.cs │ ├── AddOnControllerGetTests.cs │ ├── AddOnFilesControllerChangelogTests.cs │ ├── AddOnFilesControllerGetTests.cs │ ├── AddOnFilesControllerIndexTests.cs │ ├── AuthenticationControllerLoginTests.cs │ ├── IndexControllerIndexTests.cs │ └── IndexControllerStatusTests.cs ├── Curse.RestProxy.Tests.csproj ├── Properties │ └── AssemblyInfo.cs ├── Serialization │ └── SnakeCasePropertyNamesContractResolverTests.cs ├── app.config └── packages.config ├── Curse.RestProxy.sln ├── Curse.RestProxy ├── AddOnService │ └── TokenEndpointBehavior.cs ├── App_Start │ ├── DependencyContainerConfig.cs │ └── WebApiConfig.cs ├── ApplicationInsights.config ├── Authentication │ ├── CurseFailedAuthenticationExceptionFilter.cs │ ├── SetCurseTokenActionFilter.cs │ ├── TokenAuthenticationFilter.cs │ └── TokenIdentity.cs ├── Controllers │ ├── AddOnController.cs │ ├── AddOnFilesController.cs │ ├── AuthenticationController.cs │ └── IndexController.cs ├── Curse.RestProxy.csproj ├── Global.asax ├── Global.asax.cs ├── Http │ ├── HttpResponseMessageExtensions.cs │ ├── IHttpActionResultExtensions.cs │ └── WrappedActionResult.cs ├── Models │ └── AuthenticationRequest.cs ├── Properties │ ├── AssemblyInfo.cs │ └── PublishProfiles │ │ └── curse-rest-proxy.pubxml ├── Serialization │ └── SnakeCasePropertyNamesContractResolver.cs ├── Service References │ ├── AddOnService │ │ ├── AddOnService.disco │ │ ├── AddOnService.wsdl │ │ ├── AddOnService.xsd │ │ ├── AddOnService1.wsdl │ │ ├── AddOnService1.xsd │ │ ├── AddOnService2.xsd │ │ ├── AddOnService3.xsd │ │ ├── AddOnService4.xsd │ │ ├── AddOnService5.xsd │ │ ├── AddOnService6.xsd │ │ ├── Curse.RestProxy.AddOnService.AddOn.datasource │ │ ├── Curse.RestProxy.AddOnService.AddOnFile.datasource │ │ ├── Curse.RestProxy.AddOnService.DownloadToken.datasource │ │ ├── Curse.RestProxy.AddOnService.FingerprintMatchResult.datasource │ │ ├── Curse.RestProxy.AddOnService.FuzzyMatch.datasource │ │ ├── Curse.RestProxy.AddOnService.RepositoryMatch.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponse.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSavedGameeheogrl4.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSyncedGameInstanceeheogrl4.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponseOfESavedGameRestrictionLeveleheogrl4.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponseOfSavedGameConstraintseheogrl4.datasource │ │ ├── Curse.RestProxy.AddOnService.ServiceResponseOfSyncedGameInstanceeheogrl4.datasource │ │ ├── Reference.cs │ │ ├── Reference.svcmap │ │ ├── configuration.svcinfo │ │ └── configuration91.svcinfo │ └── LoginService │ │ ├── ClientLoginService.disco │ │ ├── ClientLoginService.wsdl │ │ ├── ClientLoginService.xsd │ │ ├── ClientLoginService1.wsdl │ │ ├── ClientLoginService1.xsd │ │ ├── ClientLoginService2.xsd │ │ ├── Curse.RestProxy.LoginService.LoginResponse.datasource │ │ ├── Curse.RestProxy.LoginService.RegisterUserResult.datasource │ │ ├── Reference.cs │ │ ├── Reference.svcmap │ │ ├── configuration.svcinfo │ │ └── configuration91.svcinfo ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Authentication/TokenIdentityTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Curse.RestProxy.Authentication; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Curse.RestProxy.Tests.Authentication 6 | { 7 | [TestClass] 8 | public class TokenIdentityTests 9 | { 10 | [TestMethod] 11 | public void ConstructorSetsUserId() 12 | { 13 | var identity = new TokenIdentity(1, "token"); 14 | 15 | Assert.AreEqual(1, identity.UserId, 16 | "The constructor should set the UserId"); 17 | } 18 | 19 | [TestMethod] 20 | public void ConstructorSetsToken() 21 | { 22 | var identity = new TokenIdentity(1, "token"); 23 | 24 | Assert.AreEqual("token", identity.Token, 25 | "The constructor should set the Token"); 26 | } 27 | 28 | [TestMethod] 29 | [ExpectedException(typeof(ArgumentNullException), 30 | "Constructing with a null token should throw ArgumentNullException")] 31 | public void ConstructorThrowsWhenTokenNull() 32 | { 33 | new TokenIdentity(1, null); 34 | } 35 | 36 | [TestMethod] 37 | public void NameIsUserId() 38 | { 39 | var identity = new TokenIdentity(1, "token"); 40 | 41 | Assert.AreEqual("1", identity.Name, 42 | "Name should be the string represenation of UserId"); 43 | } 44 | 45 | [TestMethod] 46 | public void AuthenticationTypeIsToken() 47 | { 48 | var identity = new TokenIdentity(1, "token"); 49 | 50 | Assert.AreEqual("Token", identity.AuthenticationType, 51 | "AuthenticationType should be \"Token\""); 52 | } 53 | 54 | [TestMethod] 55 | public void IsAuthenticatedIsTrue() 56 | { 57 | var identity = new TokenIdentity(1, "token"); 58 | 59 | Assert.IsTrue(identity.IsAuthenticated, 60 | "IsAuthenticated should be true."); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AddOnControllerDescriptionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.Results; 4 | using Curse.RestProxy.Controllers; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Moq; 7 | 8 | namespace Curse.RestProxy.Tests.Controllers 9 | { 10 | [TestClass] 11 | public class AddOnControllerDescriptionTests 12 | { 13 | [TestMethod] 14 | public void DescriptionReturnsOkWhenAddOnFound() 15 | { 16 | var description = "description"; 17 | var addOnService = Mock.Of(s => 18 | s.v2GetAddOnDescriptionAsync(1) == Task.FromResult(description) 19 | ); 20 | 21 | var controller = new AddOnController(addOnService); 22 | 23 | var result = controller.Description(1).Result; 24 | 25 | Assert.IsTrue(result.GetType().FullName.StartsWith("System.Web.Http.Results.OkNegotiatedContentResult"), 26 | "Description should return Ok when the addon is found"); 27 | } 28 | 29 | [TestMethod] 30 | public void DescriptionReturnsResultFromAddOnService() 31 | { 32 | var description = "description"; 33 | var addOnService = Mock.Of(s => 34 | s.v2GetAddOnDescriptionAsync(1) == Task.FromResult(description) 35 | ); 36 | 37 | var controller = new AddOnController(addOnService); 38 | 39 | dynamic result = controller.Description(1).Result; 40 | 41 | Assert.AreEqual(description, result.Content.Description, 42 | "Description should return result from the addon service"); 43 | } 44 | 45 | [TestMethod] 46 | public void DescriptionReturnsNotFoundWhenAddOnDoesNotExist() 47 | { 48 | var addOnService = Mock.Of(s => 49 | s.v2GetAddOnDescriptionAsync(1) == Task.FromResult((string)null) 50 | ); 51 | 52 | var controller = new AddOnController(addOnService); 53 | 54 | var result = controller.Description(1).Result; 55 | 56 | Assert.IsInstanceOfType(result, typeof(NotFoundResult), 57 | "Description should return not found when addon does not exist"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AddOnControllerGetTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.Results; 4 | using Curse.RestProxy.Controllers; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Moq; 7 | 8 | namespace Curse.RestProxy.Tests.Controllers 9 | { 10 | [TestClass] 11 | public class AddOnControllerGetTests 12 | { 13 | [TestMethod] 14 | public void GetReturnsOkWhenAddOnFound() 15 | { 16 | var addOn = new AddOnService.AddOn(); 17 | var addOnService = Mock.Of(s => 18 | s.GetAddOnAsync(1) == Task.FromResult(addOn) 19 | ); 20 | 21 | var controller = new AddOnController(addOnService); 22 | 23 | var result = controller.Get(1).Result; 24 | 25 | Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult), 26 | "Get should return Ok when the addon is found"); 27 | } 28 | 29 | [TestMethod] 30 | public void GetReturnsResultFromAddOnService() 31 | { 32 | var addOn = new AddOnService.AddOn(); 33 | var addOnService = Mock.Of(s => 34 | s.GetAddOnAsync(1) == Task.FromResult(addOn) 35 | ); 36 | 37 | var controller = new AddOnController(addOnService); 38 | 39 | var result = controller.Get(1).Result as OkNegotiatedContentResult; 40 | 41 | Assert.AreEqual(addOn, result.Content, 42 | "Get should return result from the addon service"); 43 | } 44 | 45 | [TestMethod] 46 | public void GetReturnsNotFoundWhenAddOnDoesNotExist() 47 | { 48 | var addOnService = Mock.Of(s => 49 | s.GetAddOnAsync(1) == Task.FromResult((AddOnService.AddOn)null) 50 | ); 51 | 52 | var controller = new AddOnController(addOnService); 53 | 54 | var result = controller.Get(1).Result; 55 | 56 | Assert.IsInstanceOfType(result, typeof(NotFoundResult), 57 | "Get should return not found when addon does not exist"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AddOnFilesControllerChangelogTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.Results; 4 | using Curse.RestProxy.Controllers; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Moq; 7 | 8 | namespace Curse.RestProxy.Tests.Controllers 9 | { 10 | [TestClass] 11 | public class AddOnFilesControllerChangelogTests 12 | { 13 | [TestMethod] 14 | public void ChangelogReturnsOkWhenFileFound() 15 | { 16 | var changelog = "changes"; 17 | var addOnService = Mock.Of(s => 18 | s.v2GetChangeLogAsync(1, 2) == Task.FromResult(changelog) 19 | ); 20 | 21 | var controller = new AddOnFilesController(addOnService); 22 | 23 | var result = controller.Changelog(1, 2).Result; 24 | 25 | Assert.IsTrue(result.GetType().FullName.StartsWith("System.Web.Http.Results.OkNegotiatedContentResult"), 26 | "Changelog should return Ok when the file is found"); 27 | } 28 | 29 | [TestMethod] 30 | public void ChangelogReturnsResultFromAddOnService() 31 | { 32 | var changelog = "changes"; 33 | var addOnService = Mock.Of(s => 34 | s.v2GetChangeLogAsync(1, 2) == Task.FromResult(changelog) 35 | ); 36 | 37 | var controller = new AddOnFilesController(addOnService); 38 | 39 | dynamic result = controller.Changelog(1, 2).Result; 40 | 41 | Assert.AreEqual(changelog, result.Content.Changelog, 42 | "Changelog should return result from the addon service"); 43 | } 44 | 45 | [TestMethod] 46 | public void ChangelogReturnsNotFoundWhenFileDoesNotExist() 47 | { 48 | var addOnService = Mock.Of(s => 49 | s.v2GetChangeLogAsync(1, 2) == Task.FromResult((string)null) 50 | ); 51 | 52 | var controller = new AddOnFilesController(addOnService); 53 | 54 | var result = controller.Changelog(1, 2).Result; 55 | 56 | Assert.IsInstanceOfType(result, typeof(NotFoundResult), 57 | "Changelog should return not found when file does not exist"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AddOnFilesControllerGetTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Http.Results; 4 | using Curse.RestProxy.Controllers; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Moq; 7 | 8 | namespace Curse.RestProxy.Tests.Controllers 9 | { 10 | [TestClass] 11 | public class AddOnFilesControllerGetTests 12 | { 13 | [TestMethod] 14 | public void GetReturnsOkWhenFileFound() 15 | { 16 | var file = new AddOnService.AddOnFile(); 17 | var addOnService = Mock.Of(s => 18 | s.GetAddOnFileAsync(1, 2) == Task.FromResult(file) 19 | ); 20 | 21 | var controller = new AddOnFilesController(addOnService); 22 | 23 | var result = controller.Get(1, 2).Result; 24 | 25 | Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult), 26 | "Get should return Ok when the file is found"); 27 | } 28 | 29 | [TestMethod] 30 | public void GetReturnsResultFromAddOnService() 31 | { 32 | var file = new AddOnService.AddOnFile(); 33 | var addOnService = Mock.Of(s => 34 | s.GetAddOnFileAsync(1, 2) == Task.FromResult(file) 35 | ); 36 | 37 | var controller = new AddOnFilesController(addOnService); 38 | 39 | var result = controller.Get(1, 2).Result as OkNegotiatedContentResult; 40 | 41 | Assert.AreEqual(file, result.Content, 42 | "Get should return result from the addon service"); 43 | } 44 | 45 | [TestMethod] 46 | public void GetReturnsNotFoundWhenFileDoesNotExist() 47 | { 48 | var addOnService = Mock.Of(s => 49 | s.GetAddOnFileAsync(1, 2) == Task.FromResult((AddOnService.AddOnFile)null) 50 | ); 51 | 52 | var controller = new AddOnFilesController(addOnService); 53 | 54 | var result = controller.Get(1, 2).Result; 55 | 56 | Assert.IsInstanceOfType(result, typeof(NotFoundResult), 57 | "Get should return not found when file does not exist"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AddOnFilesControllerIndexTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using System.Web.Http.Results; 5 | using Curse.RestProxy.Controllers; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Moq; 8 | 9 | namespace Curse.RestProxy.Tests.Controllers 10 | { 11 | [TestClass] 12 | public class AddOnFilesControllerIndexTests 13 | { 14 | [TestMethod] 15 | public void IndexReturnsOkWhenAddOnFound() 16 | { 17 | var files = new List(); 18 | var addOnService = Mock.Of(s => 19 | s.GetAllFilesForAddOnAsync(1) == Task.FromResult(files) 20 | ); 21 | 22 | var controller = new AddOnFilesController(addOnService); 23 | 24 | var result = controller.Index(1).Result; 25 | 26 | Assert.IsTrue(result.GetType().FullName.StartsWith("System.Web.Http.Results.OkNegotiatedContentResult"), 27 | "Index should return Ok when the addon is found"); 28 | } 29 | 30 | [TestMethod] 31 | public void IndexReturnsResultFromAddOnService() 32 | { 33 | var files = new List(); 34 | var addOnService = Mock.Of(s => 35 | s.GetAllFilesForAddOnAsync(1) == Task.FromResult(files) 36 | ); 37 | 38 | var controller = new AddOnFilesController(addOnService); 39 | 40 | dynamic result = controller.Index(1).Result; 41 | 42 | Assert.AreEqual(files, result.Content.Files, 43 | "Index should return result from the addon service"); 44 | } 45 | 46 | [TestMethod] 47 | public void IndexReturnsNotFoundWhenAddOnDoesNotExist() 48 | { 49 | var addOnService = Mock.Of(s => 50 | s.GetAllFilesForAddOnAsync(1) == Task.FromResult((List)null) 51 | ); 52 | 53 | var controller = new AddOnFilesController(addOnService); 54 | 55 | var result = controller.Index(1).Result; 56 | 57 | Assert.IsInstanceOfType(result, typeof(NotFoundResult), 58 | "Index should return not found when addon does not exist"); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/AuthenticationControllerLoginTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading.Tasks; 4 | using System.Web.Http.Results; 5 | using Curse.RestProxy.Controllers; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Moq; 8 | 9 | namespace Curse.RestProxy.Tests.Controllers 10 | { 11 | [TestClass] 12 | public class AuthenticationControllerAuthenticateTests 13 | { 14 | /* 15 | * Service Integration 16 | */ 17 | [TestMethod] 18 | public void AuthenticateCallsClientLoginService() 19 | { 20 | var clientLoginResponse = new LoginService.LoginResponse() 21 | { 22 | Status = LoginService.AuthenticationStatus.Success 23 | }; 24 | var service = MockClientLoginService(clientLoginResponse); 25 | var controller = new AuthenticationController(service); 26 | 27 | var response = controller.Authenticate(new Models.AuthenticationRequest() 28 | { 29 | Username = "username", 30 | Password = "password" 31 | }).Result; 32 | 33 | Mock.Get(service).Verify(s => 34 | s.LoginAsync(It.Is(lr => 35 | lr.Username == "username" && lr.Password == "password") 36 | ) 37 | ); 38 | } 39 | 40 | /* 41 | * Success 42 | */ 43 | [TestMethod] 44 | public void AuthenticateReturnsOkWhenAuthenticationSucceeds() 45 | { 46 | var clientLoginResponse = new LoginService.LoginResponse() 47 | { 48 | Status = LoginService.AuthenticationStatus.Success 49 | }; 50 | var service = MockClientLoginService(clientLoginResponse); 51 | var controller = new AuthenticationController(service); 52 | 53 | var result = controller.Authenticate(new Models.AuthenticationRequest() 54 | { 55 | Username = "username", 56 | Password = "password" 57 | }).Result; 58 | 59 | Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult), 60 | "Authenticate should return ok when authentication succeeds"); 61 | } 62 | 63 | [TestMethod] 64 | public void AuthenticateBodyContainsClientLoginResponseWhenAuthenticationSucceeds() 65 | { 66 | var clientLoginResponse = new LoginService.LoginResponse() 67 | { 68 | Status = LoginService.AuthenticationStatus.Success 69 | }; 70 | var service = MockClientLoginService(clientLoginResponse); 71 | var controller = new AuthenticationController(service); 72 | 73 | var result = controller.Authenticate(new Models.AuthenticationRequest() 74 | { 75 | Username = "username", 76 | Password = "password" 77 | }).Result as OkNegotiatedContentResult; 78 | 79 | Assert.AreEqual(clientLoginResponse, result.Content, 80 | "Authenticate should return the client login response when authentication succeeds"); 81 | } 82 | 83 | /* 84 | * Authentication fails 85 | */ 86 | [TestMethod] 87 | public void AuthenticateReturnsUnauthorizedWhenAuthenticationFails() 88 | { 89 | var clientLoginResponse = new LoginService.LoginResponse() 90 | { 91 | Status = LoginService.AuthenticationStatus.InvalidPassword 92 | }; 93 | var service = MockClientLoginService(clientLoginResponse); 94 | var controller = new AuthenticationController(service); 95 | 96 | var result = controller.Authenticate(new Models.AuthenticationRequest() 97 | { 98 | Username = "username", 99 | Password = "password" 100 | }).Result; 101 | 102 | Assert.IsInstanceOfType(result, typeof(UnauthorizedResult), 103 | "Authenticate should return unauthorized when authentication fails"); 104 | } 105 | 106 | /* 107 | * Input Validation 108 | */ 109 | [TestMethod] 110 | public void AuthenticateReturnsBadRequestWhenAuthenticationRequestNull() 111 | { 112 | var clientLoginResponse = new LoginService.LoginResponse() 113 | { 114 | Status = LoginService.AuthenticationStatus.InvalidPassword 115 | }; 116 | var service = MockClientLoginService(clientLoginResponse); 117 | var controller = new AuthenticationController(service); 118 | 119 | var result = controller.Authenticate(null).Result; 120 | 121 | Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult), 122 | "Authenticate should return bad request when the authentication request is null"); 123 | } 124 | 125 | [TestMethod] 126 | public void AuthenticateReturnsBadRequestWhenUserNameNull() 127 | { 128 | var clientLoginResponse = new LoginService.LoginResponse() 129 | { 130 | Status = LoginService.AuthenticationStatus.InvalidPassword 131 | }; 132 | var service = MockClientLoginService(clientLoginResponse); 133 | var controller = new AuthenticationController(service); 134 | 135 | var result = controller.Authenticate(new Models.AuthenticationRequest() 136 | { 137 | Username = null, 138 | Password = "password" 139 | }).Result; 140 | 141 | Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult), 142 | "Authenticate should return bad request when the username is null"); 143 | } 144 | 145 | [TestMethod] 146 | public void AuthenticateReturnsBadRequestWhenPasswordNull() 147 | { 148 | var clientLoginResponse = new LoginService.LoginResponse() 149 | { 150 | Status = LoginService.AuthenticationStatus.InvalidPassword 151 | }; 152 | var service = MockClientLoginService(clientLoginResponse); 153 | var controller = new AuthenticationController(service); 154 | 155 | var result = controller.Authenticate(new Models.AuthenticationRequest() 156 | { 157 | Username = "username", 158 | Password = null 159 | }).Result; 160 | 161 | Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult), 162 | "Authenticate should return bad request when the password is null"); 163 | } 164 | 165 | private LoginService.IClientLoginService MockClientLoginService(LoginService.LoginResponse response) 166 | { 167 | return Mock.Of(l => 168 | l.LoginAsync(It.IsAny()) == 169 | Task.FromResult(response) 170 | ); 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/IndexControllerIndexTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http.Results; 3 | using Curse.RestProxy.Controllers; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Moq; 6 | 7 | namespace Curse.RestProxy.Tests.Controllers 8 | { 9 | [TestClass] 10 | public class IndexControllerIndexTests 11 | { 12 | [TestMethod] 13 | public void IndexReturnsOk() 14 | { 15 | var controller = new IndexController(Mock.Of(), 16 | Mock.Of()); 17 | 18 | var result = controller.Index(); 19 | 20 | Assert.IsTrue(result.GetType().FullName.StartsWith("System.Web.Http.Results.OkNegotiatedContentResult"), 21 | "Index should return Ok"); 22 | } 23 | 24 | [TestMethod] 25 | public void IndexReturnsCorrectResult() 26 | { 27 | var controller = new IndexController(Mock.Of(), 28 | Mock.Of()); 29 | 30 | dynamic result = controller.Index(); 31 | 32 | Assert.IsNotNull(result.Content, 33 | "The content should not be null"); 34 | Assert.IsNotNull(result.Content.Website, 35 | "The website link should not be null"); 36 | Assert.AreEqual("http://github.com/amiller/Curse.RestProxy", result.Content.Website, 37 | "The website link should point to the correct location"); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Controllers/IndexControllerStatusTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ServiceModel; 3 | using System.Threading.Tasks; 4 | using Curse.RestProxy.Controllers; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Moq; 7 | 8 | namespace Curse.RestProxy.Tests.Controllers 9 | { 10 | [TestClass] 11 | public class IndexControllerStatusTests 12 | { 13 | [TestMethod] 14 | public void StatusReturnsOk() 15 | { 16 | var controller = new IndexController(Mock.Of(), 17 | Mock.Of()); 18 | 19 | var result = controller.Status().Result; 20 | 21 | Assert.IsTrue(result.GetType().FullName.StartsWith("System.Web.Http.Results.OkNegotiatedContentResult"), 22 | "Index should return Ok"); 23 | } 24 | 25 | [TestMethod] 26 | public void StatusReturnsCorrectContent() 27 | { 28 | var loginService = Mock.Of(s => 29 | s.CheckUsernameAvailabilityAsync(It.IsAny()) == 30 | Task.FromResult(true) 31 | ); 32 | var addOnService = Mock.Of(s => 33 | s.HealthCheckAsync() == Task.FromResult("Success") 34 | ); 35 | var controller = new IndexController(loginService, addOnService); 36 | 37 | dynamic result = controller.Status().Result; 38 | dynamic content = result.Content; 39 | 40 | Assert.AreEqual("Ok", content.CurseRestProxy, 41 | "Status should return Ok for CurseRestPRoxy"); 42 | Assert.AreEqual("Ok", content.LoginService, 43 | "Status should return Ok for the login service"); 44 | Assert.AreEqual("Ok", content.AddOnService, 45 | "Status should return Ok for addon service"); 46 | } 47 | 48 | [TestMethod] 49 | public void StatusReturnsDownWhenLoginServiceUnreachable() 50 | { 51 | var loginService = Mock.Of(); 52 | var addOnService = Mock.Of(s => 53 | s.HealthCheckAsync() == Task.FromResult("Success") 54 | ); 55 | var controller = new IndexController(loginService, addOnService); 56 | 57 | Mock.Get(loginService). 58 | Setup(s => s.CheckUsernameAvailabilityAsync(It.IsAny())). 59 | Throws(); 60 | 61 | dynamic result = controller.Status().Result; 62 | dynamic content = result.Content; 63 | 64 | Assert.AreEqual("Down", content.LoginService, 65 | "Status should return Down for the login service when it is unreachable"); 66 | } 67 | 68 | [TestMethod] 69 | public void StatusReturnsErrorWhenLoginServiceThrowsFault() 70 | { 71 | var loginService = Mock.Of(); 72 | var addOnService = Mock.Of(s => 73 | s.HealthCheckAsync() == Task.FromResult("Success") 74 | ); 75 | var controller = new IndexController(loginService, addOnService); 76 | 77 | Mock.Get(loginService). 78 | Setup(s => s.CheckUsernameAvailabilityAsync(It.IsAny())). 79 | Throws(); 80 | 81 | dynamic result = controller.Status().Result; 82 | dynamic content = result.Content; 83 | 84 | Assert.AreEqual("Error", content.LoginService, 85 | "Status should return Error for the login service when it throws a fault"); 86 | } 87 | 88 | [TestMethod] 89 | public void StatusReturnsDownWhenAddOnServiceUnreachable() 90 | { 91 | var loginService = Mock.Of(s => 92 | s.CheckUsernameAvailabilityAsync(It.IsAny()) == 93 | Task.FromResult(true) 94 | ); 95 | var addOnService = Mock.Of(); 96 | var controller = new IndexController(loginService, addOnService); 97 | 98 | Mock.Get(addOnService). 99 | Setup(s => s.HealthCheckAsync()). 100 | Throws(); 101 | 102 | dynamic result = controller.Status().Result; 103 | dynamic content = result.Content; 104 | 105 | Assert.AreEqual("Down", content.AddOnService, 106 | "Status should return Down for the add on service when it is unreachable"); 107 | } 108 | 109 | [TestMethod] 110 | public void StatusReturnsErrorWhenAddOnServiceThrowsFault() 111 | { 112 | var loginService = Mock.Of(s => 113 | s.CheckUsernameAvailabilityAsync(It.IsAny()) == 114 | Task.FromResult(true) 115 | ); 116 | var addOnService = Mock.Of(); 117 | var controller = new IndexController(loginService, addOnService); 118 | 119 | Mock.Get(addOnService). 120 | Setup(s => s.HealthCheckAsync()). 121 | Throws(); 122 | 123 | dynamic result = controller.Status().Result; 124 | dynamic content = result.Content; 125 | 126 | Assert.AreEqual("Error", content.AddOnService, 127 | "Status should return Error for the add on service when it throws a fault"); 128 | } 129 | 130 | [TestMethod] 131 | public void StatusReturnsResultWhenAddOnServiceNotSuccess() 132 | { 133 | var loginService = Mock.Of(s => 134 | s.CheckUsernameAvailabilityAsync(It.IsAny()) == 135 | Task.FromResult(true) 136 | ); 137 | var addOnService = Mock.Of(s => 138 | s.HealthCheckAsync() == Task.FromResult("SomeError") 139 | ); 140 | var controller = new IndexController(loginService, addOnService); 141 | 142 | dynamic result = controller.Status().Result; 143 | dynamic content = result.Content; 144 | 145 | Assert.AreEqual("SomeError", content.AddOnService, 146 | "Status should return result for the add on service when it is not success"); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Curse.RestProxy.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {0D57E306-436A-4C3C-9567-B4CC5D606941} 7 | Library 8 | Properties 9 | Curse.RestProxy.Tests 10 | Curse.RestProxy.Tests 11 | v4.5.2 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | False 15 | UnitTest 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | False 38 | 39 | 40 | ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll 41 | True 42 | 43 | 44 | ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | {149C13E4-4ACB-4088-951F-7096D8994BE4} 78 | Curse.RestProxy 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Curse.RestProxy.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Curse.RestProxy.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0d57e306-436a-4c3c-9567-b4cc5d606941")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/Serialization/SnakeCasePropertyNamesContractResolverTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Curse.RestProxy.Serialization; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Curse.RestProxy.Tests.Serialization 6 | { 7 | [TestClass] 8 | public class SnakeCasePropertyNamesContractResolverTests 9 | { 10 | private IDictionary TestCases = new Dictionary 11 | { 12 | { "already_snake", "already_snake" }, 13 | { "ALLUPPER", "allupper" }, 14 | { "alllower", "alllower" }, 15 | { "PascalCase", "pascal_case" }, 16 | { "camelCase", "camel_case" }, 17 | { "ACRONYMName", "acronym_name" }, 18 | { "SomeACRONYM", "some_acronym" } 19 | }; 20 | 21 | [TestMethod] 22 | public void ResolvesCorrectSnakeCaseNames() 23 | { 24 | var resolver = new SnakeCasePropertyNamesContractResolver(); 25 | 26 | foreach(var kvp in TestCases) 27 | { 28 | var result = resolver.GetResolvedPropertyName(kvp.Key); 29 | Assert.AreEqual(kvp.Value, result, 30 | "{0} should resolve to {1}", kvp.Key, kvp.Value); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Curse.RestProxy.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Curse.RestProxy.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Curse.RestProxy", "Curse.RestProxy\Curse.RestProxy.csproj", "{149C13E4-4ACB-4088-951F-7096D8994BE4}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Curse.RestProxy.Tests", "Curse.RestProxy.Tests\Curse.RestProxy.Tests.csproj", "{0D57E306-436A-4C3C-9567-B4CC5D606941}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F398A4D6-362E-49E9-94E7-DD21D01A64B2}" 11 | ProjectSection(SolutionItems) = preProject 12 | .gitattributes = .gitattributes 13 | .gitignore = .gitignore 14 | LICENSE = LICENSE 15 | README.md = README.md 16 | EndProjectSection 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {149C13E4-4ACB-4088-951F-7096D8994BE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {149C13E4-4ACB-4088-951F-7096D8994BE4}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {149C13E4-4ACB-4088-951F-7096D8994BE4}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {149C13E4-4ACB-4088-951F-7096D8994BE4}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {0D57E306-436A-4C3C-9567-B4CC5D606941}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {0D57E306-436A-4C3C-9567-B4CC5D606941}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {0D57E306-436A-4C3C-9567-B4CC5D606941}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {0D57E306-436A-4C3C-9567-B4CC5D606941}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /Curse.RestProxy/AddOnService/TokenEndpointBehavior.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | using System.ServiceModel; 3 | using System.ServiceModel.Channels; 4 | using System.ServiceModel.Description; 5 | using System.ServiceModel.Dispatcher; 6 | using Curse.RestProxy.Authentication; 7 | 8 | namespace Curse.RestProxy.AddOnService 9 | { 10 | public class TokenEndpointBehavior: IEndpointBehavior, IClientMessageInspector 11 | { 12 | private AuthenticationToken Token { get; set; } 13 | 14 | public TokenEndpointBehavior(TokenIdentity identity) 15 | { 16 | Token = new AuthenticationToken() 17 | { 18 | Token = identity.Token, 19 | UserID = identity.UserId 20 | }; 21 | } 22 | 23 | public object BeforeSendRequest(ref Message request, IClientChannel channel) 24 | { 25 | var header = MessageHeader.CreateHeader("AuthenticationToken", "urn:Curse.FriendsService:v1", Token); 26 | request.Headers.Add(header); 27 | return null; 28 | } 29 | 30 | public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) 31 | { 32 | clientRuntime.MessageInspectors.Add(this); 33 | } 34 | 35 | public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) 36 | { 37 | } 38 | 39 | public void AfterReceiveReply(ref Message reply, object correlationState) 40 | { 41 | } 42 | 43 | public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) 44 | { 45 | } 46 | 47 | public void Validate(ServiceEndpoint endpoint) 48 | { 49 | } 50 | 51 | [DataContract(Namespace = "urn:Curse.FriendsService:v1")] 52 | private class AuthenticationToken 53 | { 54 | [DataMember] 55 | public int UserID { get; set; } 56 | 57 | [DataMember] 58 | public string Token { get; set; } 59 | 60 | [DataMember] 61 | public string ApiKey { get; set; } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /Curse.RestProxy/App_Start/DependencyContainerConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http; 3 | using Microsoft.Practices.Unity; 4 | using Microsoft.Practices.Unity.WebApi; 5 | 6 | namespace Curse.RestProxy 7 | { 8 | /// 9 | /// Specifies the Unity configuration for the main container. 10 | /// 11 | public static class DependencyContainerConfig 12 | { 13 | /// Configure the dependency container 14 | public static void Configure(HttpConfiguration config) 15 | { 16 | var container = new UnityContainer(); 17 | RegisterTypes(container); 18 | 19 | config.DependencyResolver = new UnityHierarchicalDependencyResolver(container); 20 | } 21 | 22 | /// Registers the type mappings with the Unity container. 23 | /// The unity container to configure. 24 | /// There is no need to register concrete types such as controllers or API controllers (unless you want to 25 | /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered. 26 | public static void RegisterTypes(IUnityContainer container) 27 | { 28 | container.RegisterType( 29 | new HierarchicalLifetimeManager(), 30 | new InjectionConstructor("BinaryHttpsClientLoginServiceEndpoint")); 31 | 32 | container.RegisterType( 33 | new HierarchicalLifetimeManager(), 34 | new InjectionConstructor("BinaryHttpsAddOnServiceEndpoint")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Curse.RestProxy/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using Curse.RestProxy.Authentication; 3 | using Curse.RestProxy.Serialization; 4 | using Newtonsoft.Json.Converters; 5 | 6 | namespace Curse.RestProxy 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Configure routes 13 | config.MapHttpAttributeRoutes(); 14 | 15 | // Configure json formatting 16 | var jsonFormatter = config.Formatters.JsonFormatter; 17 | jsonFormatter.SerializerSettings.ContractResolver = new SnakeCasePropertyNamesContractResolver(); 18 | jsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter()); 19 | config.Formatters.Clear(); 20 | config.Formatters.Add(jsonFormatter); 21 | 22 | // Configure authentication and authorization 23 | config.Filters.Add(new TokenAuthenticationFilter()); 24 | config.Filters.Add(new AuthorizeAttribute()); 25 | config.Filters.Add(new SetCurseTokenActionFilter()); 26 | config.Filters.Add(new CurseFailedAuthenticationExceptionFilter()); 27 | 28 | // Configure dependency injection 29 | DependencyContainerConfig.Configure(config); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Curse.RestProxy/ApplicationInsights.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | -------------------------------------------------------------------------------- /Curse.RestProxy/Authentication/CurseFailedAuthenticationExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.Http; 3 | using System.ServiceModel; 4 | using System.Web.Http.Filters; 5 | using Curse.RestProxy.Http; 6 | 7 | namespace Curse.RestProxy.Authentication 8 | { 9 | /// 10 | /// Handles a FaultCode of "FailedAuthentication" from the Curse WCF services by returning 11 | /// a 401 Unauthorized response. 12 | /// 13 | public class CurseFailedAuthenticationExceptionFilter: ExceptionFilterAttribute 14 | { 15 | public override void OnException(HttpActionExecutedContext context) 16 | { 17 | var faultException = context.Exception as FaultException; 18 | if(faultException == null || faultException.Code.Name != "FailedAuthentication") 19 | return; 20 | 21 | context.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); 22 | context.Response.AddWwwAuthenticateTokenHeader(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Authentication/SetCurseTokenActionFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Web; 6 | using System.Web.Http; 7 | using System.Web.Http.Controllers; 8 | using System.Web.Http.Filters; 9 | using Curse.RestProxy.AddOnService; 10 | 11 | namespace Curse.RestProxy.Authentication 12 | { 13 | /// 14 | /// Sets the token for the Curse WCF services to the authentication token from the 15 | /// authorization header. 16 | /// 17 | public class SetCurseTokenActionFilter: ActionFilterAttribute 18 | { 19 | public override void OnActionExecuting(HttpActionContext actionContext) 20 | { 21 | base.OnActionExecuting(actionContext); 22 | 23 | var identity = actionContext.RequestContext.Principal.Identity as TokenIdentity; 24 | 25 | if(identity == null) 26 | return; 27 | 28 | var dependencyResolver = actionContext.Request.GetDependencyScope(); 29 | var addOnService = dependencyResolver.GetService(typeof(IAddOnService)) as AddOnServiceClient; 30 | 31 | addOnService.ChannelFactory.Endpoint.Behaviors.Add(new TokenEndpointBehavior(identity)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Authentication/TokenAuthenticationFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Net.Http.Headers; 4 | using System.Security.Principal; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using System.Web.Http.Filters; 8 | using System.Web.Http.Results; 9 | using Curse.RestProxy.Http; 10 | 11 | namespace Curse.RestProxy.Authentication 12 | { 13 | /// 14 | /// Provides authentication based on a token in the Authorization header 15 | /// 16 | public class TokenAuthenticationFilter: IAuthenticationFilter 17 | { 18 | public bool AllowMultiple 19 | { 20 | get 21 | { 22 | return false; 23 | } 24 | } 25 | 26 | public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) 27 | { 28 | return Task.Run(() => 29 | { 30 | HttpRequestMessage request = context.Request; 31 | AuthenticationHeaderValue authorization = request.Headers.Authorization; 32 | 33 | if(authorization == null) 34 | return; 35 | 36 | if(authorization.Scheme != "Token") 37 | return; 38 | 39 | int userId; 40 | string token; 41 | if(!TryParseAuthorizationParameter(authorization.Parameter, out userId, out token)) 42 | { 43 | context.ErrorResult = new StatusCodeResult(System.Net.HttpStatusCode.Unauthorized, request); 44 | return; 45 | } 46 | 47 | context.Principal = new GenericPrincipal(new TokenIdentity(userId, token), new[] { "User" }); 48 | 49 | return; 50 | }); 51 | } 52 | 53 | public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) 54 | { 55 | context.Result = context.Result.With(response => 56 | { 57 | if(response.StatusCode == System.Net.HttpStatusCode.Unauthorized) 58 | response.AddWwwAuthenticateTokenHeader(); 59 | }); 60 | return Task.FromResult(0); 61 | } 62 | 63 | /// 64 | /// Try to parse an authorization header parameter of the form "userid:token". 65 | /// userid must be an integer 66 | /// token must be non-empty string 67 | /// 68 | private static bool TryParseAuthorizationParameter(string authParam, out int userId, out string token) 69 | { 70 | userId = 0; 71 | token = null; 72 | 73 | if(String.IsNullOrEmpty(authParam)) 74 | return false; 75 | 76 | var parts = authParam.Split(':'); 77 | if(parts.Length != 2) 78 | return false; 79 | 80 | if(!int.TryParse(parts[0], out userId)) 81 | return false; 82 | 83 | token = parts[1]; 84 | if(String.IsNullOrEmpty(token)) 85 | return false; 86 | 87 | return true; 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Authentication/TokenIdentity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Principal; 3 | 4 | namespace Curse.RestProxy.Authentication 5 | { 6 | /// 7 | /// Provides an identity based on an access token 8 | /// 9 | public class TokenIdentity: IIdentity 10 | { 11 | public int UserId { get; private set; } 12 | public string Token { get; private set; } 13 | 14 | public TokenIdentity(int userId, string token) 15 | { 16 | if(token == null) 17 | throw new ArgumentNullException("token"); 18 | 19 | UserId = userId; 20 | Token = token; 21 | } 22 | 23 | public string AuthenticationType 24 | { 25 | get 26 | { 27 | return "Token"; 28 | } 29 | } 30 | 31 | public bool IsAuthenticated 32 | { 33 | get 34 | { 35 | return true; 36 | } 37 | } 38 | 39 | public string Name 40 | { 41 | get 42 | { 43 | return UserId.ToString(); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Controllers/AddOnController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using System.Web.Http; 3 | 4 | namespace Curse.RestProxy.Controllers 5 | { 6 | [RoutePrefix("api/addon")] 7 | public class AddOnController : ApiController 8 | { 9 | private AddOnService.IAddOnService AddOnService { get; set; } 10 | 11 | public AddOnController(AddOnService.IAddOnService addOnService) 12 | { 13 | AddOnService = addOnService; 14 | } 15 | 16 | [HttpGet] 17 | [Route("{id}", Name = "AddOn")] 18 | public async Task Get(int id) 19 | { 20 | var result = await AddOnService.GetAddOnAsync(id); 21 | 22 | if(result == null) 23 | return NotFound(); 24 | 25 | return Ok(result); 26 | } 27 | 28 | [HttpGet] 29 | [Route("{id}/description", Name = "AddOnDescription")] 30 | public async Task Description(int id) 31 | { 32 | var result = await AddOnService.v2GetAddOnDescriptionAsync(id); 33 | 34 | if(result == null) 35 | return NotFound(); 36 | 37 | return Ok(new 38 | { 39 | Description = result 40 | }); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Curse.RestProxy/Controllers/AddOnFilesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Web; 6 | using System.Web.Http; 7 | 8 | namespace Curse.RestProxy.Controllers 9 | { 10 | [RoutePrefix("api/addon/{addonId}")] 11 | public class AddOnFilesController: ApiController 12 | { 13 | private AddOnService.IAddOnService AddOnService { get; set; } 14 | 15 | public AddOnFilesController(AddOnService.IAddOnService addOnService) 16 | { 17 | AddOnService = addOnService; 18 | } 19 | 20 | [HttpGet] 21 | [Route("files", Name = "AddOnFiles")] 22 | public async Task Index(int addonId) 23 | { 24 | var result = await AddOnService.GetAllFilesForAddOnAsync(addonId); 25 | 26 | if(result == null) 27 | return NotFound(); 28 | 29 | return Ok(new 30 | { 31 | Files = result 32 | }); 33 | } 34 | 35 | [HttpGet] 36 | [Route("file/{fileId}", Name = "AddOnFile")] 37 | public async Task Get(int addonId, int fileId) 38 | { 39 | var result = await AddOnService.GetAddOnFileAsync(addonId, fileId); 40 | 41 | if(result == null) 42 | return NotFound(); 43 | 44 | return Ok(result); 45 | } 46 | 47 | [HttpGet] 48 | [Route("file/{fileId}/changelog", Name = "AddOnFileChangelog")] 49 | public async Task Changelog(int addonId, int fileId) 50 | { 51 | var result = await AddOnService.v2GetChangeLogAsync(addonId, fileId); 52 | 53 | if(result == null) 54 | return NotFound(); 55 | 56 | return Ok(new 57 | { 58 | Changelog = result 59 | }); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Controllers/AuthenticationController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using System.Web.Http; 3 | using Curse.RestProxy.Models; 4 | 5 | namespace Curse.RestProxy.Controllers 6 | { 7 | [AllowAnonymous] 8 | [RoutePrefix("api")] 9 | public class AuthenticationController : ApiController 10 | { 11 | private LoginService.IClientLoginService ClientLoginService { get; set; } 12 | 13 | public AuthenticationController(LoginService.IClientLoginService clientLoginService) 14 | { 15 | ClientLoginService = clientLoginService; 16 | } 17 | 18 | [HttpPost] 19 | [Route("authenticate", Name = "Authenticate")] 20 | public async Task Authenticate(AuthenticationRequest request) 21 | { 22 | if(request == null || string.IsNullOrEmpty(request.Username) || string.IsNullOrEmpty(request.Password)) 23 | return BadRequest("Username and password are required"); 24 | 25 | var result = await ClientLoginService.LoginAsync(new LoginService.LoginRequest() 26 | { 27 | Username = request.Username, 28 | Password = request.Password 29 | }); 30 | 31 | if(result.Status != LoginService.AuthenticationStatus.Success) 32 | return Unauthorized(); 33 | 34 | return Ok(result); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Curse.RestProxy/Controllers/IndexController.cs: -------------------------------------------------------------------------------- 1 | using System.ServiceModel; 2 | using System.Threading.Tasks; 3 | using System.Web.Http; 4 | 5 | namespace Curse.RestProxy.Controllers 6 | { 7 | [AllowAnonymous] 8 | [RoutePrefix("api")] 9 | public class IndexController : ApiController 10 | { 11 | private LoginService.IClientLoginService ClientLoginService { get; set; } 12 | private AddOnService.IAddOnService AddOnService { get; set; } 13 | 14 | public IndexController(LoginService.IClientLoginService clientLoginService, 15 | AddOnService.IAddOnService addOnService) 16 | { 17 | ClientLoginService = clientLoginService; 18 | AddOnService = addOnService; 19 | } 20 | 21 | [HttpGet] 22 | [Route("", Name = "Index")] 23 | public IHttpActionResult Index() 24 | { 25 | return Ok(new { Website = "http://github.com/amiller/Curse.RestProxy" }); 26 | } 27 | 28 | [HttpGet] 29 | [Route("status", Name = "Status")] 30 | public async Task Status() 31 | { 32 | return Ok(new 33 | { 34 | CurseRestProxy = "Ok", 35 | LoginService = await GetClientLoginServiceStatus(), 36 | AddOnService = await GetAddOnServiceStatus() 37 | }); 38 | } 39 | 40 | private async Task GetClientLoginServiceStatus() 41 | { 42 | try 43 | { 44 | var result = await ClientLoginService.CheckUsernameAvailabilityAsync(null); 45 | return "Ok"; 46 | } 47 | catch(EndpointNotFoundException) 48 | { 49 | return "Down"; 50 | } 51 | catch(FaultException) 52 | { 53 | return "Error"; 54 | } 55 | } 56 | 57 | private async Task GetAddOnServiceStatus() 58 | { 59 | try 60 | { 61 | var result = await AddOnService.HealthCheckAsync(); 62 | 63 | if(result == "Success") 64 | return "Ok"; 65 | 66 | return result; 67 | } 68 | catch(EndpointNotFoundException) 69 | { 70 | return "Down"; 71 | } 72 | catch(FaultException) 73 | { 74 | return "Error"; 75 | } 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Curse.RestProxy/Curse.RestProxy.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 10 | 11 | 2.0 12 | {149C13E4-4ACB-4088-951F-7096D8994BE4} 13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 14 | Library 15 | Properties 16 | Curse.RestProxy 17 | Curse.RestProxy 18 | v4.5.2 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | true 37 | 38 | 39 | pdbonly 40 | true 41 | bin\ 42 | TRACE 43 | prompt 44 | 4 45 | 46 | 47 | 48 | ..\packages\Microsoft.ApplicationInsights.Agent.Intercept.1.2.1\lib\net45\Microsoft.AI.Agent.Intercept.dll 49 | True 50 | 51 | 52 | ..\packages\Microsoft.ApplicationInsights.DependencyCollector.1.2.3\lib\net45\Microsoft.AI.DependencyCollector.dll 53 | True 54 | 55 | 56 | ..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.1.2.3\lib\net45\Microsoft.AI.PerfCounterCollector.dll 57 | True 58 | 59 | 60 | ..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.1.2.3\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll 61 | True 62 | 63 | 64 | ..\packages\Microsoft.ApplicationInsights.Web.1.2.3\lib\net45\Microsoft.AI.Web.dll 65 | True 66 | 67 | 68 | ..\packages\Microsoft.ApplicationInsights.WindowsServer.1.2.3\lib\net45\Microsoft.AI.WindowsServer.dll 69 | True 70 | 71 | 72 | ..\packages\Microsoft.ApplicationInsights.1.2.3\lib\net45\Microsoft.ApplicationInsights.dll 73 | True 74 | 75 | 76 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 77 | True 78 | 79 | 80 | 81 | ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll 82 | True 83 | 84 | 85 | ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll 86 | True 87 | 88 | 89 | ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll 90 | True 91 | 92 | 93 | ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll 94 | True 95 | 96 | 97 | ..\packages\Unity.AspNet.WebApi.4.0.1\lib\net45\Microsoft.Practices.Unity.WebApi.dll 98 | True 99 | 100 | 101 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 102 | True 103 | 104 | 105 | ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll 106 | True 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | ..\packages\WebActivatorEx.2.1.0\lib\net40\WebActivatorEx.dll 129 | True 130 | 131 | 132 | 133 | 134 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 135 | 136 | 137 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll 138 | 139 | 140 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll 141 | 142 | 143 | 144 | 145 | 146 | PreserveNewest 147 | 148 | 149 | 150 | 151 | Designer 152 | 153 | 154 | 155 | Designer 156 | 157 | 158 | Designer 159 | 160 | 161 | Designer 162 | 163 | 164 | Designer 165 | 166 | 167 | Designer 168 | 169 | 170 | Designer 171 | 172 | 173 | Reference.svcmap 174 | 175 | 176 | Reference.svcmap 177 | 178 | 179 | Reference.svcmap 180 | 181 | 182 | Reference.svcmap 183 | 184 | 185 | Reference.svcmap 186 | 187 | 188 | Reference.svcmap 189 | 190 | 191 | Reference.svcmap 192 | 193 | 194 | Reference.svcmap 195 | 196 | 197 | Reference.svcmap 198 | 199 | 200 | Reference.svcmap 201 | 202 | 203 | Reference.svcmap 204 | 205 | 206 | Reference.svcmap 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | WCF Proxy Generator 216 | Reference.cs 217 | 218 | 219 | Reference.svcmap 220 | 221 | 222 | Reference.svcmap 223 | 224 | 225 | WCF Proxy Generator 226 | Reference.cs 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | Global.asax 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | True 252 | True 253 | Reference.svcmap 254 | 255 | 256 | True 257 | True 258 | Reference.svcmap 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | Designer 267 | 268 | 269 | 270 | Designer 271 | 272 | 273 | Designer 274 | 275 | 276 | Web.config 277 | 278 | 279 | Web.config 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 10.0 294 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | True 304 | 305 | 306 | 307 | 308 | 309 | 310 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 311 | 312 | 313 | 314 | 315 | 322 | -------------------------------------------------------------------------------- /Curse.RestProxy/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Curse.RestProxy.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Curse.RestProxy/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using System.Web.Http; 3 | using Microsoft.ApplicationInsights.Extensibility; 4 | 5 | namespace Curse.RestProxy 6 | { 7 | public class WebApiApplication : System.Web.HttpApplication 8 | { 9 | protected void Application_Start() 10 | { 11 | var insightsKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]; 12 | if(!string.IsNullOrEmpty(insightsKey)) 13 | TelemetryConfiguration.Active.InstrumentationKey = insightsKey; 14 | 15 | GlobalConfiguration.Configure(WebApiConfig.Register); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Http/HttpResponseMessageExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Net.Http; 3 | using System.Net.Http.Headers; 4 | 5 | namespace Curse.RestProxy.Http 6 | { 7 | public static class HttpResponseMessageExtensions 8 | { 9 | public static void AddWwwAuthenticateTokenHeader(this HttpResponseMessage response) 10 | { 11 | if(!response.HasWwwAuthenticateTokenHeader()) 12 | response.Headers.WwwAuthenticate.Add(new AuthenticationHeaderValue("Token", "realm=\"api\"")); 13 | } 14 | 15 | public static bool HasWwwAuthenticateTokenHeader(this HttpResponseMessage response) 16 | { 17 | return response.Headers.WwwAuthenticate.Any(h => h.Scheme == "Token"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Http/IHttpActionResultExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Web.Http; 4 | 5 | namespace Curse.RestProxy.Http 6 | { 7 | public static class IHttpActionResultExtensions 8 | { 9 | /// 10 | /// Perform additional processing after the action result is executed 11 | /// 12 | public static IHttpActionResult With(this IHttpActionResult result, Action action) 13 | { 14 | return new WrappedActionResult(result, action); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Http/WrappedActionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using System.Web.Http; 6 | 7 | namespace Curse.RestProxy.Http 8 | { 9 | /// 10 | /// Wraps an action result and executes the specified action after executing the result. 11 | /// 12 | public class WrappedActionResult: IHttpActionResult 13 | { 14 | private IHttpActionResult InnerResult { get; set; } 15 | private Action Action { get; set; } 16 | 17 | public WrappedActionResult(IHttpActionResult innerResult, Action action) 18 | { 19 | InnerResult = innerResult; 20 | Action = action; 21 | } 22 | 23 | public async Task ExecuteAsync(CancellationToken cancellationToken) 24 | { 25 | var response = await InnerResult.ExecuteAsync(cancellationToken); 26 | 27 | if(Action != null) 28 | Action(response); 29 | 30 | return response; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Models/AuthenticationRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Curse.RestProxy.Models 2 | { 3 | public class AuthenticationRequest 4 | { 5 | public string Username { get; set; } 6 | public string Password { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Curse.RestProxy")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Curse.RestProxy")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("149c13e4-4acb-4088-951f-7096d8994be4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | 37 | [assembly: InternalsVisibleTo("Curse.RestProxy.Tests")] -------------------------------------------------------------------------------- /Curse.RestProxy/Properties/PublishProfiles/curse-rest-proxy.pubxml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | MSDeploy 9 | False 10 | Release 11 | Any CPU 12 | http://curse-rest-proxy.azurewebsites.net 13 | True 14 | True 15 | curse-rest-proxy.scm.azurewebsites.net:443 16 | curse-rest-proxy 17 | 18 | False 19 | WMSVC 20 | True 21 | $curse-rest-proxy 22 | <_SavePWD>True 23 | <_DestinationType>AzureWebSite 24 | 25 | -------------------------------------------------------------------------------- /Curse.RestProxy/Serialization/SnakeCasePropertyNamesContractResolver.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | using Newtonsoft.Json.Serialization; 3 | 4 | namespace Curse.RestProxy.Serialization 5 | { 6 | public class SnakeCasePropertyNamesContractResolver: DefaultContractResolver 7 | { 8 | private Regex upperLowerRegex = new Regex("([A-Z]+)([A-Z][a-z])", RegexOptions.Compiled); 9 | private Regex lowerUpperRegex = new Regex("([a-z])([A-Z])", RegexOptions.Compiled); 10 | 11 | protected override string ResolvePropertyName(string propertyName) 12 | { 13 | propertyName = upperLowerRegex.Replace(propertyName, "$1_$2"); 14 | propertyName = lowerUpperRegex.Replace(propertyName, "$1_$2"); 15 | 16 | return propertyName.ToLower(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService.disco: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService1.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 1 12 | 13 | 14 | 15 | 16 | 17 | 18 | 2 19 | 20 | 21 | 22 | 23 | 24 | 25 | 3 26 | 27 | 28 | 29 | 30 | 31 | 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 5 40 | 41 | 42 | 43 | 44 | 45 | 46 | 6 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 1 74 | 75 | 76 | 77 | 78 | 79 | 80 | 2 81 | 82 | 83 | 84 | 85 | 86 | 87 | 3 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 1 100 | 101 | 102 | 103 | 104 | 105 | 106 | 2 107 | 108 | 109 | 110 | 111 | 112 | 113 | 3 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 1 126 | 127 | 128 | 129 | 130 | 131 | 132 | 2 133 | 134 | 135 | 136 | 137 | 138 | 139 | 3 140 | 141 | 142 | 143 | 144 | 145 | 146 | 4 147 | 148 | 149 | 150 | 151 | 152 | 153 | 5 154 | 155 | 156 | 157 | 158 | 159 | 160 | 6 161 | 162 | 163 | 164 | 165 | 166 | 167 | 7 168 | 169 | 170 | 171 | 172 | 173 | 174 | 8 175 | 176 | 177 | 178 | 179 | 180 | 181 | 9 182 | 183 | 184 | 185 | 186 | 187 | 188 | 10 189 | 190 | 191 | 192 | 193 | 194 | 195 | 11 196 | 197 | 198 | 199 | 200 | 201 | 202 | 12 203 | 204 | 205 | 206 | 207 | 208 | 209 | 13 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 1 222 | 223 | 224 | 225 | 226 | 227 | 228 | 2 229 | 230 | 231 | 232 | 233 | 234 | 235 | 3 236 | 237 | 238 | 239 | 240 | 241 | 242 | 4 243 | 244 | 245 | 246 | 247 | 248 | 249 | 5 250 | 251 | 252 | 253 | 254 | 255 | 256 | 6 257 | 258 | 259 | 260 | 261 | 262 | 263 | 7 264 | 265 | 266 | 267 | 268 | 269 | 270 | 8 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 1 283 | 284 | 285 | 286 | 287 | 288 | 289 | 2 290 | 291 | 292 | 293 | 294 | 295 | 296 | 3 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService2.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService3.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 1 25 | 26 | 27 | 28 | 29 | 30 | 31 | 2 32 | 33 | 34 | 35 | 36 | 37 | 38 | 3 39 | 40 | 41 | 42 | 43 | 44 | 45 | 4 46 | 47 | 48 | 49 | 50 | 51 | 52 | 5 53 | 54 | 55 | 56 | 57 | 58 | 59 | 6 60 | 61 | 62 | 63 | 64 | 65 | 66 | 7 67 | 68 | 69 | 70 | 71 | 72 | 73 | 8 74 | 75 | 76 | 77 | 78 | 79 | 80 | 9 81 | 82 | 83 | 84 | 85 | 86 | 87 | 10 88 | 89 | 90 | 91 | 92 | 93 | 94 | 11 95 | 96 | 97 | 98 | 99 | 100 | 101 | 12 102 | 103 | 104 | 105 | 106 | 107 | 108 | 13 109 | 110 | 111 | 112 | 113 | 114 | 115 | 14 116 | 117 | 118 | 119 | 120 | 121 | 122 | 15 123 | 124 | 125 | 126 | 127 | 128 | 129 | 16 130 | 131 | 132 | 133 | 134 | 135 | 136 | 17 137 | 138 | 139 | 140 | 141 | 142 | 143 | 18 144 | 145 | 146 | 147 | 148 | 149 | 150 | 19 151 | 152 | 153 | 154 | 155 | 156 | 157 | 20 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 1 318 | 319 | 320 | 321 | 322 | 323 | 324 | 2 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 1 337 | 338 | 339 | 340 | 341 | 342 | 343 | 2 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 1 393 | 394 | 395 | 396 | 397 | 398 | 399 | 2 400 | 401 | 402 | 403 | 404 | 405 | 406 | 3 407 | 408 | 409 | 410 | 411 | 412 | 413 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService4.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/AddOnService5.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.AddOn.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.AddOn, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.AddOnFile.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.AddOnFile, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.DownloadToken.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.DownloadToken, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.FingerprintMatchResult.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.FingerprintMatchResult, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.FuzzyMatch.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.FuzzyMatch, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.RepositoryMatch.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.RepositoryMatch, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponse.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponse, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSavedGameeheogrl4.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSavedGameeheogrl4, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSyncedGameInstanceeheogrl4.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponseOfArrayOfSyncedGameInstanceeheogrl4, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponseOfESavedGameRestrictionLeveleheogrl4.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponseOfESavedGameRestrictionLeveleheogrl4, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponseOfSavedGameConstraintseheogrl4.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponseOfSavedGameConstraintseheogrl4, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Curse.RestProxy.AddOnService.ServiceResponseOfSyncedGameInstanceeheogrl4.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.AddOnService.ServiceResponseOfSyncedGameInstanceeheogrl4, Service References.AddOnService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | true 7 | 8 | false 9 | false 10 | false 11 | 12 | 13 | 14 | 15 | true 16 | Auto 17 | true 18 | true 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/AddOnService/configuration.svcinfo: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService.disco: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService1.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | http://clientservice-v6-beta.curse.com/ClientLoginService.svc/Binary 48 | 49 | 50 | 51 | 52 | 53 | https://iis30a-live.curse.us/ClientLoginService.svc/Binary 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService1.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/ClientLoginService2.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 100 45 | 46 | 47 | 48 | 49 | 50 | 51 | 101 52 | 53 | 54 | 55 | 56 | 57 | 58 | 102 59 | 60 | 61 | 62 | 63 | 64 | 65 | 103 66 | 67 | 68 | 69 | 70 | 71 | 72 | 104 73 | 74 | 75 | 76 | 77 | 78 | 79 | 105 80 | 81 | 82 | 83 | 84 | 85 | 86 | 106 87 | 88 | 89 | 90 | 91 | 92 | 93 | 107 94 | 95 | 96 | 97 | 98 | 99 | 100 | 108 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/Curse.RestProxy.LoginService.LoginResponse.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.LoginService.LoginResponse, Service References.LoginService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/Curse.RestProxy.LoginService.RegisterUserResult.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | Curse.RestProxy.LoginService.RegisterUserResult, Service References.LoginService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | true 7 | 8 | false 9 | false 10 | false 11 | 12 | 13 | 14 | 15 | true 16 | Auto 17 | true 18 | true 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Curse.RestProxy/Service References/LoginService/configuration.svcinfo: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Curse.RestProxy/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Curse.RestProxy/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Curse.RestProxy/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Curse.RestProxy/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Andy Miller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Curse REST Proxy 2 | 3 | This is a simple REST API proxy for the Curse web services. Online at 4 | https://curse-rest-proxy.azurewebsites.net/api 5 | 6 | Curse uses WCF services in SOAP binary transport mode, which makes communicating with them outside 7 | of a .NET environment very difficult. This proxy provides a thin REST wrapper around those services 8 | to allow other platforms easier access to the Curse client services. 9 | 10 | ## Overview 11 | 12 | | Name | Endpoint | Description | 13 | |---------------------------------------------------------|--------------------------------------------------------------------------------------------|-------------| 14 | | Home | GET https://curse-rest-proxy.azurewebsites.net/api | | 15 | | Status | GET https://curse-rest-proxy.azurewebsites.net/api/status | Service Status | 16 | | [Authentication](#authentication) | POST https://curse-rest-proxy.azurewebsites.net/api/authenticate | Authentication | 17 | | [Get Add On](#get-add-on) | GET https://curse-rest-proxy.azurewebsites.net/api/addon/:id | Get the details for an add on | 18 | | [Get Add On Description](#get-add-on-description) | GET https://curse-rest-proxy.azurewebsites.net/api/addon/:id/description | Get the description of an add on | 19 | | [Get Add On Files](#get-add-on-files) | GET https://curse-rest-proxy.azurewebsites.net/api/addon/:id/files | Get the list of files for this add on | 20 | | [Get Add On File](#get-add-on-file) | GET https://curse-rest-proxy.azurewebsites.net/api/addon/:addon_id/file/:file_id | Get the details for a file | 21 | | [Get Add On File Changelog](#get-add-on-file-changelog) | GET https://curse-rest-proxy.azurewebsites.net/api/addon/:addon_id/file/:file_id/changelog | Get the changelog for a file | 22 | 23 | ## Usage 24 | 25 | ### Post Data 26 | 27 | The API only accepts post data in `application/json` format. The following header must be on all 28 | POST requests: 29 | 30 | Content-Type: application/json 31 | 32 | ### Authentication 33 | 34 | Usage of the Curse WCF services requires authentication with a valid username and password. 35 | Authenticating will return a token that can be used on subsequent calls to the services. 36 | 37 | #### Request 38 | 39 | POST https://curse-rest-proxy.azurewebsites.net/api/authenticate 40 | Content-Type: application/json 41 | { 42 | "username": "", 43 | "password": "" 44 | } 45 | 46 | #### Success Response 47 | 48 | 200 Ok 49 | Content-Type: application/json 50 | { 51 | "session": { 52 | "actual_premium_status": false, 53 | "effective_premium_status": false, 54 | "email_address": "", 55 | "session_id": "", 56 | "subscription_token": , 57 | "token": "", 58 | "user_id": , 59 | "username": "" 60 | }, 61 | "status": "Success" 62 | } 63 | 64 | #### Authentication Failed 65 | 66 | 401 Unauthorized 67 | Www-Authenticate: Token realm="api" 68 | 69 | #### Invalid Request 70 | 71 | 400 Bad Request 72 | Content-Type: application/json 73 | { 74 | "message": "Username and password are required" 75 | } 76 | 77 | #### Authorization Header 78 | 79 | Once authenticated, subsequent requests to the service must include the `Authorization` header with 80 | the value of `Token :` where `userid` and `token` come from the authenticate response. 81 | For example: 82 | 83 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1 84 | Authorization: Token 12345:abcdef 85 | 86 | If the header is missing, not in the correct form, or the token is rejected by Curse, the API will 87 | respond with: 88 | 89 | 401 Unauthorized 90 | Www-Authenticate: Token realm="api" 91 | 92 | ### Get Add On 93 | 94 | Get the details for an add on. 95 | 96 | #### Request 97 | 98 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1 99 | Authorization: Token 12345:abcdef 100 | 101 | #### Response 102 | 103 | 200 Ok 104 | Content-Type: application/json 105 | { 106 | "id": 1, 107 | "name": "Package Name", 108 | "package_type": "ModPack", // ModPack | Mod | World 109 | "summary": "A demo package", 110 | "web_site_url": "http://www.curse.com/modpacks/minecraft/1-package-name" 111 | "attachments": [ 112 | { 113 | "description": "", 114 | "is_default": true, 115 | "thumbnail_url": "http://example.com/path/to/thumbnail.png", 116 | "title": "title.png", 117 | "url": "http://example.com/path/to/file.png" 118 | } 119 | ], 120 | "authors": [ 121 | { 122 | "name": "John Doe", 123 | "url": "http://www.curse.com/members/JohnDoe.aspx" 124 | } 125 | ], 126 | "avatar_url": null, 127 | "categories": [ 128 | { 129 | "id": 4475, 130 | "name": "Adventure and RPG", 131 | "url": "http://www.curse.com/modpacks/minecraft/category/adventure-and-rpg" 132 | }, 133 | { 134 | "id": 4479, 135 | "name": "Hardcore", 136 | "url": "http://www.curse.com/modpacks/minecraft/category/hardcore" 137 | } 138 | ], 139 | "category_section": { 140 | "extra_include_pattern": null, 141 | "game_id": 432, 142 | "id": 4471, 143 | "initial_inclusion_pattern": ".", 144 | "name": "Modpacks", 145 | "package_type": "ModPack", 146 | "path": "downloads" 147 | }, 148 | "comment_count": 0, 149 | "default_file_id": 42, 150 | "donation_url": null, 151 | "download_count": 101, 152 | "external_url": null, 153 | "game_id": 432, 154 | "icon_id": 1, 155 | "install_count": 0, 156 | "is_featured": 0, 157 | "latest_files": [ 158 | { 159 | "alternate_file_id": 0, 160 | "dependencies": [], 161 | "download_url": "http://example.com/path/to/file-1.0.0.zip", 162 | "file_date": "2015-10-07T20:36:26", 163 | "file_name": "file-1.0.0.zip", 164 | "file_name_on_disk": "file-1.0.0.zip", 165 | "file_status": "Normal", 166 | "game_version": [ 167 | "1.7.10" 168 | ], 169 | "id": 42, 170 | "is_alternate": false, 171 | "is_available": true, 172 | "modules": [ 173 | { 174 | "fingerprint": 9876543421, 175 | "foldername": "manifest.json" 176 | } 177 | ], 178 | "package_fingerprint": 987654321, 179 | "release_type": "Release" 180 | } 181 | ], 182 | "game_version_latest_files": [ 183 | { 184 | "file_type": "Release", 185 | "game_vesion": "1.7.10", 186 | "project_file_id": 42, 187 | "project_file_name": "file-1.0.0.zip" 188 | } 189 | ], 190 | "likes": 2, 191 | "popularity_score": 100.4567, 192 | "primary_author_name": "John Doe", 193 | "primary_category_avatar_url": null, 194 | "primary_category_id": 4475, 195 | "primary_category_name": null, 196 | "rating": 0, 197 | "stage": "Release", 198 | "status": "Normal", 199 | } 200 | 201 | ### Get Add On Description 202 | 203 | Get the description for an add on. 204 | 205 | #### Request 206 | 207 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1/description 208 | Authorization: Token 12345:abcdef 209 | 210 | #### Response 211 | 212 | 200 Ok 213 | Content-Type: application/json 214 | { 215 | "description": "A long description of the add on. This may contain HTML." 216 | } 217 | 218 | ### Get Add On Files 219 | 220 | Get the files for an add on. 221 | 222 | #### Request 223 | 224 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1/files 225 | Authorization: Token 12345:abcdef 226 | 227 | #### Response 228 | 229 | 200 Ok 230 | Content-Type: application/json 231 | { 232 | "files": [ 233 | { 234 | "alternate_file_id": 0, 235 | "dependencies": [], 236 | "download_url": "http://example.com/path/to/file-1.0.1.zip", 237 | "file_date": "2015-11-07T20:36:26", 238 | "file_name": "file-1.0.0.zip", 239 | "file_name_on_disk": "file-1.0.0.zip", 240 | "file_status": "Normal", 241 | "game_version": [ 242 | "1.7.10" 243 | ], 244 | "id": 42, 245 | "is_alternate": false, 246 | "is_available": true, 247 | "modules": [ 248 | { 249 | "fingerprint": 9876543421, 250 | "foldername": "manifest.json" 251 | } 252 | ], 253 | "package_fingerprint": 987654321, 254 | "release_type": "Release" 255 | }, 256 | { 257 | "alternate_file_id": 0, 258 | "dependencies": [], 259 | "download_url": "http://example.com/path/to/file-1.0.0.zip", 260 | "file_date": "2015-10-07T20:36:26", 261 | "file_name": "file-1.0.0.zip", 262 | "file_name_on_disk": "file-1.0.0.zip", 263 | "file_status": "Normal", 264 | "game_version": [ 265 | "1.7.10" 266 | ], 267 | "id": 43, 268 | "is_alternate": false, 269 | "is_available": true, 270 | "modules": [ 271 | { 272 | "fingerprint": 9876543421, 273 | "foldername": "manifest.json" 274 | } 275 | ], 276 | "package_fingerprint": 987654321, 277 | "release_type": "Release" 278 | } 279 | ] 280 | } 281 | 282 | ### Get Add On File 283 | 284 | Get a specific file for an add on. 285 | 286 | #### Request 287 | 288 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1/file/42 289 | Authorization: Token 12345:abcdef 290 | 291 | #### Response 292 | 293 | 200 Ok 294 | Content-Type: application/json 295 | { 296 | "alternate_file_id": 0, 297 | "dependencies": [], 298 | "download_url": "http://example.com/path/to/file-1.0.1.zip", 299 | "file_date": "2015-11-07T20:36:26", 300 | "file_name": "file-1.0.0.zip", 301 | "file_name_on_disk": "file-1.0.0.zip", 302 | "file_status": "Normal", 303 | "game_version": [ 304 | "1.7.10" 305 | ], 306 | "id": 42, 307 | "is_alternate": false, 308 | "is_available": true, 309 | "modules": [ 310 | { 311 | "fingerprint": 9876543421, 312 | "foldername": "manifest.json" 313 | } 314 | ], 315 | "package_fingerprint": 987654321, 316 | "release_type": "Release" 317 | } 318 | 319 | ### Get Add On File Changelog 320 | 321 | Get the changelog for an add on file. 322 | 323 | #### Request 324 | 325 | GET https://curse-rest-proxy.azurewebsites.net/api/addon/1/file/42/changelog 326 | Authorization: Token 12345:abcdef 327 | 328 | #### Response 329 | 330 | 200 Ok 331 | Content-Type: application/json 332 | { 333 | "changelog": "A changelog for the file. This may contain HTML." 334 | } 335 | 336 | ## Project Feed 337 | 338 | The Curse WCF services do not seem to provide a way to get a list of all add ons, nor a 339 | way to search for an add on. It assumes you already know the id of the add on you need. 340 | 341 | The official Curse Client uses a json feed of all of the add ons for a game to get its list. 342 | 343 | See: https://github.com/amcoder/Curse.RestProxy/wiki/Curse-Project-Feed 344 | 345 | ## License 346 | 347 | Curse REST Proxy is released under the [MIT license](https://opensource.org/licenses/MIT). 348 | --------------------------------------------------------------------------------