high-magician-68236
06/24/2024, 7:35 AMchilly-king-10285
06/24/2024, 7:35 AMchilly-king-10285
06/24/2024, 7:36 AMbash git clone <https://github.com/ory/kratos.git> cd kratos git checkout v0.8.0-alpha.3
[Source](https://www.ory.sh/docs/kratos/guides/zero-trust-iap-proxy-identity-access-proxy#running-ory-kratos-and-the-ory-oathkeeper-identity-and-access-proxy) 2. Run the quickstart and add the Ory Oathkeeper config: bash docker-compose \ -f quickstart.yml \ -f quickstart-oathkeeper.yml \ up --build --force-recreate
[Source](https://www.ory.sh/docs/kratos/guides/zero-trust-iap-proxy-identity-access-proxy#running-ory-kratos-and-the-ory-oathkeeper-identity-and-access-proxy) 3. Set up an OAuth 2.0 Client: bash docker run --rm -it \ -e HYDRA_ADMIN_URL=<https://ory-hydra-example--hydra:4445> \ --network hydraguide \ oryd/hydra:v1.10.6 \ clients create --skip-tls-verify \ --id facebook-photo-backup \ --secret some-secret \ --grant-types authorization_code,refresh_token,client_credentials,implicit \ --response-types token,code,id_token \ --scope openid,offline,photos.read \ --callbacks <http://127.0.0.1:9010/callback>
[Source](https://www.ory.sh/docs/hydra/self-hosted/configure-deploy#perform-oauth-20-flow) 4. Perform the OAuth 2.0 Flow: bash --token-url <https://ory-hydra-example--hydra:4444/oauth2/token> \ --client-id facebook-photo-backup \ --client-secret some-secret \ --scope openid,offline,photos.read
[Source](https://www.ory.sh/docs/hydra/self-hosted/configure-deploy#perform-oauth-20-flow) Please note that you need to replace facebook-photo-backup
and some-secret
with your actual client id and secret. Also, make sure that ports 4433
, 4434
, 4436
, 4455
, and 4456
are free and always use 127.0.0.1
as the hostname; never use localhost
! This is important because browsers treat these two as separate domains and will therefore have issues with setting and using the right cookies. Once you have set up everything correctly, you should be able to access your application locally.high-magician-68236
06/24/2024, 7:54 AMchilly-king-10285
06/24/2024, 7:54 AMchilly-king-10285
06/24/2024, 7:55 AMbash sudo apt install postgresql postgresql-contrib sudo -i -u postgres
Then create the database: bash createdb hydra
[Source](https://www.ory.sh/docs/hydra/self-hosted/deploy-hydra-example#install-postgresql) 2. Install Ory Hydra: First, create a new user and folders to hold the installation data and configuration files: bash useradd -s /bin/false -m -d /opt/hydra hydra mkdir /opt/hydra/{bin,config}
Then, download and install Ory Hydra: bash cd /opt/hydra/bin wget <https://github.com/ory/hydra/releases/download/<version-you-want>/hydra_<version-you-want>-linux_64bit.tar.gz> tar xfvz hydra_<version-you-want>-linux_64bit.tar.gz rm *md rm LICENSE
[Source](https://www.ory.sh/docs/hydra/self-hosted/deploy-hydra-example#install-ory-hydra) 3. Configure Ory Hydra to use PostgreSQL: Open hydra.yml
and change the DSN configuration to use the Postgres database you configured before: bash dsn: <postgres://hydra:[[email> protected]](<https://www.ory.sh/cdn-cgi/l/email-protection>):5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4 urls: self: issuer: <https://oauth2.example.com>
[Source](https://www.ory.sh/docs/hydra/self-hosted/deploy-hydra-example#install-ory-hydra) 4. Apply migrations: bash /opt/hydra/bin/hydra -c /opt/hydra/config/hydra.yml migrate sql -y <postgres://hydra:[[email> protected]](<https://www.ory.sh/cdn-cgi/l/email-protection>):5432/hydra?sslmode=disable
[Source](https://www.ory.sh/docs/hydra/self-hosted/deploy-hydra-example#install-ory-hydra) 5. Test your setup: bash /opt/hydra/bin/hydra -c /opt/hydra/config/hydra.yml serve all
[Source](https://www.ory.sh/docs/hydra/self-hosted/deploy-hydra-example#install-ory-hydra) Please note that you need to replace <version-you-want>
with the actual version of Ory Hydra you want to install. Also, replace <https://oauth2.example.com>
with your actual issuer URL. For Ory Oathkeeper, you can follow the [official Ory Oathkeeper guide](https://www.ory.sh/oathkeeper/docs/) to set it up. For Ory Kratos, you can follow the [official Ory Kratos guide](https://www.ory.sh/kratos/docs/) to set it up. Remember to set up your environment variables to connect with Ory's APIs: bash export ORY_SDK_URL=https://{project.slug}.<http://projects.oryapis.com|projects.oryapis.com>
[Source](https://www.ory.sh/docs/getting-started/integrate-auth/react#run-your-react-app) Once you have set up everything correctly, you should be able to access your application locallyhigh-magician-68236
06/24/2024, 7:57 AMchilly-king-10285
06/24/2024, 7:57 AMchilly-king-10285
06/24/2024, 7:57 AMbash sudo apt install postgresql postgresql-contrib -y sudo -i -u postgres
Then create the database: bash createdb kratos
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-postgresql) 2. Change the default password encryption to a stronger one: bash psql ALTER SYSTEM SET password_encryption = 'scram-sha-256'; SELECT pg_reload_conf();
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-postgresql) 3. Create a user for Kratos: bash CREATE USER kratos PASSWORD '<YOUR_PASSWORD_HERE>';
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-postgresql) 4. Give the newly created account access to the database: bash GRANT CONNECT ON DATABASE kratos to kratos;
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-postgresql) 5. Install Ory Kratos: First, create a new user and folders to hold the installation data and configuration files: bash useradd -s /bin/false -m -d /opt/kratos kratos mkdir /opt/kratos/{bin,config}
Then, download and install Ory Kratos: bash cd /opt/kratos/bin wget <https://github.com/ory/kratos/releases/download/<version-you-want>/kratos_<version-you-want>-linux_64bit.tar.gz> tar xfvz kratos_<version-you-want>-linux_64bit.tar.gz rm *md rm LICENSE
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-ory-kratos) 6. Configure Ory Kratos to use PostgreSQL: Open kratos.yml
and change the DSN configuration to use the Postgres database you configured before: bash dsn: <postgres://kratos:<YOUR_PASSWORD_HERE>@localhost:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4>
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-ory-kratos) 7. Apply migrations: bash /opt/kratos/bin/kratos -c /opt/kratos/config/kratos.yml migrate sql -y <postgres://kratos:<YOUR_PASSWORD_HERE>@localhost:5432/kratos?sslmode=disable>
[Source](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-ory-kratos) Please note that you need to replace <version-you-want>
with the actual version of Ory Kratos you want to install, and <YOUR_PASSWORD_HERE>
with the password you set for the kratos
user in PostgreSQL. Once you have set up everything correctly, you should be able to access your application locally.high-magician-68236
06/24/2024, 8:16 AMversion: '3.9'
services:
postgres:
image: postgres:14-alpine
ports:
- 5432:5432
volumes:
- ./db/data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=test
- POSTGRES_USER=test
- POSTGRES_DB=test
chilly-king-10285
06/24/2024, 8:17 AMchilly-king-10285
06/24/2024, 8:17 AMbash docker-compose up -d
This will start your PostgreSQL database in the background. 2. Configure Ory Kratos to use your PostgreSQL database: In your Kratos configuration file (kratos.yml
), set the DSN (Data Source Name) to your PostgreSQL database: bash dsn: <postgres://test:[email> protected]:5432/test?sslmode=disable&max_conns=20&max_idle_conns=4
[Source](https://www.ory.sh/docs/kratos/quickstart#next-steps) 3. Configure Ory Hydra to use your PostgreSQL database: In your Hydra configuration file (hydra.yml
), set the DSN to your PostgreSQL database: bash dsn: <postgres://test:[email> protected]:5432/test?sslmode=disable&max_conns=20&max_idle_conns=4
[Source](https://www.ory.sh/docs/hydra/self-hosted/dependencies-environment#database-configuration) 4. Configure Ory Oathkeeper to use your PostgreSQL database: In your Oathkeeper configuration file (oathkeeper.yml
), set the DSN to your PostgreSQL database: bash dsn: <postgres://test:[email> protected]:5432/test?sslmode=disable&max_conns=20&max_idle_conns=4
[Source](https://www.ory.sh/docs/oathkeeper/guides/proxy-websockets#install-ory-kratos-and-ory-oathkeeper) Please replace localhost
with the IP address of your PostgreSQL container if it's running on a different host. 5. Run the migrations for each service: For each service (Kratos, Hydra, Oathkeeper), you need to run the migrations. Here's how you can do it for Kratos: bash docker run -e DSN="<postgres://test:[email> protected]:5432/test?sslmode=disable&max_conns=20&max_idle_conns=4" oryd/kratos:<version> migrate sql -e
[Source](https://www.ory.sh/docs/kratos/guides/docker) Replace <version>
with the version of the Kratos Docker image you're using. You need to do the same for Hydra and Oathkeeper, just replace oryd/kratos:<version>
with oryd/hydra:<version>
and oryd/oathkeeper:<version>
respectively. Once you've done all these steps, your Ory ecosystem should be connected to your PostgreSQL database.high-magician-68236
06/24/2024, 8:24 AMchilly-king-10285
06/24/2024, 8:24 AMchilly-king-10285
06/24/2024, 8:24 AMtest
. To create a separate database for Kratos, you can modify the POSTGRES_DB
environment variable in your Docker Compose file. Here's an example: yaml version: '3.9' services: postgres: image: postgres:14-alpine ports: - 5432:5432 volumes: - ./db/data:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD=test - POSTGRES_USER=test - POSTGRES_DB=kratos
In this example, the POSTGRES_DB
environment variable is set to kratos
, which means a database named kratos
will be created when the PostgreSQL container is started. Then, in your Kratos configuration file (kratos.yml
), you would set the DSN to point to this kratos
database: bash dsn: <postgres://test:[email> protected]:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
Please replace localhost
with the IP address of your PostgreSQL container if it's running on a different host. Finally, you would run the Kratos migrations against this kratos
database: bash docker run -e DSN="<postgres://test:[email> protected]:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4" oryd/kratos:<version> migrate sql -e
Replace <version>
with the version of the Kratos Docker image you're using. [Source](https://www.ory.sh/docs/kratos/quickstart#next-steps)