May 9, 2018

Google ReCAPTCHA & K2

by Andrew Blinco in Enablement, Innovation, Proof, Video

Have you ever been to a website, and before you can submit or view information, you have had to verify that you are not a robot?

While this might be a bit annoying (of course you are not a robot!) there is a very good reason for doing this – to stop automated software, or “bots” from abusing the website. There is any number of “bad actors” out there who would like to exploit weaknesses in your site.

To try and sort the humans from the bots, CAPTCHA was invented as a way of testing who you were: man or a machine. CAPTCHA is an acronym that stands for Completely Automated Public Turing Test to Tell Computers and Humans Apart.

 

In the bad old days CAPTCHAs were usually images of squiggly text or numbers that you had to read and type into a text box, like the image below. They were not very friendly or pretty.

In 2009 Google acquired one of the CAPTCHA systems called reCaptcha. In the words of Google:

reCAPTCHA is a free service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.

reCaptcha is more user-friendly, asking users to verify you are not a robot by showing the user squares of images, and asking the user to select ones that meet a criterion, such as those having a street sign in them. You first tick the “I’m not a robot” box and then complete the test.

So, if you have a public facing website that allows users to view or submit information, you will probably be interested in stopping bots from running amok by using something like reCaptcha. What if your publicly facing form is using K2. Not to worry, you can quite easily add reCaptcha to your K2 forms.

The first thing you will need is a google account. If you don’t have one, visit Google and create one.

Then visit the reCaptcha site and click on the Get reCaptcha button and enter your Google login details.

Once you have logged in you will need to register your site. Give it a label and select the reCaptcha V2 option. You will need to enter the domain name for your K2 site (e.g. denallix.com) 

Once you have done this you will be shown the information needed to add reCaptcha to your site.

To add reCaptcha to your K2 form follow these steps:

  1. Create a new view (e.g. named “Google.Recaptcha.Verify.Item”)
  2. Add a data label to the view named “Recaptcha Script Data Label”
  3. Add an expression to your data label and add the following script to the expression, taking care to replace the highlighted value with your site key obtained above

<script type=”text/javascript”>var recaptchaCallback = function(response) {$(‘span[name=”Result Data Label”]’).SFCLabel(“option”, “text”, response);};</script><script src=’https://www.google.com/recaptcha/api.js’ ></script> <div class=”g-recaptcha” data-sitekey=”<your site key>” data-callback=”recaptchaCallback”></div>

  1. Make sure you mark your data label as a literal
  2. Add another data label called “Result Data Label”

At this point you can run your view, and you should be able to verify you are not a robot. When you are verified your Result Data Label should have a long string in it:

Great! You have verified you are not a robot, however, this is only half the story. Even though Google has returned a response (that long string), you have not fully verified. This is because you need to send that response off to Google now and get back a final confirmation.  To do this you will need to call Googles https://www.google.com/recaptcha/api/siteverify URL. The best and easiest way to do this is via a K2 REST service.

To create a reCaptcha REST service instance you will need a swagger file. A swagger file describes the service and is used by K2 for it to create the Service Instance and related Service Objects. The quickest and easiest way to create this is by using a service like REST United.

There is only one endpoint needed –  the following images describe the steps to create it in Rest UNITED.

Once you have the swagger file (you can export this from RESTUnited, go to Test & Export, select Swagger and then Export) place it on a location (i.e. file share or website) accessible by K2.

You can now create a new REST Service Instance and add this location to the “Descriptor Location” setting for your service instance.

Once your Google reCaptcha service is created, you can generate the SmartObject you need to perform the verification. The Service Object you need will be called “ValidationResponse” if you followed the steps above for creating the swagger file in RESTUnited. You can ask K2 to create the SmartObject for you by using the “Generate SmartObjects” button on the Service Instances page in Management.

This SmartObject will have a single “Verify” method that you need to call. This method takes two parameters: secret and response. The secret parameter maps to the “secret key” that was generated for you by Google when you registered your site. The response parameter is the long string that was returned to your “Result Data Label”

