Skip to main content

RecaptchaExtension

RecaptchaExtension​

To use recaptcha extension in the graphql field, add the following line in the field:

  field :login,
mutation: Mutations::Auth::Login,
extensions: [
CmGraphql::Extensions::RecaptchaExtension
]
# With options
field :login,
mutation: Mutations::Auth::Login,
extensions: [
{ CmGraphql::Extensions::RecaptchaExtension => { action: 'login', minimum_score: 0.5 } }
]

Sample request​

mutation Login {
login(input: {
email: "anbu+5@commutatus.com"
}, recaptchaToken: "recaptcha_token") {
accessToken
expiresAt
}
}

Arguments:​

  • action: Action name. It will be mandatory unless field_name and action passed are not same. For eg: login is the field_name, so the action option can be ignored.
  • minimum_score: Minimum score for recaptcha. It will be optional. If not provided, it will use the RECAPTCHA_MINIMUM_SCORE constant.

Credentials​

Please create google recaptcha account from google console Please update the credentials for recaptcha, format will be

gcp:
recaptcha_site_key: 'your_site_key'
recaptcha_secret_key: 'your_secret_key'

To override the minimum score for recaptcha instead of using options, add the following line in config/initializers/constants.rb:

RECAPTCHA_MINIMUM_SCORE = 0.5

Note​

  • RecaptchaExtension verfier module is derived from the gem recaptcha