Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a support for after_submit webhooks in the login flow #4077

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adpaste
Copy link

@adpaste adpaste commented Sep 4, 2024

Implementation of an after_submit webhook that was discussed in #3580
It allows users to implement rate-limiting in the login process.

Example usage:

selfservice:
    login:
      after_submit:
        hooks:
          - hook: web_hook
            config:
              url: http://127.0.0.1:8080/rate-limit
              method: POST
              body: file:///etc/config/rate-limit.jsonnet

Example jsonnet config:

function(ctx) {
  username: if std.objectHas(ctx.fields, "identifier") then ctx.fields.identifier[0] else null,
  ip: if std.objectHas(ctx.request_headers, "Client-Ip") then ctx.request_headers["Client-Ip"][0] else null
}

You can also send other form fields to the webhook, like this:

function(ctx) {
  method: if std.objectHas(ctx.fields, "method") then ctx.fields.method[0] else null,
  username: if std.objectHas(ctx.fields, "identifier") then ctx.fields.identifier[0] else null,
  ip: if std.objectHas(ctx.request_headers, "Client-Ip") then ctx.request_headers["Client-Ip"][0] else null
}

And implement different rules, for different login methods.

Related issue(s)

Implements #3580

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

@adpaste adpaste marked this pull request as ready for review September 4, 2024 12:18
@adpaste
Copy link
Author

adpaste commented Sep 4, 2024

Please let me know if you have any comments.
One PR check failed, but I don't see why. Is it some random issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant