https://www.ory.sh/ logo
#talk-kratos
Title
# talk-kratos
c

cold-evening-80162

03/24/2022, 1:14 PM
Hi, I would like to configure a web hook after successfull registration but before the indentity is saved in the database. I found this
_After registration:_ is executed when a registration was successful:
_Before persisting:_ runs before the identity is saved in the database.
_After persisting:_ runs after the identity was saved in the database.
in documentation but there is no example on how to configure this correctly in kratos.yml file.
d

damp-sunset-69236

03/24/2022, 1:26 PM
Hello. Have you checked Configuration reference?
c

cold-evening-80162

03/24/2022, 1:29 PM
Hey, yes I checked the configruation reference but there are no indicators on how to set an "before persisting" hook in the "after" logic.
Copy code
## registration ##
    #
    registration:
      
      ## Registration UI URL ##
      #
      # URL where the Registration UI is hosted. Check the [reference implementation](<https://github.com/ory/kratos-selfservice-ui-node>).
      #
      # Default value: <https://www.ory.sh/kratos/docs/fallback/registration>
      #
      # Examples:
      # - <https://my-app.com/signup>
      # 
      # Set this value using environment variables on
      # - Linux/macOS:
      #    $ export SELFSERVICE_FLOWS_REGISTRATION_UI_URL=<value>
      # - Windows Command Line (CMD):
      #    > set SELFSERVICE_FLOWS_REGISTRATION_UI_URL=<value>
      #
      ui_url: <https://my-app.com/signup>

      ## lifespan ##
      #
      # Default value: 1h
      #
      # Examples:
      # - 1h
      # - 1m
      # - 1s
      # 
      # Set this value using environment variables on
      # - Linux/macOS:
      #    $ export SELFSERVICE_FLOWS_REGISTRATION_LIFESPAN=<value>
      # - Windows Command Line (CMD):
      #    > set SELFSERVICE_FLOWS_REGISTRATION_LIFESPAN=<value>
      #
      lifespan: 1h

      ## before ##
      #
      before:
        
        ## hooks ##
        #
        # Set this value using environment variables on
        # - Linux/macOS:
        #    $ export SELFSERVICE_FLOWS_REGISTRATION_BEFORE_HOOKS=<value>
        # - Windows Command Line (CMD):
        #    > set SELFSERVICE_FLOWS_REGISTRATION_BEFORE_HOOKS=<value>
        #
        hooks:
          - hook: web_hook
            config:
              url: <http://a.aaa>
              method: ""
              body: file:///path/to/body.jsonnet
              auth:
                type: api_key
                config:
                  name: ""
                  value: ""
                  in: header
              response:
                ignore: false

      ## after ##
      #
      after:
        
        ## password ##
        #
        password:
          
          ## hooks ##
          #
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS=<value>
          #
          hooks:
            - hook: session

          ## Redirect browsers to set URL per default ##
          #
          # Ory Kratos redirects to this URL per default on completion of self-service flows and other browser interaction. Read this [article for more information on browser redirects](<https://www.ory.sh/kratos/docs/concepts/browser-redirect-flow-completion>).
          #
          # Examples:
          # - <https://my-app.com/dashboard>
          # - /dashboard
          # 
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_DEFAULT_BROWSER_RETURN_URL=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_DEFAULT_BROWSER_RETURN_URL=<value>
          #
          default_browser_return_url: <https://my-app.com/dashboard>

        ## webauthn ##
        #
        webauthn:
          
          ## hooks ##
          #
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_WEBAUTHN_HOOKS=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_WEBAUTHN_HOOKS=<value>
          #
          hooks:
            - hook: session

          ## Redirect browsers to set URL per default ##
          #
          # Ory Kratos redirects to this URL per default on completion of self-service flows and other browser interaction. Read this [article for more information on browser redirects](<https://www.ory.sh/kratos/docs/concepts/browser-redirect-flow-completion>).
          #
          # Examples:
          # - <https://my-app.com/dashboard>
          # - /dashboard
          # 
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_WEBAUTHN_DEFAULT_BROWSER_RETURN_URL=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_WEBAUTHN_DEFAULT_BROWSER_RETURN_URL=<value>
          #
          default_browser_return_url: <https://my-app.com/dashboard>

        ## oidc ##
        #
        oidc:
          
          ## hooks ##
          #
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_OIDC_HOOKS=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_OIDC_HOOKS=<value>
          #
          hooks:
            - hook: session

          ## Redirect browsers to set URL per default ##
          #
          # Ory Kratos redirects to this URL per default on completion of self-service flows and other browser interaction. Read this [article for more information on browser redirects](<https://www.ory.sh/kratos/docs/concepts/browser-redirect-flow-completion>).
          #
          # Examples:
          # - <https://my-app.com/dashboard>
          # - /dashboard
          # 
          # Set this value using environment variables on
          # - Linux/macOS:
          #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_OIDC_DEFAULT_BROWSER_RETURN_URL=<value>
          # - Windows Command Line (CMD):
          #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_OIDC_DEFAULT_BROWSER_RETURN_URL=<value>
          #
          default_browser_return_url: <https://my-app.com/dashboard>

        ## hooks ##
        #
        # Set this value using environment variables on
        # - Linux/macOS:
        #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_HOOKS=<value>
        # - Windows Command Line (CMD):
        #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_HOOKS=<value>
        #
        hooks:
          - hook: web_hook
            config:
              url: <http://a.aaa>
              method: ""
              body: file:///path/to/body.jsonnet
              auth:
                type: api_key
                config:
                  name: ""
                  value: ""
                  in: header
              response:
                ignore: false

        ## Redirect browsers to set URL per default ##
        #
        # Ory Kratos redirects to this URL per default on completion of self-service flows and other browser interaction. Read this [article for more information on browser redirects](<https://www.ory.sh/kratos/docs/concepts/browser-redirect-flow-completion>).
        #
        # Examples:
        # - <https://my-app.com/dashboard>
        # - /dashboard
        # 
        # Set this value using environment variables on
        # - Linux/macOS:
        #    $ export SELFSERVICE_FLOWS_REGISTRATION_AFTER_DEFAULT_BROWSER_RETURN_URL=<value>
        # - Windows Command Line (CMD):
        #    > set SELFSERVICE_FLOWS_REGISTRATION_AFTER_DEFAULT_BROWSER_RETURN_URL=<value>
        #
        default_browser_return_url: <https://my-app.com/dashboard>

      ## Enable User Registration ##
      #
      # If set to true will enable [User Registration](<https://www.ory.sh/kratos/docs/self-service/flows/user-registration/>).
      #
      # Default value: true
      #
      # Set this value using environment variables on
      # - Linux/macOS:
      #    $ export SELFSERVICE_FLOWS_REGISTRATION_ENABLED=<value>
      # - Windows Command Line (CMD):
      #    > set SELFSERVICE_FLOWS_REGISTRATION_ENABLED=<value>
      #
      enabled: false
j

jolly-jelly-9637

03/24/2022, 1:55 PM
I’ve also been looking for this, but looking at the source code this does not exist atm. Webhooks are only executed post-persist. There’s a pull request which I believe would implement this but I don’t think it will be merged soon: https://github.com/ory/kratos/pull/1585 We should look into helping this 🙂
c

cold-evening-80162

03/24/2022, 2:01 PM
Hmm okay, unfortunately I have zero experience with GO, so I would be of no help regarding the PR 😕
6 Views