Skip to main content
Version: v0.2

User Login and User Registration

ORY Kratos supports two type of login and registration flows:

  • Browser-based (easy): This flow works for all applications running on top of a browser. Websites, single-page apps, Cordova/Ionic, and so on.
  • API-based (advanced): This flow works for native applications like iOS (Swift), Android (Java), Microsoft (.NET), React Native, Electron, and others.

The login and registration flows documented here are the foundation for the password and social sign in and sign up strategies.

Self-Service User Login and User Registration for Browser Applications

ORY Kratos supports browser applications that run on server-side (e.g. Java, NodeJS, PHP) as well as client-side (e.g. JQuery, ReactJS, AngularJS, ...).

Browser-based login and registration makes use of three core HTTP technologies:

  • HTTP Redirects
  • HTTP POST (application/json, application/x-www-urlencoded) and RESTful GET requests.
  • HTTP Cookies to prevent CSRF and Session Hijaking attack vectors.

The browser flow is the easiest and most secure to set up and integrated with. ORY Kratos takes care of all required session and CSRF cookies and ensures that all security requirements are fulfilled.

Future versions of ORY Kratos will be able to deal with multi-domain environments that require SSO. For example, one account would be used to sign into both and A common real-world example is using your Google account to seamlessly be signed into YouTube and Google at the same time.

This flow is not suitable for scenarios where you use purely programmatic clients that do not work well with HTTP Cookies and HTTP Redirects.

The Login and Registration User Interface

The Login and Registration User Interface is a route (page / site) in your application that should render a sign in and registration form:

<!-- Login -->
<form action="..." method="POST">
<input type="text" name="identifier" placeholder="Enter your username" />
<input type="password" name="password" placeholder="Enter your password" />
<input type="hidden" name="csrf_token" value="cdef..." />
<input type="submit" />

<!-- Registration -->
<form action="..." method="POST">
<input type="email" name="email" placeholder="Enter your E-Mail Address" />
<input type="password" name="password" placeholder="Enter your password" />
placeholder="Enter your First Name"
<input type="last_name" name="password" placeholder="Enter your Last Name" />
<input type="hidden" name="csrf_token" value="cdef..." />
<input type="submit" />

Once implemented (using e.g. our reference implementation) you reference these routes in your ORY Kratos config file:

login_ui: https://.../login
registration_ui: https://.../registration

Depending on the type of login flows you want to support, you may a also add a "Sign up/in with GitHub" flow:

<!-- Login and Registration -->
<form action="..." method="POST">
<input type="hidden" name="csrf_token" value="cdef..." />

<!-- Basically <a href="">Sign up/in with GitHub</a> -->
<input type="submit" name="provider" value="GitHub" />

In stark contrast to other Identity Systems, ORY Kratos does not render this HTML. Instead, you need to implement the HTML code in your application (e.g. NodeJS + ExpressJS, Java, PHP, ReactJS, ...), which gives you extreme flexibility and customizability in your user interface flows and designs.

Each Login and Registration Strategy (e.g. Username and Password, Social Sign In, Passwordless, ...) works a bit different but they all boil down to the same abstract sequence:

Abstract Login and Registration User Flow

The exact data being fetched and the step "Processes Login / Registration Info" depend, of course, on the actual Strategy being used. But it is important to understand that "Your Application" is responsible for rendering the actual Login and Registration HTML Forms. You can of course implement one app for rendering all the Login, Registration, ... screens, and another app (think "Service Oriented Architecture", "Micro-Services" or "Service Mesh") is responsible for rendering your Dashboards, Management Screens, and so on.


It is RECOMMENDED to put all applications (or "services"), including ORY Kratos, behind a common API Gateway or Reverse Proxy. This greatly reduces the amount of work you have to do to get all the Cookies working properly. We RECOMMEND using ORY Oathkeeper for this as it integrates best with the ORY Ecosystem and because all of our examples use ORY Oathkeeper. You MAY of course use any other reverse proxy (Envoy, AWS API Gateway, Ambassador, Nginx, Kong, ...), but we do not have examples or guides for those at this time.


