-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jgdevlabs/dev
Adding full support for reCAPTCHA V3 and automatic binding to challenges
- Loading branch information
Showing
28 changed files
with
1,228 additions
and
840 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes.
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
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ trigger: | |
paths: | ||
exclude: | ||
- '*/README.md' | ||
- '*/.github/*' | ||
- '*/LICENSE.md' | ||
- '*/CHANGELOG.md' | ||
|
||
pr: none | ||
|
||
|
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,69 +1,59 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;net461</TargetFrameworks> | ||
<RootNamespace>Griesoft.AspNetCore.ReCaptcha</RootNamespace> | ||
<AssemblyName>Griesoft.AspNetCore.ReCaptcha</AssemblyName> | ||
<Company>Griesinger Software</Company> | ||
<Authors>Joonas Griesinger</Authors> | ||
<Owners>jgdevlabs,jooni91</Owners> | ||
<Title>ASP.NET Core reCAPTCHA Service</Title> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>8.0</LangVersion> | ||
<Description>A Google reCPATCHA validation wrapper service for ASP.NET Core. With only a few simple setup steps you are ready to block bots from filling in and submitting forms on your website.</Description> | ||
<Copyright>2020 © Griesinger Software</Copyright> | ||
<PackageProjectUrl>https://github.com/jgdevlabs/aspnetcore-recaptcha</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/jgdevlabs/aspnetcore-recaptcha</RepositoryUrl> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
<PackageTags>aspnetcore;recaptcha;aspnetcoremvc;actionfilter;google;razor;recaptcha-v2;recaptcha-v3;taghelper</PackageTags> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DocumentationFile>D:\repos\ReCaptcha\docs\Griesoft.AspNetCore.ReCaptcha.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'"> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0'"> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Localization\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Localization\Resources.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0'"> | ||
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604</NoWarn> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1;net461;net5.0;net6.0</TargetFrameworks> | ||
<RootNamespace>Griesoft.AspNetCore.ReCaptcha</RootNamespace> | ||
<AssemblyName>Griesoft.AspNetCore.ReCaptcha</AssemblyName> | ||
<Company>Griesinger Software</Company> | ||
<Authors>Joonas Griesinger</Authors> | ||
<Owners>jgdevlabs,jooni91</Owners> | ||
<Title>ASP.NET Core reCAPTCHA Service</Title> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<Description>A Google reCAPTCHA validation wrapper service for ASP.NET Core. With only a few simple setup steps you are ready to block bots from filling in and submitting forms on your website.</Description> | ||
<Copyright>2022 © Griesinger Software</Copyright> | ||
<PackageProjectUrl>https://github.com/jgdevlabs/aspnetcore-recaptcha</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/jgdevlabs/aspnetcore-recaptcha</RepositoryUrl> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
<PackageTags>aspnetcore;recaptcha;aspnetcoremvc;recaptcha-v2;recaptcha-v3</PackageTags> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<DocumentationFile>..\..\docs\Griesoft.AspNetCore.ReCaptcha.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Localization\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Localization\Resources.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
</Project> |
42 changes: 42 additions & 0 deletions
42
src/ReCaptcha/TagHelpers/CallbackScriptTagHelperComponent.cs
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,42 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
[assembly: InternalsVisibleTo("ReCaptcha.Tests")] | ||
namespace Griesoft.AspNetCore.ReCaptcha.TagHelpers | ||
{ | ||
/// <summary> | ||
/// This tag helper component is used to add a short callback script to the bottom of a body tag. | ||
/// </summary> | ||
/// <remarks> | ||
/// The callback script is used as a default callback function to submit a form after a reCAPTCHA challenge was successful. | ||
/// </remarks> | ||
internal class CallbackScriptTagHelperComponent : TagHelperComponent | ||
{ | ||
private readonly string _formId; | ||
|
||
public CallbackScriptTagHelperComponent(string formId) | ||
{ | ||
if (string.IsNullOrEmpty(formId)) | ||
{ | ||
throw new ArgumentNullException(nameof(formId)); | ||
} | ||
|
||
_formId = formId; | ||
} | ||
|
||
public override void Process(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (string.Equals(context.TagName, "body", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
output.PostContent.AppendHtml(CallbackScript(_formId)); | ||
} | ||
} | ||
|
||
public static string CallbackScript(string formId) | ||
{ | ||
// Append the formId to the function name in case that multiple recaptcha tags are added in a document. | ||
return $"<script>function submit{formId}(token){{document.getElementById('{formId}').submit();}}</script>"; | ||
} | ||
} | ||
} |
Oops, something went wrong.