Hey Folks! Is there a way in kratos to make verifi...
# talk-kratos
c
Hey Folks! Is there a way in kratos to make verification of an email mandatory for login after every N number of days? version: v0.10.1
f
Hi Gowri, did you check the Kratos Admin API? I guess you can update VerifiableIdentityAddress status after N number of days or any other custom logic
c
Hi Andrii, Thankyou, I have tried to update VerifiableIdentityAddress through Admin API but it doesn't update the verified status
f
it should be possible to update
can you share more info of your funcs calls?
c
I am trying with the postman, this how the req curl looks like:
Copy code
curl --location --request PUT '<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "923dcc29-9ff2-473f-ac03-bd603c5082cc",
    "schema_id": "default",
    "schema_url": "<http://127.0.0.1:4433/schemas/ZGVmYXVsdA>",
    "verifiable_addresses": [
        {
            "id": "bdcf18fa-5f18-43fc-a3d3-12ace86c139c",
            "value": "<mailto:gowri@xyz.com|gowri@xyz.com>",
            "verified": false
        }
    ]
}'
this is the error, I am getting
Copy code
{
  "error": {
    "code": 500,
    "status": "Internal Server Error",
    "message": "invalid character '}' looking for beginning of value"
  }
}
f
I think PUT is for creating. For update I guess you need POST
just check the docs. PUT is right )
b
@colossal-airline-19852 that command looks right, but the error message indicates your payload is malformed. Please double-check that the JSON you’re sending is not malformed.
status and via fields are missing in your request body
c
Copy code
curl --location --request PUT '<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "923dcc29-9ff2-473f-ac03-bd603c5082cc",
    "schema_id": "default",
    "schema_url": "<http://127.0.0.1:4433/schemas/ZGVmYXVsdA>",
    "verifiable_addresses": [
        {
            "id": "bdcf18fa-5f18-43fc-a3d3-12ace86c139c",
            "value": "<mailto:gowri@xyz.com|gowri@xyz.com>",
            "verified": false,
            "via": "email",
            "status": "sent"
        }
    ]
}'
I have tried by adding
status
and
via
to payload, but it is the same error, @bland-eye-99092 I have verified the JSON, it isn't malformed, I am not sure why response is like this
Copy code
{
  "error": {
    "code": 500,
    "status": "Internal Server Error",
    "message": "invalid character '}' looking for beginning of value"
  }
}
f
what about logs from kratos?
Copy code
log:
  level: info # trace | debug | info | warning | error | fatal | panic