Instead of having to add the “secret” parameter in every time you call this “Verify” SmartObject method, you can add it in as a specific value in the SmartObject method definition. Edit the SmartObject method and choose to bind “secret” to a specific value, and paste your secret key in (don’t worry if K2 reports the value as “undefined” as per the image below, it will retain the value).

Now when you call this method on your form you do not need to pass the secret key in.

So now you can complete the final piece of the puzzle, and send Google your response and secret and get verification that the user is not a robot!

  1. Add a new data label to your view called “Recaptcha Valid Data Label”. Optionally you can add another data label to hold any error codes returned by the verify call (e.g. add an “Error Codes Data Label”)
  2. Add a new unbound rule to your view called “Verify Recaptcha Response” and add an action to call a SmartObject method
  3. Select your “Validation Response” SmartObject created above and the “Verify” method.
  4. Configure the action and map the “Result Data Label” to the “response” input parameter, and the “Success” property to the “Recaptcha Valid Data Label” in the output mappings.

  1. You can now finish this view and add it to a form. On your form you can now call the “Verify reCaptcha Response” rule in response to an event on your form, such as a button click. You will first want to check that the “Result Data Label” has a value, so that you can tell if the user has tried the reCaptcha verification. Once you have called the rule to verify the response you can check the value in “Recaptcha Valid Data Label” to see if is true (passed) or false (failed), and then act accordingly.

You now have a re-usable view and pattern for implementing Google reCaptcha on any of your K2 forms!

