• Stars
    star
    278
  • Rank 142,799 (Top 3 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ory Kratos NodeJS / ExpressJS User Interface Reference Implementation

tests

This repository contains a reference implementation for Ory Kratos' in NodeJS / ExpressJS / Handlebars / NextJS. It implements all Ory Kratos flows (login, registration, account settings, account recovery, account verification).

If you only want to add authentication to your app, and not customize the login, registration, account recovery, ... screens, please check out the Ory Kratos Quickstart.

Configuration

Below is a list of environment variables required by the Express.js service to function properly.

In a local development run of the service using npm run start, some of these values will be set by nodemon and is configured by the nodemon.json file.

When using this UI with an Ory Network project, you can use ORY_SDK_URL instead of KRATOS_PUBLIC_URL and HYDRA_ADMIN_URL.

Ory Identities requires the following variables to be set:

  • ORY_SDK_URL or KRATOS_PUBLIC_URL (required): The URL where ORY Kratos's Public API is located at. If this app and ORY Kratos are running in the same private network, this should be the private network address (e.g. kratos-public.svc.cluster.local).
  • KRATOS_BROWSER_URL (optional) The browser accessible URL where ORY Kratos's public API is located, only needed if it differs from KRATOS_PUBLIC_URL
  • KRATOS_ADMIN_URL (optional) The URL where Ory Kratos' Admin API is located at (e.g. http://kratos:4434).

Ory OAuth2 requires more setup to get CSRF cookies on the /consent endpoint.

  • ORY_SDK_URL or HYDRA_ADMIN_URL (optional): The URL where Ory Hydra's Admin API is located at. If this app and Ory Hydra are running in the same private network, this should be the private network address (e.g. hydra-admin.svc.cluster.local)
  • COOKIE_SECRET (required): Required for signing cookies. Must be a string with at least 8 alphanumerical characters.
  • CSRF_COOKIE_NAME (required): Change the cookie name to match your domain using the __HOST-example.com-x-csrf-token format.
  • CSRF_COOKIE_SECRET (optional): Required for the Consent route to set a CSRF cookie with a hashed value. The value must be a string with at least 8 alphanumerical characters.
  • REMEMBER_CONSENT_SESSION_FOR_SECONDS (optional): Sets the remember_for value of the accept consent request in seconds. The default is 3600 seconds.
  • ORY_ADMIN_API_TOKEN (optional): When using with an Ory Network project, you should add the ORY_ADMIN_API_TOKEN for OAuth2 Consent flows.
  • DANGEROUSLY_DISABLE_SECURE_CSRF_COOKIES (optional) This environment variables should only be used in local development when you do not have HTTPS setup. This sets the CSRF cookies to secure: false, required for running locally. When using this setting, you must also set CSRF_COOKIE_NAME to a name without the __Host- prefix.
  • TRUSTED_CLIENT_IDS (optional): A list of trusted client ids. They can be set to skip the consent screen.

Getting TLS working:

  • TLS_CERT_PATH (optional): Path to certificate file. Should be set up together with TLS_KEY_PATH to enable HTTPS.
  • TLS_KEY_PATH (optional): Path to key file Should be set up together with TLS_CERT_PATH to enable HTTPS.

This is the easiest mode as it requires no additional set up. This app runs on port :4455 and ORY Kratos KRATOS_PUBLIC_URL URL.

This mode relies on the browser's ability to send cookies regardless of the port. Cookies set for 127.0.0.1:4433 will thus also be sent when requesting 127.0.0.1:4455. For environments where applications run on separate subdomains, check out Multi-Domain Cookies

To authenticate incoming requests, this app uses ORY Kratos' whoami API to check whether the session is valid or not.

Base Path

There are two ways of serving this application under a base path:

  1. Let Express.js handle the routing by setting the BASE_PATH environment variable to the sub-path, e.g. /myapp.
  2. Use a reverse proxy or API gateway to strip the path prefix.

The second approach is not always possible, especially when running the application on a serverless environment. In this case, the first approach is recommended.

Development

To run this app with dummy data and no real connection to ORY Kratos, use:

NODE_ENV=stub npm start

If you would like to also generate fake data for the id_token, please set the environment varialbe export CONFORMITY_FAKE_CLAIMS=1

Test with ORY Kratos

The easiest way to test this app with a local installation of ORY Kratos is to have the ORY Kratos Quickstart running. This is what that would look like:

# start the quickstart using docker compose as explained in the tutorial: https://www.ory.sh/kratos/docs/quickstart/
export KRATOS_PUBLIC_URL=http://127.0.0.1:4433/
export PORT=4455

# In ORY Kratos run the quickstart:
#
#   make quickstart-dev
#
# Next you need to kill the docker container that runs this app in order to free the ports:
#
#   docker kill kratos_kratos-selfservice-ui-node_1

npm start

Update TypeScript SDK

If you've made changes to the ORY Kratos API you may want to manually generate the TypeScript SDK in order for URLs and payloads to work as expected. It is expected that you start this guide from this project's root, wherever you checked it out. You also need to have the openapi-generator installed.

# Set path to kratos:
export KRATOS_DIR=/path/to/kratos
make build-sdk

Building the Docker Image

# Set path to kratos:
export KRATOS_DIR=/path/to/kratos
make build-sdk-docker

Clean up

make clean-sdk

More Repositories

1

hydra

OpenID Certified™ OpenID Connect and OAuth Provider written in Go - cloud native, security-first, open source API security for your infrastructure. SDKs for any language. Works with Hardware Security Modules. Compatible with MITREid.
Go
14,588
star
2

kratos

Next-gen identity server (think Auth0, Okta, Firebase) with Ory-hardened authentication, MFA, FIDO2, TOTP, WebAuthn, profile management, identity schemas, social sign in, registration, account recovery, passwordless. Golang, headless, API-only - without templating or theming headaches. Available as a cloud service.
Go
8,361
star
3

keto

Open Source (Go) implementation of "Zanzibar: Google's Consistent, Global Authorization System". Ships gRPC, REST APIs, newSQL, and an easy and granular permission language. Supports ACL, RBAC, and other access models.
Go
4,528
star
4

dockertest

Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.
Go
3,676
star
5

oathkeeper

A cloud native Identity & Access Proxy / API (IAP) and Access Control Decision API that authenticates, authorizes, and mutates incoming HTTP(s) requests. Inspired by the BeyondCorp / Zero Trust white paper. Written in Go.
Go
3,140
star
6

ladon

A SDK for access control policies: authorization for the microservice and IoT age. Inspired by AWS IAM policies. Written for Go.
Go
2,280
star
7

fosite

Extensible security first OAuth 2.0 and OpenID Connect SDK for Go.
Go
2,218
star
8

k8s

Kubernetes Helm Charts for the ORY ecosystem.
Mustache
322
star
9

hydra-login-consent-node

This is an ExpressJS reference implementation for the ORY Hydra User Login and Consent interface written in TypeScript and ExpressJS.
TypeScript
266
star
10

go-acc

Accurate Code Coverage reporting for Golang (Go)
Go
208
star
11

examples-archive

THIS REPOSITORY IS NOT UP TO DATE. Different docker-based examples for ORY's services (Hydra, Keto, Oathkeeper).
Shell
129
star
12

docs

The Ory documentation
TypeScript
125
star
13

graceful

A best practice http server set up that supports graceful shutdown
Go
123
star
14

sdk

The place where ORY's SDKs are being auto-generated
C#
109
star
15

examples

A curated collection of examples and solutions created and maintained by the Ory Community.
JavaScript
103
star
16

herodot

A lightweight Go library for writing responses and errors to HTTP
Go
82
star
17

kratos-selfservice-ui-react-nextjs

A full reference implementation for designing your own login, registration, recovery, verification, ... pages using Ory Kratos' APIs.
TypeScript
81
star
18

elements

Ory Elements is a component library that makes building login, registration and account pages for Ory a breeze. Check out the components library on Chromatic https://www.chromatic.com/library?appId=63b58e306cfd32348fa48d50
TypeScript
77
star
19

network

Ory runs a global end-to-end security infrastructure for humans, robots, and servers. We build and use open source software.
77
star
20

x

Libraries used in the Ory ecosystem
Go
77
star
21

kratos-selfservice-ui-react-native

A reference implementation of an app using ORY Kratos for auth (login), sign up (registration), profile settings (update password), MFA/2FA, account recovery (password reset), and more for React Native. This repository is available as an expo template!
TypeScript
68
star
22

fosite-example

Go
66
star
23

kratos-client-go

Shell
55
star
24

hydra-consent-app-go

A simple consent app for Hydra written in Go - for Hydra =< 1.0.0
Go
41
star
25

cli

The Ory CLI.
Go
38
star
26

jobs

Want to build the next generation identity stack? You've come to the right place!
37
star
27

hydra-consent-app-express

A simple nodejs consent app based on express - for Hydra =< 1.0.0
JavaScript
37
star
28

hydra-client-go

Shell
34
star
29

osin-storage

PostgreSQL storage backend for RangelReale osin OAuth2
Go
33
star
30

oathkeeper-maester

Kuberenetes CRD Controller for Ory Oathkeeper. ⚠️ Maintained by the community, not an official Ory project!
Go
32
star
31

hydra-maester

Kuberenetes CRD Controller for Ory Hydra. ⚠️ Maintained by the community, not an official Ory project!
Go
29
star
32

web

www.ory.sh
TypeScript
25
star
33

hydra-client-java

Java
25
star
34

kratos-nextjs-react-example

Add login, registration, account recovery (password reset), account verification (email verification), social sign in, multi-factor authentication to your Next.js / React App using Ory!
TypeScript
25
star
35

status

DEPRECATED
Markdown
21
star
36

closed-reference-notifier

A GitHub action to open an issue when GitHub references in your code are closed.
TypeScript
20
star
37

hydra-js

DOES NOT WORK WITH VERSIONS > 0.10.0 - A simple library to help you build node-based identity providers that work with Hydra.
JavaScript
18
star
38

go-convenience

Well-tested helpers for dealing with daily problems in Go.
Go
18
star
39

defcon-30-ctf

Go
17
star
40

redux-saga-fetch

A simple wrapper that reduces boilerplate code when using redux-saga in combination with async backend calls.
TypeScript
16
star
41

hydra-client-php

PHP
15
star
42

meta

A place where we plan and schedule our open source activities and track cross-project and ory-wide issues
Shell
15
star
43

integrations

TypeScript
14
star
44

kratos-client-php

PHP
14
star
45

keto-client-go

Shell
14
star
46

build-buf-action

A GitHub action to build and lint protobuf using buildbuf
Shell
13
star
47

encrypt-dir

A very simple cli helper that encrypts files in directories using AES-GCM (128bit)
Go
13
star
48

summit

This repository holds all material related to the Ory Summit, specifically the presentations.
11
star
49

common

Ory's cross-project go libraries, intended for internal use.
Go
11
star
50

client-go

Shell
11
star
51

docusaurus-template

DEPRECATED
JavaScript
10
star
52

works

This repository shows examples of practical solutions using Ory projects and other OSS
Go
10
star
53

oathkeeper-client-go

Shell
10
star
54

ladon-community

Go
9
star
55

ci

Automation and robots for Ory's CI and CD pipelines
Shell
7
star
56

kratos-client-js

Autogenerated kratos SDK.
7
star
57

keto-client-java

Java
7
star
58

kratos-client-rust

Autogenerated kratos SDK.
Rust
7
star
59

kratos-client-java

Java
6
star
60

oathkeeper-client-php

PHP
6
star
61

keto-client-php

PHP
6
star
62

hydra-auth0-consent-sdk

A NodeJS library for working with Auth0 as an Identity Provider
JavaScript
6
star
63

client-dotnet

Autogenerated client SDK.
C#
6
star
64

kratos-client-ruby

Autogenerated kratos SDK.
Ruby
6
star
65

ory-config

A small Web App for configuring Ory systems built in VueJs 2.x
Vue
6
star
66

ory-sdk-go

Go
6
star
67

pagination

Go
5
star
68

kratos-client-dart

Autogenerated kratos SDK.
Dart
5
star
69

ory-sdk-archive

Shell
5
star
70

client-php

PHP
5
star
71

open-source-support

Are you looking for help above and beyond our community self service support?
5
star
72

milestone-action

JavaScript
5
star
73

eslint-config-ory-am-react

The ESLint configuration used by Ory (React specific)
JavaScript
5
star
74

themes

TypeScript
5
star
75

kratos-maester

5
star
76

hydra-client-js

Autogenerated hydra SDK.
4
star
77

label-sync-action

JavaScript
4
star
78

summit-platform

TypeScript
4
star
79

kratos-client-python

Autogenerated kratos SDK.
Python
4
star
80

keto-maester

4
star
81

metrics-middleware

A simple metrics middleware for segment.io
Go
4
star
82

sdk-js

JavaScript
4
star
83

hydra-client-dart

Autogenerated hydra SDK.
Dart
4
star
84

client-java

Java
4
star
85

homebrew-tap

Location for all of Ory's homebrew packages
Ruby
4
star
86

client-js

Autogenerated client SDK.
4
star
87

eslint-config-ory-am

The ESLint configuration used by Ory
JavaScript
3
star
88

changelog

Ory Changelog Generator
JavaScript
3
star
89

ory-client-go

3
star
90

scoop

3
star
91

slack-invite

3
star
92

oathkeeper-client-dotnet

Autogenerated oathkeeper SDK.
C#
3
star
93

oathkeeper-client-js

Autogenerated oathkeeper SDK.
3
star
94

hydra-oracle-plugin

Go
3
star
95

hydra-client-ruby

Autogenerated hydra SDK.
Ruby
3
star
96

hydra-client-rust

Autogenerated hydra SDK.
Rust
3
star
97

release

Release infrastructure for ORY and related components
HTML
3
star
98

client-python

Autogenerated client SDK.
Python
3
star
99

hydra-client-dotnet

Autogenerated hydra SDK.
C#
3
star
100

homebrew-kratos

Ruby
3
star