-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
87,583 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v8.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v8.0": { | ||
"CSO.Recaptcha/0.0.1": { | ||
"dependencies": { | ||
"Newtonsoft.Json": "13.0.3" | ||
}, | ||
"runtime": { | ||
"CSO.Recaptcha.dll": {} | ||
} | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"runtime": { | ||
"lib/net6.0/Newtonsoft.Json.dll": { | ||
"assemblyVersion": "13.0.0.0", | ||
"fileVersion": "13.0.3.27908" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"CSO.Recaptcha/0.0.1": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"type": "package", | ||
"serviceable": true, | ||
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", | ||
"path": "newtonsoft.json/13.0.3", | ||
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v8.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v8.0": { | ||
"Recaptcha/0.0.1": { | ||
"dependencies": { | ||
"Newtonsoft.Json": "13.0.3" | ||
}, | ||
"runtime": { | ||
"Recaptcha.dll": {} | ||
} | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"runtime": { | ||
"lib/net6.0/Newtonsoft.Json.dll": { | ||
"assemblyVersion": "13.0.0.0", | ||
"fileVersion": "13.0.3.27908" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"Recaptcha/0.0.1": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
}, | ||
"Newtonsoft.Json/13.0.3": { | ||
"type": "package", | ||
"serviceable": true, | ||
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", | ||
"path": "newtonsoft.json/13.0.3", | ||
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.2.32630.192 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE5B5136-CEE7-40AE-A799-A364D1A27D20}" | ||
ProjectSection(SolutionItems) = preProject | ||
nuget.config = nuget.config | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSO.Recaptcha", "CSO.Recaptcha\CSO.Recaptcha.csproj", "{EBFD0B0A-6C09-4878-96AF-6C29673762BE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Debug|x64.ActiveCfg = Debug|x64 | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Debug|x64.Build.0 = Debug|x64 | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Release|x64.ActiveCfg = Release|x64 | ||
{EBFD0B0A-6C09-4878-96AF-6C29673762BE}.Release|x64.Build.0 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C633644D-71C0-4CF2-95D0-F6C367931EB3} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> | ||
<GenerateAssemblyInfo>True</GenerateAssemblyInfo> | ||
<Configuration></Configuration> | ||
<Company>Central Statistics Office, Ireland</Company> | ||
<PackageId>CSO.Recaptcha.BETA</PackageId> | ||
<Product>CSO Recaptcha</Product> | ||
<Copyright>Central Statistics Office, Ireland</Copyright> | ||
<Version>0.0.1</Version> | ||
<Authors>Central Statistics Office, Ireland</Authors> | ||
<SignAssembly>False</SignAssembly> | ||
<RepositoryUrl>https://github.com/CSOIreland/CSORecaptcha</RepositoryUrl> | ||
<PackageReleaseNotes> | ||
- [INFO] initial release of CSO standalone recaptcha library | ||
</PackageReleaseNotes> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
<RestoreLockedMode>true</RestoreLockedMode> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
|
||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<Optimize>False</Optimize> | ||
<DebugType>portable</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DebugType>portable</DebugType> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace CSO.Recaptcha | ||
{ | ||
/// <summary> | ||
/// Handle the Google ReCaptcha to validate human inputs in forms | ||
/// </summary> | ||
public static class ReCAPTCHA | ||
{ | ||
#region Properties | ||
#endregion | ||
|
||
#region Methods | ||
/// <summary> | ||
/// Check if the ReCaptcha is enabled | ||
/// </summary> | ||
/// <param name="configDict"></param> | ||
/// <returns></returns> | ||
private static bool IsEnabled(IDictionary<string, string> configDict) | ||
{ | ||
/// <summary> | ||
/// Flag to indicate if ReCAPTCHA is enabled | ||
/// </summary> | ||
bool API_RECAPTCHA_ENABLED = Convert.ToBoolean(configDict["API_RECAPTCHA_ENABLED"]); | ||
|
||
if (API_RECAPTCHA_ENABLED) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Validate the encoded response against the Google server | ||
/// </summary> | ||
/// <param name="encodedResponse"></param> | ||
/// <param name="configDict"></param> | ||
/// <param name="LogObject"></param> | ||
/// <returns></returns> | ||
public static bool Validate(string encodedResponse, IDictionary<string, string> configDict, dynamic LogObject) | ||
{ | ||
/// <summary> | ||
/// Flag to indicate if ReCAPTCHA is enabled | ||
/// </summary> | ||
bool API_RECAPTCHA_ENABLED = Convert.ToBoolean(configDict["API_RECAPTCHA_ENABLED"]); | ||
|
||
/// <summary> | ||
/// URL | ||
/// </summary> | ||
string API_RECAPTCHA_URL = configDict["API_RECAPTCHA_URL"]; | ||
|
||
/// <summary> | ||
/// privates key | ||
/// </summary> | ||
string API_RECAPTCHA_PRIVATE_KEY = configDict["API_RECAPTCHA_PRIVATE_KEY"]; | ||
|
||
|
||
|
||
LogObject.Info("ReCAPTCHA Enabled: " + API_RECAPTCHA_ENABLED); | ||
LogObject.Info("ReCAPTCHA URL: " + API_RECAPTCHA_URL); | ||
LogObject.Info("ReCAPTCHA Private Key: ********"); // Hide API_RECAPTCHA_PRIVATE_KEY from logs | ||
|
||
// Skip the validation if not enabled | ||
if (!IsEnabled(configDict)) | ||
return true; | ||
|
||
try | ||
{ | ||
// Validate the response against the server | ||
var client = new HttpClient(); | ||
|
||
var requestString = string.Format(API_RECAPTCHA_URL, API_RECAPTCHA_PRIVATE_KEY, encodedResponse); | ||
string responseString = ""; | ||
|
||
using (HttpResponseMessage response = client.GetAsync(requestString).Result) | ||
{ | ||
using (HttpContent content = response.Content) | ||
{ | ||
responseString = content.ReadAsStringAsync().Result; | ||
} | ||
} | ||
|
||
|
||
|
||
// var responseObject = Utility.JsonDeserialize_IgnoreLoopingReference<JObject>(responseString); | ||
var responseObject = JsonConvert.DeserializeObject<dynamic>(responseString, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None }); | ||
var responseSuccess = (string)responseObject["success"]; | ||
|
||
LogObject.Instance.Info("Server Response: " + responseString); | ||
|
||
if (responseSuccess.ToLowerInvariant() == "true") | ||
{ | ||
// All good and valid | ||
LogObject.Instance.Info("Valid Encoded Response: " + encodedResponse); | ||
return true; | ||
} | ||
else | ||
{ | ||
// Something went wrong | ||
LogObject.Instance.Info("Invalid Encoded Response: " + encodedResponse); | ||
return false; | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
LogObject.Instance.Fatal(e); | ||
return false; | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": { | ||
"net8.0": { | ||
"Newtonsoft.Json": { | ||
"type": "Direct", | ||
"requested": "[13.0.3, )", | ||
"resolved": "13.0.3", | ||
"contentHash": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==" | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/installed_packages/newtonsoft.json/13.0.3/.nupkg.metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": 2, | ||
"contentHash": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==", | ||
"source": "https://api.nuget.org/v3/index.json" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2007 James Newton-King | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.