One Comment

  1. 1 May 2019 at 8:59 am

    I’m now not sure where you are getting your info, however great topic.
    I needs to spend some time studying more or understanding more.
    Thank you for fantastic info I was in search of this info for my mission.

  2. 1 May 2019 at 2:46 pm

    Hi colleagues, good post and fastidious arguments commented at this place, I am actually enjoying
    by these.

  3. 2 May 2019 at 12:24 am

    It’s nearly impossible to find educated people for this topic, however,
    you seem like you know what you’re talking about! Thanks

  4. 2 May 2019 at 1:11 am

    Great blog! Do you have any suggestions for aspiring writers?

    I’m planning to start my own website soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go for a paid option? There are so many
    choices out there that I’m totally confused .. Any ideas?
    Cheers!

  5. 2 May 2019 at 4:07 am

    I constantly spent my half an hour to read this website’s articles daily along with a cup of coffee.

  6. 3 May 2019 at 9:06 am

    Have you ever considered about including a little bit more than just your articles?
    I mean, what you say is fundamental and all.

    Nevertheless just imagine if you added some great visuals or video clips to give
    your posts more, “pop”! Your content is excellent but
    with images and clips, this blog could undeniably be one of the
    greatest in its niche. Amazing blog!

  7. 3 May 2019 at 9:29 am

    I am really loving the theme/design of your blog.
    Do you ever run into any internet browser compatibility problems?
    A couple of my blog visitors have complained about my blog not working correctly in Explorer but looks great in Safari.

    Do you have any solutions to help fix this problem?

  8. 5 May 2019 at 6:08 am

    Fantástico no entanto, eu era querendo saber se
    você poderia escrever um pouco mais sobre este tópico ?
    Eu seria muito grato se você poderia elaborar um pouco mais.
    Obrigado !

  9. 5 May 2019 at 7:42 am

    Hello, yes this paragraph is actually nice and I have learned lot of
    things from it concerning blogging. thanks.

  10. 7 May 2019 at 5:15 am

    Hi there, I enjoy reading all of your article. I wanted to write a little comment to support you.

  11. 7 May 2019 at 9:29 am

    What’s up, I would like to subscribe for this blog to obtain hottest updates, thus where can i do it please help
    out.

  12. 8 May 2019 at 6:25 am

    Wonderful blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed
    in Yahoo News? I’ve been trying for a while but I never
    seem to get there! Many thanks

  13. 8 May 2019 at 7:55 am

    Hello! I’ve been following your web site for a long time now and finally got the bravery to
    go ahead and give you a shout out from
    New Caney Texas! Just wanted to mention keep up the good job!

  14. 9 May 2019 at 2:43 am

    Greetings from California! I’m bored to tears at work so I decided to browse your site
    on my iphone during lunch break. I love the information you present here and can’t wait to take a look when I get
    home. I’m amazed at how quick your blog loaded on my phone ..

    I’m not even using WIFI, just 3G .. Anyhow,
    excellent site!

  15. 9 May 2019 at 6:59 am

    DIABO- Eu chefia no Espaço, na Pó bem como no Martírio.

  16. 9 May 2019 at 10:10 am

    As batatas com carraspana levam 8 minutos mais ou menos.

  17. 9 May 2019 at 5:51 pm

    Pretty! This was an incredibly wonderful article. Many thanks for providing this information.

  18. 11 May 2019 at 12:27 am

    WOW juswt what I was searching for. Came here by searching for
    Water Extraction Company

  19. 12 May 2019 at 3:45 pm

    Thank you for sharing your info. I really appreciate
    your efforts and I am waiting for your next post thank you once
    again.

  20. 13 May 2019 at 1:37 pm

    Zithromax Route Administration Buy Clomid Online Zest Creative priligy canada Cialis Online Kaufen Per Uberweisung Come Si Acquista Viagra In Farmacia

  21. 13 May 2019 at 5:59 pm

    I used to be suggested this website by my cousin. I am not positive whether or not this post is written through him as no one else realize
    such special approximately my problem. You’re wonderful!
    Thank you!

  22. 13 May 2019 at 6:00 pm

    Wow! This blog looks exactly like my old
    one! It’s on a entirely different subject but it has pretty much the same page layout and design. Superb choice of colors!

  23. 13 May 2019 at 6:11 pm

    I am actually happy to read this web site posts which carries tons of useful information, thanks for providing these
    kinds of statistics.

  24. 13 May 2019 at 7:23 pm

    Wow, wonderful blog layout! How long have you been blogging for?

    you make blogging look easy. The overall look of your website is great,
    as well as the content!

  25. 13 May 2019 at 7:58 pm

    Wonderful goods from you, man. I have understand your stuff previous to and you’re just too excellent.

    I really like what you have acquired here, really
    like what you are saying and the way in which you say it.
    You make it entertaining and you still take care of to keep
    it wise. I can’t wait to read much more from you. This is actually a terrific site.

  26. 13 May 2019 at 9:13 pm

    When I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I receive four emails with the same comment.
    Perhaps there is a means you can remove me from that service?

    Appreciate it!

  27. 14 May 2019 at 6:27 pm

    Thanks a lot for sharing this with all folks you actually recognise what you’re
    talking approximately! Bookmarked. Please also talk over with my web
    site =). We can have a link exchange agreement among us

  28. 14 May 2019 at 7:26 pm

    I absolutely love your site.. Pleasant colors & theme. Did you make this amazing site
    yourself? Please reply back as I’m wanting to create my own personal blog and would love to learn where you got this
    from or what the theme is called. Thanks!

  29. 16 May 2019 at 2:43 pm

    Hi to every one, the contents existing at this web site
    are truly amazing for people knowledge, well, keep
    up the nice work fellows.

  30. 16 May 2019 at 4:34 pm

    Hi, I do believe this is a great website. I stumbledupon it 😉 I am going to come back yet again since i have bookmarked
    it. Money and freedom is the greatest way to
    change, may you be rich and continue to guide others.

  31. 17 May 2019 at 12:53 pm

    Hello terrific website! Does running a blog such as this require a great deal of work?

    I have virtually no knowledge of computer programming but I was hoping
    to start my own blog in the near future. Anyway, if you have
    any suggestions or tips for new blog owners please share.
    I know this is off subject however I just had to ask.
    Thanks a lot!

  32. 17 May 2019 at 3:03 pm

    Magnificent beat ! I wish to apprentice while you
    amend your website, how can i subscribe for a blog web site?
    The account helped me a acceptable deal. I had been tiny
    bit acquainted of this your broadcast provided
    bright clear concept

  33. 18 May 2019 at 3:34 am

    Aw, this was an exceptionally nice post. Taking a few minutes and actual effort to produce a really good article… but what can I say… I hesitate a whole lot and never manage to get nearly anything
    done.

  34. 18 May 2019 at 3:46 am

    These are actually impressive ideas in concerning blogging.
    You have touched some fastidious points here.
    Any way keep up wrinting.

  35. 19 May 2019 at 8:00 am

    Its like you read my mind! You appear to know so much about this, like you wrote
    the book in it or something. I think that you could do with some pics
    to drive the message home a bit, but instead of that,
    this is excellent blog. A fantastic read. I’ll certainly be back.

  36. 19 May 2019 at 8:30 am

    I’ll right away seize your rss feed as I can not in finding your
    e-mail subscription link or newsletter service.

    Do you have any? Kindly allow me realize in order that I may
    subscribe. Thanks.

  37. 19 May 2019 at 12:33 pm

    I’m not sure exactly why but this website is loading very slow for me.
    Is anyone else having this problem or is it a issue on my end?
    I’ll check back later on and see if the problem still exists.

  38. 19 May 2019 at 1:23 pm

    Asking questions are actually pleasant thing if you are not understanding something completely, however this piece of writing presents pleasant understanding even.

  39. 19 May 2019 at 1:54 pm

    Hello, i believe that i saw you visited my site thus
    i got here to go back the choose?.I’m trying to to find issues to enhance my web site!I suppose its good enough to make use of a few of your ideas!!

  40. 19 May 2019 at 2:14 pm

    Everything said was very reasonable. But, consider this, suppose you added a
    little content? I ain’t suggesting your content is not good,
    but suppose you added a post title to maybe grab folk’s attention?
    I mean K2 ANZ | Google ReCAPTCHA & K2 is a little vanilla.
    You could look at Yahoo’s front page and see how they write news headlines to get people interested.

    You might add a related video or a pic or two to get readers interested about what you’ve written. In my opinion, it might bring your website a little livelier.

  41. 19 May 2019 at 6:20 pm

    Link exchange is nothing else but it is simply placing the other person’s weblog link on your page at proper place and other person will
    also do similar for you.

  42. 19 May 2019 at 8:14 pm

    I’m not certain the place you’re getting your information, but great topic.
    I must spend some time learning much more or understanding more.
    Thanks for fantastic information I used to be in search
    of this info for my mission.

  43. 19 May 2019 at 9:08 pm

    You’ve made some really good points there. I looked on the internet for more info about
    the issue and found most people will go along with your views
    on this site.

  44. 19 May 2019 at 9:50 pm

    After I originally left a comment I seem to have clicked on the -Notify me when new comments are added-
    checkbox and from now on each time a comment is added I receive 4 emails with the
    exact same comment. Perhaps there is an easy method you are able to remove me from that service?

    Thank you!

  45. 19 May 2019 at 11:20 pm

    I blog frequently and I really thank you for your content.
    This article has really peaked my interest.

    I’m going to take a note of your website and keep checking for new details about once per week.
    I subscribed to your Feed as well.

  46. 20 May 2019 at 12:54 am

    An interesting discussion is worth comment. I believe that you should write
    more on this issue, it might not be a taboo matter but usually people don’t talk
    about such topics. To the next! All the best!!

  47. 20 May 2019 at 5:06 am

    Thank you for sharing your thoughts. I truly appreciate your efforts and I will be waiting for your next write ups thank you once again.

  48. 23 May 2019 at 2:57 pm

    What’s up Dear, are you genuinely visiting this web site daily, if so afterward you will absolutely obtain pleasant know-how.

Leave a Reply

Your email address will not be published.