/// <summary>Snippet for CreateAssessment</summary> public void CreateAssessmentResourceNames() { // Snippet: CreateAssessment(ProjectName, Assessment, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) ProjectName parent = ProjectName.FromProject("[PROJECT]"); Assessment assessment = new Assessment(); // Make the request Assessment response = recaptchaEnterpriseServiceClient.CreateAssessment(parent, assessment); // End snippet }
/// <summary>Snippet for CreateAssessment</summary> public void CreateAssessment() { // Snippet: CreateAssessment(string, Assessment, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) string parent = "projects/[PROJECT]"; Assessment assessment = new Assessment(); // Make the request Assessment response = recaptchaEnterpriseServiceClient.CreateAssessment(parent, assessment); // End snippet }
/// <summary>Snippet for AnnotateAssessment</summary> public void AnnotateAssessmentResourceNames() { // Snippet: AnnotateAssessment(AssessmentName, AnnotateAssessmentRequest.Types.Annotation, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) AssessmentName name = AssessmentName.FromProjectAssessment("[PROJECT]", "[ASSESSMENT]"); AnnotateAssessmentRequest.Types.Annotation annotation = AnnotateAssessmentRequest.Types.Annotation.Unspecified; // Make the request AnnotateAssessmentResponse response = recaptchaEnterpriseServiceClient.AnnotateAssessment(name, annotation); // End snippet }
/// <summary>Snippet for AnnotateAssessment</summary> public void AnnotateAssessment() { // Snippet: AnnotateAssessment(string, AnnotateAssessmentRequest.Types.Annotation, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) string name = "projects/[PROJECT]/assessments/[ASSESSMENT]"; AnnotateAssessmentRequest.Types.Annotation annotation = AnnotateAssessmentRequest.Types.Annotation.Unspecified; // Make the request AnnotateAssessmentResponse response = recaptchaEnterpriseServiceClient.AnnotateAssessment(name, annotation); // End snippet }
/// <summary>Snippet for GetKey</summary> public void GetKeyRequestObject() { // Snippet: GetKey(GetKeyRequest, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) GetKeyRequest request = new GetKeyRequest { KeyName = KeyName.FromProjectKey("[PROJECT]", "[KEY]"), }; // Make the request Key response = recaptchaEnterpriseServiceClient.GetKey(request); // End snippet }
/// <summary>Snippet for CreateAssessmentAsync</summary> public async Task CreateAssessmentResourceNamesAsync() { // Snippet: CreateAssessmentAsync(ProjectName, Assessment, CallSettings) // Additional: CreateAssessmentAsync(ProjectName, Assessment, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) ProjectName parent = ProjectName.FromProject("[PROJECT]"); Assessment assessment = new Assessment(); // Make the request Assessment response = await recaptchaEnterpriseServiceClient.CreateAssessmentAsync(parent, assessment); // End snippet }
/// <summary>Snippet for CreateAssessment</summary> public void CreateAssessmentRequestObject() { // Snippet: CreateAssessment(CreateAssessmentRequest, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) CreateAssessmentRequest request = new CreateAssessmentRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), Assessment = new Assessment(), }; // Make the request Assessment response = recaptchaEnterpriseServiceClient.CreateAssessment(request); // End snippet }
/// <summary>Snippet for CreateAssessmentAsync</summary> public async Task CreateAssessmentAsync() { // Snippet: CreateAssessmentAsync(string, Assessment, CallSettings) // Additional: CreateAssessmentAsync(string, Assessment, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) string parent = "projects/[PROJECT]"; Assessment assessment = new Assessment(); // Make the request Assessment response = await recaptchaEnterpriseServiceClient.CreateAssessmentAsync(parent, assessment); // End snippet }
/// <summary>Snippet for AnnotateAssessment</summary> public void AnnotateAssessmentRequestObject() { // Snippet: AnnotateAssessment(AnnotateAssessmentRequest, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) AnnotateAssessmentRequest request = new AnnotateAssessmentRequest { AssessmentName = AssessmentName.FromProjectAssessment("[PROJECT]", "[ASSESSMENT]"), Annotation = AnnotateAssessmentRequest.Types.Annotation.Unspecified, }; // Make the request AnnotateAssessmentResponse response = recaptchaEnterpriseServiceClient.AnnotateAssessment(request); // End snippet }
/// <summary>Snippet for UpdateKey</summary> public void UpdateKeyRequestObject() { // Snippet: UpdateKey(UpdateKeyRequest, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.Create(); // Initialize request argument(s) UpdateKeyRequest request = new UpdateKeyRequest { Key = new Key(), UpdateMask = new FieldMask(), }; // Make the request Key response = recaptchaEnterpriseServiceClient.UpdateKey(request); // End snippet }
/// <summary>Snippet for ListKeysAsync</summary> public async Task ListKeysRequestObjectAsync() { // Snippet: ListKeysAsync(ListKeysRequest, CallSettings) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) ListKeysRequest request = new ListKeysRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), }; // Make the request PagedAsyncEnumerable <ListKeysResponse, Key> response = recaptchaEnterpriseServiceClient.ListKeysAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Key item) => { // Do something with each item Console.WriteLine(item); }); // Or iterate over pages (of server-defined size), performing one RPC per page await response.AsRawResponses().ForEachAsync((ListKeysResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Key item in page) { // Do something with each item Console.WriteLine(item); } }); // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Key> singlePage = await response.ReadPageAsync(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Key item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for AnnotateAssessmentAsync</summary> public async Task AnnotateAssessmentAsync() { // Snippet: AnnotateAssessmentAsync(string, AnnotateAssessmentRequest.Types.Annotation, CallSettings) // Additional: AnnotateAssessmentAsync(string, AnnotateAssessmentRequest.Types.Annotation, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) string name = "projects/[PROJECT]/assessments/[ASSESSMENT]"; AnnotateAssessmentRequest.Types.Annotation annotation = AnnotateAssessmentRequest.Types.Annotation.Unspecified; // Make the request AnnotateAssessmentResponse response = await recaptchaEnterpriseServiceClient.AnnotateAssessmentAsync(name, annotation); // End snippet }
/// <summary>Snippet for AnnotateAssessmentAsync</summary> public async Task AnnotateAssessmentResourceNamesAsync() { // Snippet: AnnotateAssessmentAsync(AssessmentName, AnnotateAssessmentRequest.Types.Annotation, CallSettings) // Additional: AnnotateAssessmentAsync(AssessmentName, AnnotateAssessmentRequest.Types.Annotation, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) AssessmentName name = AssessmentName.FromProjectAssessment("[PROJECT]", "[ASSESSMENT]"); AnnotateAssessmentRequest.Types.Annotation annotation = AnnotateAssessmentRequest.Types.Annotation.Unspecified; // Make the request AnnotateAssessmentResponse response = await recaptchaEnterpriseServiceClient.AnnotateAssessmentAsync(name, annotation); // End snippet }
/// <summary>Snippet for DeleteKeyAsync</summary> public async Task DeleteKeyRequestObjectAsync() { // Snippet: DeleteKeyAsync(DeleteKeyRequest, CallSettings) // Additional: DeleteKeyAsync(DeleteKeyRequest, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) DeleteKeyRequest request = new DeleteKeyRequest { KeyName = KeyName.FromProjectKey("[PROJECT]", "[KEY]"), }; // Make the request await recaptchaEnterpriseServiceClient.DeleteKeyAsync(request); // End snippet }
/// <summary>Snippet for CreateAssessmentAsync</summary> public async Task CreateAssessmentRequestObjectAsync() { // Snippet: CreateAssessmentAsync(CreateAssessmentRequest, CallSettings) // Additional: CreateAssessmentAsync(CreateAssessmentRequest, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) CreateAssessmentRequest request = new CreateAssessmentRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), Assessment = new Assessment(), }; // Make the request Assessment response = await recaptchaEnterpriseServiceClient.CreateAssessmentAsync(request); // End snippet }
/// <summary>Snippet for UpdateKeyAsync</summary> public async Task UpdateKeyRequestObjectAsync() { // Snippet: UpdateKeyAsync(UpdateKeyRequest, CallSettings) // Additional: UpdateKeyAsync(UpdateKeyRequest, CancellationToken) // Create client RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync(); // Initialize request argument(s) UpdateKeyRequest request = new UpdateKeyRequest { Key = new Key(), UpdateMask = new FieldMask(), }; // Make the request Key response = await recaptchaEnterpriseServiceClient.UpdateKeyAsync(request); // End snippet }
public bool ReCaptchaPassed(string gRecaptchaResponse) { string SiteKey = "6LegSIoaAAAAADG_Bsv_EZPPFeBhOEmXTJg5Qx9u"; string Token = gRecaptchaResponse; string AssessmentName = "RegistrationAssessment"; string ParentProject = "projects/tranquil-bison-277423"; string RecaptchaAction = "REGISTER"; RecaptchaEnterpriseServiceClientBuilder CredentialBuilder = new RecaptchaEnterpriseServiceClientBuilder(); CredentialBuilder.JsonCredentials = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS_JSON_VERSION"); RecaptchaEnterpriseServiceClient client = CredentialBuilder.Build(); CreateAssessmentRequest createAssessmentRequest = new CreateAssessmentRequest() { Assessment = new Assessment() { Event = new Event() { SiteKey = SiteKey, Token = Token, ExpectedAction = RecaptchaAction }, Name = AssessmentName, }, Parent = ParentProject }; Assessment response = client.CreateAssessment(createAssessmentRequest); if (response.TokenProperties.Valid == false) { System.Console.WriteLine("The CreateAssessment() call failed " + "because the token was invalid for the following reason: " + response.TokenProperties.InvalidReason.ToString()); _telemetry.TrackEvent("ReCaptchaCompleted", new Dictionary <string, string> { { "RiskAnalysis", "-1" } }); return(false); } else { if (response.Event.ExpectedAction == RecaptchaAction) { System.Console.WriteLine("The reCAPTCHA score for this token is: " + response.RiskAnalysis.Score.ToString()); _telemetry.TrackEvent("ReCaptchaCompleted", new Dictionary <string, string> { { "RiskAnalysis", response.RiskAnalysis.Score.ToString() } }); if (response.RiskAnalysis.Score > .4) { return(true); } else { return(false); } } else { System.Console.WriteLine("The action attribute in your reCAPTCHA " + "tag does not match the action you are expecting to score"); _telemetry.TrackEvent("ReCaptchaCompleted", new Dictionary <string, string> { { "RiskAnalysis", "-1" } }); return(false); } } }