1
1
---
2
- id : 5min-tutorial
3
- title : 5 minute tutorial
2
+ id : quickstart
3
+ title : Ory Hydra OAuth2 Server Quickstart
4
4
sidebar_label : Quickstart
5
5
---
6
6
7
- import CodeFromRemote from " @theme/CodeFromRemote"
8
-
9
- This tutorial walks you through a quick setup of Ory Hydra Federation Server and an exemplary User Login & Consent App based on
7
+ In this quickstart, you will set up Ory Hydra OAuth2 & OpenID Connect Server and an exemplary User Login & Consent App using
10
8
Docker Compose. You need to have the latest [ Docker] ( https://www.docker.com ) and [ Docker Compose] ( https://docs.docker.com/compose )
11
- version installed, as well as [ ` jq ` ] ( https://stedolan.github.io/jq/download/ ) .
9
+ version and Git installed, as well as [ ` jq ` ] ( https://stedolan.github.io/jq/download/ ) .
10
+
11
+ You do not want to self-host? Try
12
+ [ out common OAuth2 grants on the fully managed version of Ory Hydra] ( ../../getting-started/ory-network-oauth2.mdx ) .
13
+
14
+ ``` mdx-code-block
15
+ import CodeFromRemote from "@theme/CodeFromRemote"
16
+ ```
12
17
13
18
![ OAuth2 Flow with Open Source OAuth2 Server Ory Hydra] ( _static/oauth2-flow.gif )
14
19
20
+ ``` mdx-code-block
15
21
<p align="center">
16
22
<iframe width="560" height="315" src="https://www.youtube.com/embed/tlO9p2E501A" frameborder="0" allowfullscreen />
17
23
</p>
24
+ ```
25
+
26
+ To get started, clone the Ory Hydra locally:
27
+
28
+ ```
29
+ git clone https://github.com/ory/hydra.git
30
+ cd hydra
31
+ ```
18
32
19
- We will use the Docker Compose configuration in the Ory Hydra code base. Getting the Hydra source code is easy :
33
+ Run the following command(s) to start the OAuth2 server :
20
34
21
- - if you have Go 1.15+ installed: ` go get -d github.com/ory/hydra `
22
- - if you have Git installed: ` git clone https://github.com/ory/hydra.git `
23
- - otherwise: download the [ Hydra source code] ( https://github.com/ory-am/hydra/archive/master.zip ) . and extract it somewhere
35
+ ```` mdx-code-block
36
+ import Tabs from '@theme/Tabs'
37
+ import TabItem from '@theme/TabItem'
38
+ import MacOS from '@site/src/components/Install/MacOS'
39
+ import Linux from '@site/src/components/Install/Linux'
40
+ import Windows from '@site/src/components/Install/Windows'
24
41
25
- Change into the directory with the Hydra source code and run the following command to start the needed containers:
42
+ <Tabs>
43
+ <TabItem value="postgres-prod" label="PostgreSQL (prod)" default>
44
+
45
+ Run the latest Ory Hydra production build:
26
46
27
47
```sh
28
- docker- compose -f quickstart.yml \
48
+ docker compose -f quickstart.yml \
29
49
-f quickstart-postgres.yml \
30
- up --build
50
+ up
31
51
32
52
Starting hydra_postgresd_1
33
53
Starting hydra_hydra_1
34
54
[...]
35
55
```
36
56
37
- This command adds support for PostgreSQL. If you wish to use another database backend, you can run this command to use MySQL:
57
+ </TabItem>
58
+ <TabItem value="postgres-dev" label="PostgreSQL (dev)">
59
+
60
+
61
+ Run the current commit of Ory Hydra.
38
62
39
63
```sh
40
- docker-compose -f quickstart.yml \
41
- -f quickstart-mysql.yml \
42
- up --build
64
+ docker compose -f quickstart.yml \
65
+ -f quickstart-postgres.yml \
66
+ up \
67
+ --build
68
+
69
+ Starting hydra_postgresd_1
70
+ Starting hydra_hydra_1
71
+ [...]
43
72
```
44
73
45
- This one to use CockroachDB:
74
+ Building the image will override the Ory Hydra production image on your local registry. To download the latest
75
+ production image again, run:
46
76
47
77
```sh
48
- docker-compose -f quickstart.yml \
49
- -f quickstart-cockroach.yml \
50
- up --build
78
+ docker compose -f quickstart.yml pull hydra --policy always
51
79
```
52
80
53
- Or simply omit the second file to default to SQLite:
54
81
55
- ``` sh
56
- docker-compose -f quickstart.yml \
57
- up --build
82
+ </TabItem>
83
+ <TabItem value="mysql-prod" label="MySQL">
84
+
85
+
86
+ ```shell
87
+ docker compose -f quickstart.yml \
88
+ -f quickstart-mysql.yml \
89
+ up
58
90
```
59
91
60
- This command makes Docker Compose start up a database server and a basic base Ory Hydra server that uses this database. If you
61
- need more details on this, please examine the ` scripts/5-min-tutorial.sh ` and ` docker-compose*.yml ` files.
92
+
93
+ </TabItem>
94
+ <TabItem value="sqlite" label="SQLite" default>
95
+
96
+
97
+ ```shell
98
+ docker compose -f quickstart.yml up
99
+ ```
100
+
101
+
102
+ </TabItem>
103
+ <TabItem value="observability" label="Observability">
104
+
62
105
63
106
You may also extend the command above to enable distributed tracing. The tracing UI is exposed at
64
107
[http://127.0.0.1:16686/search](http://127.0.0.1:16686/search):
65
108
66
109
```sh
67
- docker- compose -f quickstart.yml \
110
+ docker compose -f quickstart.yml \
68
111
-f quickstart-postgres.yml \
69
112
-f quickstart-tracing.yml \
70
113
up --build
@@ -74,32 +117,39 @@ Hydra provides an endpoint for Prometheus to scrape as a target. You can run the
74
117
and status of Hydra is exposed at targets page in Prometheus [http://localhost:9090/targets](http://localhost:9090/targets):
75
118
76
119
```sh
77
- docker- compose -f quickstart.yml \
120
+ docker compose -f quickstart.yml \
78
121
-f quickstart-prometheus.yml \
79
122
up --build
80
123
```
81
124
125
+
126
+ </TabItem>
127
+ <TabItem value="hsm" label="HSM">
128
+
129
+
82
130
If you want to test Hardware Security Module add `-f quickstart-hsm.yml`. For more information head over to
83
- [ HSM support] ( ./self-hosted/ hsm-support.md) .
131
+ [HSM support](hsm-support.md).
84
132
85
133
```sh
86
- docker- compose -f quickstart.yml \
134
+ docker compose -f quickstart.yml \
87
135
-f quickstart-hsm.yml \
88
136
up --build
89
137
```
90
138
91
- Let's confirm that everything is working by creating an OAuth 2.0 Client.
92
139
93
- Note: The following commands run Hydra inside Docker. If you have the Ory Hydra CLI installed locally, you can omit
94
- ` docker-compose -f quickstart.yml exec /hydra ` in front of each command.
140
+ </TabItem>
141
+ </Tabs>
142
+ ````
143
+
144
+ Let's confirm that everything is working by creating an OAuth 2.0 Client.
95
145
96
146
The OAuth 2.0 client uses port ` 4444 ` and ` 4445 ` . The former is Ory Hydra's public endpoint, the latter its administrative
97
- endpoint. For more information head over to [ Exposing Administrative and Public API Endpoints] ( ./self-hosted/ production) .
147
+ endpoint. For more information head over to [ Exposing Administrative and Public API Endpoints] ( production.md ) .
98
148
99
149
Let's create the OAuth 2.0 Client:
100
150
101
151
``` sh
102
- client=$( docker- compose -f quickstart.yml exec hydra \
152
+ client=$( docker compose -f quickstart.yml exec hydra \
103
153
hydra create client \
104
154
--endpoint http://127.0.0.1:4445/ \
105
155
--format json \
@@ -113,7 +163,7 @@ client_secret=$(echo $client | jq -r '.client_secret')
113
163
Let's perform the client credentials grant:
114
164
115
165
``` sh
116
- docker- compose -f quickstart.yml exec hydra \
166
+ docker compose -f quickstart.yml exec hydra \
117
167
hydra perform client-credentials \
118
168
--endpoint http://127.0.0.1:4444/ \
119
169
--client-id " $client_id " \
@@ -128,7 +178,7 @@ EXPIRY 2022-06-27 11:50:28.244046504 +0000 UTC m=+3599.059213960
128
178
Let's perform token introspection on that token. Make sure to copy the token you just got and not the dummy value.
129
179
130
180
``` sh
131
- docker- compose -f quickstart.yml exec hydra \
181
+ docker compose -f quickstart.yml exec hydra \
132
182
hydra introspect token \
133
183
--format json-pretty \
134
184
--endpoint http://127.0.0.1:4445/ \
@@ -151,7 +201,7 @@ Next, we will perform the OAuth 2.0 Authorization Code Grant. For that, we must
151
201
that grant:
152
202
153
203
``` sh
154
- code_client=$( docker- compose -f quickstart.yml exec hydra \
204
+ code_client=$( docker compose -f quickstart.yml exec hydra \
155
205
hydra create client \
156
206
--endpoint http://127.0.0.1:4445 \
157
207
--grant-type authorization_code,refresh_token \
@@ -171,7 +221,7 @@ The following command starts a server that serves an example web application. Th
171
221
Authorization Code Flow using Ory Hydra. The web server runs on [ http://127.0.0.1:5555 ] ( http://127.0.0.1:5555 ) .
172
222
173
223
``` sh
174
- docker- compose -f quickstart.yml exec hydra \
224
+ docker compose -f quickstart.yml exec hydra \
175
225
hydra perform authorization-code \
176
226
--client-id $code_client_id \
177
227
--client-secret $code_client_secret \
@@ -195,22 +245,24 @@ Great! You installed Ory Hydra, connected the CLI, created a client and complete
195
245
clean up this set up in order to avoid conflicts with other tutorials from this guide:
196
246
197
247
```sh
198
- docker- compose -f quickstart.yml kill
199
- docker- compose -f quickstart.yml rm -f -v
248
+ docker compose -f quickstart.yml kill
249
+ docker compose -f quickstart.yml rm -f -v
200
250
```
201
251
202
252
## Quickstart configuration
203
253
204
254
In this tutorial we use a simplified configuration. You can find it in
205
255
[`contrib/quickstart/5-min/hydra.yml`](https://github.com/ory/hydra/blob/master/contrib/quickstart/5-min/hydra.yml). The
206
- configuration gets loaded in docker- compose as specified in the
256
+ configuration gets loaded in docker compose as specified in the
207
257
[`quickstart.yml`](https://github.com/ory/hydra/blob/master/quickstart.yml).
208
258
259
+ ```mdx-code-block
209
260
<CodeFromRemote
210
261
lang="js"
211
262
link="https://github.com/ory/hydra/blob/master/contrib/quickstart/5-min/hydra.yml"
212
263
src="https://raw.githubusercontent.com/ory/hydra/master/contrib/quickstart/5-min/hydra.yml"
213
264
/>
265
+ ```
214
266
215
- Have a look at the [reference configuration](./reference/configuration.mdx) for further information on all possible configuration
267
+ Have a look at the [reference configuration](.. /reference/configuration.mdx) for further information on all possible configuration
216
268
options.
0 commit comments