hey everyone, how can i get the session token with...
# general
g
hey everyone, how can i get the session token with curl command?
p
Hi You need to do the
api
flow using curl through 2 steps. 1. Create an initial request for login / registration
Copy code
curl https://<kratos-url>/self-service/registration/api | jq

{
  "id": "8289b32a-4d06-4a13-933b-e366b5584c6b",
  "type": "api",
  "expires_at": "2022-04-19T13:21:59.503301853Z",
  "issued_at": "2022-04-19T12:21:59.503301853Z",
  "request_url": "http://<kratos-url>/self-service/registration/api",
  "ui": {
    "action": "https://<kratos-url>/self-service/registration?flow=8289b32a-4d06-4a13-933b-e366b5584c6b",
    "method": "POST",
    "nodes": [
      {
        "type": "input",
        "group": "default",
        "attributes": {
          "name": "csrf_token",
          "type": "hidden",
          "value": "",
          "required": true,
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {}
      },
      {
        "type": "input",
        "group": "password",
        "attributes": {
          "name": "traits.username",
          "type": "text",
          "required": true,
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1070002,
            "text": "Username",
            "type": "info"
          }
        }
      },
      {
        "type": "input",
        "group": "password",
        "attributes": {
          "name": "password",
          "type": "password",
          "required": true,
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1070001,
            "text": "Password",
            "type": "info"
          }
        }
      },
      {
        "type": "input",
        "group": "password",
        "attributes": {
          "name": "method",
          "type": "submit",
          "value": "password",
          "disabled": false,
          "node_type": "input"
        },
        "messages": [],
        "meta": {
          "label": {
            "id": 1040001,
            "text": "Sign up",
            "type": "info",
            "context": {}
          }
        }
      }
    ]
  }
}
2. Finish the flow with a post request and body using the "action" url from the previous response.
Copy code
curl -X POST https://<kratos-url>/self-service/registration\?flow\=8289b32a-4d06-4a13-933b-e366b5584c6b --header "Content-Type: application/json" --data '{"traits.username":"<mailto:example@example.com|example@example.com>", "password":"some-password","method":"password"}' | jq

{
  "session_token": "NVXNhOaTaBc7rrRH7oxP6XM0YdMNgJqy",
  "session": {
    "id": "7749e3f9-3c28-4657-b2d8-9c95a1818310",
    "active": true,
    "expires_at": "2022-04-22T12:18:52.13506223Z",
    "authenticated_at": "2022-04-19T12:18:52.209302765Z",
    "authenticator_assurance_level": "aal1",
    "authentication_methods": [
      {
        "method": "password",
        "aal": "aal1",
        "completed_at": "2022-04-19T12:18:52.13518948Z"
      }
    ],
    "issued_at": "2022-04-19T12:18:52.13506223Z",
    "identity": {
      "id": "25d228fc-89ff-4a28-a9a3-41baaca4d5cc",
      "schema_id": "<schema-id>",
      "schema_url": "https://<kratos-url>/schemas/<schema-id>",
      "state": "active",
      "state_changed_at": "2022-04-19T12:18:52.021513516Z",
      "traits": {
        "username": "<mailto:example@example.com|example@example.com>"
      },
      "verifiable_addresses": [
        {
          "id": "60e5a350-9f5c-4491-96f1-637e27c2a08f",
          "value": "<mailto:example@example.com|example@example.com>",
          "verified": false,
          "via": "email",
          "status": "sent",
          "created_at": "2022-04-19T12:18:52.054958Z",
          "updated_at": "2022-04-19T12:18:52.054958Z"
        }
      ],
      "recovery_addresses": [
        {
          "id": "e9edbe51-17c5-4a0d-ac16-6344f74090cb",
          "value": "<mailto:example@example.com|example@example.com>",
          "via": "email",
          "created_at": "2022-04-19T12:18:52.062664Z",
          "updated_at": "2022-04-19T12:18:52.062664Z"
        }
      ],
      "created_at": "2022-04-19T12:18:52.033054Z",
      "updated_at": "2022-04-19T12:18:52.033054Z"
    }
  },
  "identity": {
    "id": "25d228fc-89ff-4a28-a9a3-41baaca4d5cc",
    "schema_id": "<schema-id>",
    "schema_url": "https://<kratos-url>/schemas/<schema-id>",
    "state": "active",
    "state_changed_at": "2022-04-19T12:18:52.021513516Z",
    "traits": {
      "username": "<mailto:example@example.com|example@example.com>"
    },
    "verifiable_addresses": [
      {
        "id": "60e5a350-9f5c-4491-96f1-637e27c2a08f",
        "value": "<mailto:example@example.com|example@example.com>",
        "verified": false,
        "via": "email",
        "status": "sent",
        "created_at": "2022-04-19T12:18:52.054958Z",
        "updated_at": "2022-04-19T12:18:52.054958Z"
      }
    ],
    "recovery_addresses": [
      {
        "id": "e9edbe51-17c5-4a0d-ac16-6344f74090cb",
        "value": "<mailto:example@example.com|example@example.com>",
        "via": "email",
        "created_at": "2022-04-19T12:18:52.062664Z",
        "updated_at": "2022-04-19T12:18:52.062664Z"
      }
    ],
    "created_at": "2022-04-19T12:18:52.033054Z",
    "updated_at": "2022-04-19T12:18:52.033054Z"
  }
}