I would use debug for tests
c
Copy code
kratos-local-kratos-1                      | time=2022-11-25T12:04:51Z level=error msg=An error occurred while handling a request func=<http://github.com/ory/x/logrusx.(*Logger).ReportError|github.com/ory/x/logrusx.(*Logger).ReportError> file=/go/pkg/mod/github.com/ory/x@v0.0.392/logrusx/logrus.go:228 audience=application error=map[message:invalid character '}' looking for beginning of value stack_trace:
kratos-local-kratos-1                      | <http://github.com/ory/kratos/schema.(*Validator).Validate|github.com/ory/kratos/schema.(*Validator).Validate>
kratos-local-kratos-1                      |    /project/schema/validator.go:69
kratos-local-kratos-1                      | <http://github.com/ory/kratos/identity.(*Validator).ValidateWithRunner|github.com/ory/kratos/identity.(*Validator).ValidateWithRunner>
kratos-local-kratos-1                      |    /project/identity/validator.go:51
kratos-local-kratos-1                      | <http://github.com/ory/kratos/identity.(*Validator).Validate|github.com/ory/kratos/identity.(*Validator).Validate>
kratos-local-kratos-1                      |    /project/identity/validator.go:55
kratos-local-kratos-1                      | <http://github.com/ory/kratos/identity.(*Manager).validate|github.com/ory/kratos/identity.(*Manager).validate>
kratos-local-kratos-1                      |    /project/identity/manager.go:160
kratos-local-kratos-1                      | <http://github.com/ory/kratos/identity.(*Manager).Update|github.com/ory/kratos/identity.(*Manager).Update>
kratos-local-kratos-1                      |    /project/identity/manager.go:94
kratos-local-kratos-1                      | <http://github.com/ory/kratos/identity.(*Handler).update|github.com/ory/kratos/identity.(*Handler).update>
kratos-local-kratos-1                      |    /project/identity/handler.go:475
kratos-local-kratos-1                      | <http://github.com/ory/kratos/x.NoCacheHandle.func1|github.com/ory/kratos/x.NoCacheHandle.func1>
kratos-local-kratos-1                      |    /project/x/nocache.go:18
kratos-local-kratos-1                      | <http://github.com/julienschmidt/httprouter.(*Router).ServeHTTP|github.com/julienschmidt/httprouter.(*Router).ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/julienschmidt/httprouter@v1.3.0/router.go:387
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.Wrap.func1|github.com/urfave/negroni.Wrap.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:46
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.HandlerFunc.ServeHTTP|github.com/urfave/negroni.HandlerFunc.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:29
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.middleware.ServeHTTP|github.com/urfave/negroni.middleware.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerResponseSize.func1|github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerResponseSize.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/prometheus/client_golang@v1.11.0/prometheus/promhttp/instrument_server.go:198
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerCounter.func1|github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerCounter.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/prometheus/client_golang@v1.11.0/prometheus/promhttp/instrument_server.go:101
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func1|github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/prometheus/client_golang@v1.11.0/prometheus/promhttp/instrument_server.go:68
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func2|github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func2>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/prometheus/client_golang@v1.11.0/prometheus/promhttp/instrument_server.go:76
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerRequestSize.func1|github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerRequestSize.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/prometheus/client_golang@v1.11.0/prometheus/promhttp/instrument_server.go:165
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/ory/x/prometheusx.Metrics.instrumentHandlerStatusBucket.func1|github.com/ory/x/prometheusx.Metrics.instrumentHandlerStatusBucket.func1>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/ory/x@v0.0.392/prometheusx/metrics.go:108
kratos-local-kratos-1                      | net/http.HandlerFunc.ServeHTTP
kratos-local-kratos-1                      |    /usr/local/go/src/net/http/server.go:2047
kratos-local-kratos-1                      | <http://github.com/ory/x/prometheusx.(*MetricsManager).ServeHTTP|github.com/ory/x/prometheusx.(*MetricsManager).ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/ory/x@v0.0.392/prometheusx/middleware.go:30
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.middleware.ServeHTTP|github.com/urfave/negroni.middleware.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38
kratos-local-kratos-1                      | <http://github.com/ory/x/metricsx.(*Service).ServeHTTP|github.com/ory/x/metricsx.(*Service).ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/ory/x@v0.0.392/metricsx/middleware.go:275
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.middleware.ServeHTTP|github.com/urfave/negroni.middleware.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38
kratos-local-kratos-1                      | <http://github.com/ory/kratos/x.HTTPLoaderContextMiddleware.func1|github.com/ory/kratos/x.HTTPLoaderContextMiddleware.func1>
kratos-local-kratos-1                      |    /project/x/httploadermiddleware.go:20
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.HandlerFunc.ServeHTTP|github.com/urfave/negroni.HandlerFunc.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:29
kratos-local-kratos-1                      | <http://github.com/urfave/negroni.middleware.ServeHTTP|github.com/urfave/negroni.middleware.ServeHTTP>
kratos-local-kratos-1                      |    /go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38
kratos-local-kratos-1                      | <http://github.com/ory/kratos/x.RedirectAdminMiddleware|github.com/ory/kratos/x.RedirectAdminMiddleware>
kratos-local-kratos-1                      |    /project/x/http_redirect_admin.go:22] http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:383 content-type:application/json postman-token:d5b13ab9-481a-4e71-aa07-18a7d4e6dd8f referer:<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/> user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc query:<nil> remote:172.19.0.1:59922 scheme:http] http_response=map[status_code:500] service_name=Ory Kratos service_version=v0.10.1
kratos-local-kratos-1                      | time=2022-11-25T12:04:51Z level=info msg=completed handling request func=<http://github.com/ory/x/reqlog.(*Middleware).ServeHTTP|github.com/ory/x/reqlog.(*Middleware).ServeHTTP> file=/go/pkg/mod/github.com/ory/x@v0.0.392/reqlog/middleware.go:139 http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:383 content-type:application/json postman-token:d5b13ab9-481a-4e71-aa07-18a7d4e6dd8f referer:<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/> user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc query:<nil> remote:172.19.0.1:59922 scheme:http] http_response=map[headers:map[cache-control:private, no-cache, no-store, must-revalidate content-type:application/json] size:121 status:500 text_status:Internal Server Error took:13.193084ms]
f
Copy code
ror=map[message:invalid character '}'
b
The issue is most likely that you’re expected to PUT the whole identity to the endpoint. PUT overrides all fields of the identity but since you’re omitting fields like
traits
or
credentials
they don’t validate. You’re looking for the
PATCH
endpoint. Unfortunately, that is not yet released on a stable release. However #ory-network supports it already.
c
@faint-insurance-61054 Yeah, but the JSON payload is valid
Copy code
{
  "id": "923dcc29-9ff2-473f-ac03-bd603c5082cc",
  "schema_id": "default",
  "schema_url": "<http://127.0.0.1:4433/schemas/ZGVmYXVsdA>",
  "verifiable_addresses": [
    {
      "id": "bdcf18fa-5f18-43fc-a3d3-12ace86c139c",
      "value": "<mailto:gowri@xyz.com|gowri@xyz.com>",
      "verified": false,
      "via": "email",
      "status": "sent"
    }
  ]
}
f
you need to have traits ..
c
@faint-insurance-61054 Initially I have tried with full payload put call, there is no error in the response but it wasn't updating the field (
verified
) in the
verifiable_addresses
f
for me it works via Golang SDK. It is hard to say about REST. I didn’t play with that
maybe you could try and check debug logs again?
c
I have checked the logs, I can see the same error
Copy code
error=map[message:invalid character '}'
however the response is 200
f
so validation didn’t pass
200 is strange in this case
can you please paste here the full payload?
c
Copy code
{
  "id": "923dcc29-9ff2-473f-ac03-bd603c5082cc",
  "schema_id": "default",
  "schema_url": "<http://127.0.0.1:4433/schemas/ZGVmYXVsdA>",
  "state": "active",
  "state_changed_at": "2022-11-25T10:49:03.53584646Z",
  "traits": {
    "email": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
    "name": {
      "first": "Mathan",
      "last": "A"
    }
  },
  "verifiable_addresses": [
    {
      "id": "bdcf18fa-5f18-43fc-a3d3-12ace86c139c",
      "value": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
      "verified": false,
      "via": "email",
      "status": "completed",
      "verified_at": "2022-11-25T11:17:02.251347876Z",
      "created_at": "2022-11-25T10:49:03.538163Z",
      "updated_at": "2022-11-25T11:17:42.810537Z"
    }
  ],
  "recovery_addresses": [
    {
      "id": "b39e5eea-8442-482a-81e2-93a92f2cd2cb",
      "value": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
      "via": "email",
      "created_at": "2022-11-25T10:49:03.538469Z",
      "updated_at": "2022-11-25T11:17:42.810818Z"
    }
  ],
  "metadata_public": null,
  "metadata_admin": null,
  "created_at": "2022-11-25T10:49:03.537749Z",
  "updated_at": "2022-11-25T10:49:03.537749Z"
}
f
you have verified_at in request
if verified=false, verified_at must be nullable
c
I have removed it and tried, still have no luck also changed the
status
to
sent
just in case
f
in logs the same error?
what about traits schema?
did you pass all required fields?
c
Copy code
{
  "id": "923dcc29-9ff2-473f-ac03-bd603c5082cc",
  "schema_id": "default",
  "schema_url": "<http://127.0.0.1:4433/schemas/ZGVmYXVsdA>",
  "state": "active",
  "state_changed_at": "2022-11-25T10:49:03.53584646Z",
  "traits": {
    "email": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
    "name": {
      "first": "Mathan",
      "last": "A"
    }
  },
  "verifiable_addresses": [
    {
      "id": "bdcf18fa-5f18-43fc-a3d3-12ace86c139c",
      "value": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
      "verified": false,
      "via": "email",
      "status": "sent",
      "created_at": "2022-11-25T10:49:03.538163Z",
      "updated_at": "2022-11-25T11:17:42.810537Z"
    }
  ],
  "recovery_addresses": [
    {
      "id": "b39e5eea-8442-482a-81e2-93a92f2cd2cb",
      "value": "<mailto:mathan@xflowpay.com|mathan@xflowpay.com>",
      "via": "email",
      "created_at": "2022-11-25T10:49:03.538469Z",
      "updated_at": "2022-11-25T11:17:42.810818Z"
    }
  ],
  "metadata_public": null,
  "metadata_admin": null,
  "created_at": "2022-11-25T10:49:03.537749Z",
  "updated_at": "2022-11-25T10:49:03.537749Z"
}
Now I have sent without the verified_at No error in the logs, but still the verified value not getting updated
logs:
Copy code
kratos-local-kratos-1                      | time=2022-11-25T12:46:04Z level=info msg=started handling request func=<http://github.com/ory/x/reqlog.(*Middleware).ServeHTTP|github.com/ory/x/reqlog.(*Middleware).ServeHTTP> file=/go/pkg/mod/github.com/ory/x@v0.0.392/reqlog/middleware.go:131 http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:1182 content-type:application/json postman-token:59c748b0-f3c3-4663-b6ea-d7aa87ea8e72 user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/ query:<nil> remote:172.19.0.1:60606 scheme:http]
kratos-local-kratos-1                      | time=2022-11-25T12:46:04Z level=info msg=completed handling request func=<http://github.com/ory/x/reqlog.(*Middleware).ServeHTTP|github.com/ory/x/reqlog.(*Middleware).ServeHTTP> file=/go/pkg/mod/github.com/ory/x@v0.0.392/reqlog/middleware.go:139 http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:1182 content-type:application/json postman-token:59c748b0-f3c3-4663-b6ea-d7aa87ea8e72 user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc query:<nil> remote:172.19.0.1:60606 scheme:http] http_response=map[headers:map[location:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc] size:0 status:307 text_status:Temporary Redirect took:150.125µs]
kratos-local-kratos-1                      | time=2022-11-25T12:46:04Z level=info msg=started handling request func=<http://github.com/ory/x/reqlog.(*Middleware).ServeHTTP|github.com/ory/x/reqlog.(*Middleware).ServeHTTP> file=/go/pkg/mod/github.com/ory/x@v0.0.392/reqlog/middleware.go:131 http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:1182 content-type:application/json postman-token:59c748b0-f3c3-4663-b6ea-d7aa87ea8e72 referer:<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/> user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc query:<nil> remote:172.19.0.1:60606 scheme:http]
kratos-local-kratos-1                      | time=2022-11-25T12:46:04Z level=info msg=completed handling request func=<http://github.com/ory/x/reqlog.(*Middleware).ServeHTTP|github.com/ory/x/reqlog.(*Middleware).ServeHTTP> file=/go/pkg/mod/github.com/ory/x@v0.0.392/reqlog/middleware.go:139 http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br cache-control:no-cache connection:keep-alive content-length:1182 content-type:application/json postman-token:59c748b0-f3c3-4663-b6ea-d7aa87ea8e72 referer:<http://127.0.0.1:4434/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc/> user-agent:PostmanRuntime/7.29.2] host:127.0.0.1:4434 method:PUT path:/admin/identities/923dcc29-9ff2-473f-ac03-bd603c5082cc query:<nil> remote:172.19.0.1:60606 scheme:http] http_response=map[headers:map[cache-control:private, no-cache, no-store, must-revalidate content-type:application/json; charset=utf-8] size:1067 status:200 text_status:OK took:29.653667ms]
f
can you try with status”: “pending”, “?
I expect this could be a reason
c
I have tried with status pending, and still no luck
btw I am using
v0.10.1
of kratos
f
verified_at returned the same. Can you try to send null there?
c
still no change in the response
f
I have no more ideas (
c
As we discussed offline, I can only achieve this with the PATCH call using the latest
master
code. means I will have to wait for the next release. cc: @steep-lamp-91158 Thanks @faint-insurance-61054 for the help so far, really appreciated 🙌.