Because Login and Registration are so similar, we can use one common piece of code to cover both. A functioning example of the code and approach used here can be found on

The code example used here is universal and does not use an SDK because we want you to understand the fundamentals of how this flow works.

Server-side route

While this example assumes a Server-Side Application, a Client-Side (e.g. ReactJS) Application would work the same, but use ORY Kratos' Public API instead.

// Uses the ORY Kratos NodeJS SDK - for more SDKs check:
const { AdminApi } = require('@oryd/kratos-client');

// The browser config key is used to redirect the user. It reflects where ORY Kratos' Public API
// is accessible from. Here, we're assuming traffic going to ``
// will be forwarded to ORY Kratos' Public API.
const kratosBrowserUrl = '';

// Initializes the SDK with ORY Kratos' Admin API.
const adminEndpoint = new AdminApi('https://ory-kratos-admin.example-org.vpc/');

// The parameter "flow" can be "login" and "registration".
// You would register the two routes in express js like this:
// app.get('/auth/registration', authHandler('registration'))
// app.get('/auth/login', authHandler('login'))
export const authHandler = (flow) => (req, res, next) => {
// The request ID is used to identify the login and registraion request and
// return data like the csrf_token and so on.
const request = req.query.request;
if (!request) {
console.log(`No request found in URL, initializing ${flow} flow.`);

const authRequest =
type === 'login'
? adminEndpoint.getSelfServiceBrowserLoginRequest(request)
: adminEndpoint.getSelfServiceBrowserRegistrationRequest(request);

authRequest.then(({ body, response }) => {
if (response.statusCode !== 200) {

// "body" contains all the request data for this Registration request.
// You can process that data here, if you want.

// Lastly, you probably want to render the data using a view (e.g. Jade Template):
res.render(flow, body);
// Handle errors using ExpressJS' next functionality:
// .catch(next)


Your views can be rather simple, as ORY Kratos provides you with all the information you need for rendering the forms. The following example illustrates a generic form generator (we use handlebars here) that works with ORY Kratos:

<form action="{{form.action}}" method="{{form.method}}">
{{~#each form.errors~}}
<!-- global form validation errors -->
<div class="error">{{message}}</div>

{{#each form.fields}}
{{~#each errors~}}
<!-- validation errors for this specific field -->
<div class="error">{{message}}</div>
<input name="{{name}}" type="{{type}}" value="{{value}}" {{#if disabled}}disabled{{/if}}>

<button type="submit">Register</button>

This example also works for the login screen:

<button type="submit">Sign in</button>

In your main "Login" or "Sign Up" view you would then consume this template for all the methods you want to support:

<!-- Username / Email and Password login / sign up form: -->
{{#if methods.password.config}}
{{> form form=methods.password.config}}

<!-- Social sign in/up form: -->
{{#if methods.oidc.config}}
{{> form form=methods.oidc.config}}

<!-- ... form: -->
<!-- ... -->

For details on payloads and potential HTML snippets consult the individual Self-Service Strategies for:

Server-Side Browser Applications

Let's take a look at the concrete network topologies, calls, and payloads. Here, we're assuming that you're running a server-side browser application (written in e.g. PHP, Java, NodeJS) to render the login and registration screen on the server and make all API calls from that server code. The counterpart to this would be a client-side browser application (written in e.g. Vanilla JavaScript, JQuery, ReactJS, AngularJS, ...) that uses AJAX requests to fetch data. For these type of applications, read this section first and go to section Client-Side Browser Applications next.

Network Architecture

We recommend checking out the Quickstart Network Architecture for a high-level, exemplary, overview of the network. In summary:

  1. The SecureApp (your application) is exposed at and proxies requests matching path ./ory/kratos/public/* to ORY Krato's Public API Port.
  2. ORY Kratos exposes (for debugging only!!) the Public API at and Admin API at
  3. Within the "intranet" or "private network", ORY Kratos is exposed at http://kratos:4433 and http://kratos:4434. These URLs are be used by the SecureApp to communicate with ORY Kratos.

Keep in mind that his architecture is just one of many possible network architectures. It is however one of the simplest as well and it works locally. For production deployments you would probably use an Reverse Proxy such as Nginx, Kong, Envoy, ORY Oathkeeper, or others.

User Login and User Registration Process Sequence

The Login and Registration User Flow is composed of several high-level steps summarized in this state diagram:

User Settings State Machine

  1. The Login/Registration User Flow is initiated because a link was clicked or an action was performed that requires an active user session.
  2. ORY Kratos executes Jobs defined in the Before Login/Registration Workflow. If a failure occurs, the whole flow is aborted.
  3. The user's browser is redirected to|registration) (the notation (login|registration) expresses the two possibilities of ../self-service/browser/flows/requests/login or ../self-service/browser/flows/requests/registration).
  4. ORY Kratos does some internal processing (e.g. checks if a session cookie is set, generates payloads for form fields, sets CSRF token, ...) and redirects the user's browser to the Login UI URL which is defined using the urls.login_ui (or urls.registration_ui) config or URLS_LOGIN_UI (or URLS_REGISTRATION_UI) environment variable, which is set to the ui endpoints - for example and The user's browser is thus redirected to|registration)?request=abcde. The request query parameter includes a unique ID which will be used to fetch contextual data for this login request.
  5. Your Server-Side Application makes a GET request to http://kratos:4434/self-service/browser/flows/requests/(login|registration)?request=abcde. ORY Kratos responds with a JSON Payload that contains data (form fields, error messages, ...) for all enabled User Login Strategies:
    id: 'abcde',
    methods: {
    password: { method: 'password', config: { action: '...', fields: [] } },
    oidc: { method: 'oidc', config: { action: '...', fields: [] } },
  6. Your Server-Side applications renders the data however you see fit. The User interacts with it an completes the Login by clicking, for example, the "Login", the "Login with Google", ... button.
  7. The User's browser makes a request to one of ORY Kratos' Strategy URLs (e.g.|registration) or ORY Kratos validates the User's credentials (when logging in - e.g. Username and Password, by performing an OpenID Connect flow, ...) or the registration form data (when signing up - e.g. is the E-Mail address valid, is the person at least 21 years old, ...):
    • If the credentials / form data is invalid, the Login Request's JSON Payload is updated - for example with
      id: 'abcde',
      methods: {
      oidc: {
      method: 'oidc',
      config: {
      /* ... */
      password: {
      method: 'password',
      config: {
      /* ... */
      errors: [
      message: 'The provided credentials are invalid. Check for spelling mistakes in your password or username, email address, or phone number.',
      and the user's Browser is redirected back to the Login UI:|registration)?request=abcde.
    • If credentials / data is valid, ORY Kratos proceeds with the next step.
    • If the flow is a registration request and the registration data is valid, the identity is created.
  8. ORY Kratos executes hooks defined in the After Login/Registration Hooks. If a failure occurs, the whole flow is aborted.
  9. The client receives the expected response. For browsers, this is a HTTP Redirection, for API clients it will be a JSON response containing the session and/or identity. For more information on this topic check Self-Service Flow Completion.

User Login Sequence Diagram for Server-Side Applications

Client-Side Browser Applications

Because Client-Side Browser Applications do not have access to ORY Kratos' Admin API, they must use the ORY Kratos Public API instead. The flow for a Client-Side Browser Application is almost the exact same as the one for Server-Side Applications, with the small difference that would be called via AJAX instead of making a request to https://kratos:4434/self-service/browser/flows/requests/login?request=abcde.

To prevent brute force, guessing, session injection, and other attacks, it is required that cookies are working for this endpoint. The cookie set in the initial HTTP request made to MUST be set and available when calling this endpoint!


The initialization request (|registration)) cannot be made via AJAX or API requests. You must open that URL in the user's browser using e.g. location.href or plain and simple old <a href=...>.

Self-Service User Login and User Registration for API Clients

Will be addressed in a future release.


ORY Kratos allows you to configure hooks that run before and after a Login or Registration Request is generated. This may be helpful if you'd like to restrict logins to IPs coming from your internal network or other logic.

For more information about hooks please read the Hook Documentation.