Passing additional fields through the user service flows that aren't stored in the kratos db but can be used on the webhooks #2036
-
Hi, Use case: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @MilesNorton, Yes, you can pass along headers, URL parameters and identity traits. Of course in your case, you would probably want to opt for using URL parameters. To get this right you can use the provided templateContext struct {
Flow flow.Flow `json:"flow"`
RequestHeaders http.Header `json:"request_headers"`
RequestMethod string `json:"request_method"`
RequestUrl string `json:"request_url"`
Identity *identity.Identity `json:"identity"`
} func (e *WebHook) ExecutePostRegistrationPostPersistHook(_ http.ResponseWriter, req *http.Request, flow *registration.Flow, session *session.Session) error {
return e.execute(&templateContext{
Flow: flow,
RequestHeaders: req.Header,
RequestMethod: req.Method,
RequestUrl: req.RequestURI,
Identity: session.Identity,
})
} So to get for instance the function(ctx) {
request_url: ctx.request_url
} This will pass along the request_url to the JSON key Then inside my registration:
lifespan: 10m
ui_url: http://127.0.0.1:4455/registration
after:
password:
hooks:
-
hook: session
-
hook: web_hook
config:
url: http://<some_external_url>/group
method: POST
body: file:///etc/config/kratos/f.jsonnet On the registration submission, I add a I have a small gin server catching the result: func main() {
r := gin.Default()
r.POST("/group", func(c *gin.Context) {
out, _ := c.GetRawData()
fmt.Printf("data: %s", string(out))
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run("0.0.0.0:5555")
} The output? [GIN-debug] Listening and serving HTTP on 0.0.0.0:5555
data: {
"request_url": "/self-service/registration?flow=040e2073-2ca6-4459-9082-650546be5e3b&group=hello"
}
[GIN] 2021/12/08 - 10:49:23 | 200 | 76.866µs | 172.18.0.5 | POST "/group" |
Beta Was this translation helpful? Give feedback.
Hi @MilesNorton,
Yes, you can pass along headers, URL parameters and identity traits. Of course in your case, you would probably want to opt for using URL parameters.
To get this right you can use the provided
ctx
variable inside of your jssonet file. Here is an excerpt of what Kratos injects for you:source