Skip to content

Commit a1c2b6f

Browse files
docs: update quickstart to use tunnel (#2096)
* docs: update quickstart to use tunnel * docs: update test script to use ory tunne * fix: use correct base path * chore: update test ports * docs: deprecate ory proxy * fix: add dev flag to tunnel command * fix: update port * fix: update port * fix: tunnel port env for examples * fix: php redirect url * fix: add tunnel url env to express example * fix: markdow syntax formatting * chore: format * fix: md syntaxt for formatting * chore: format * chore: remove p tags * fix: resolve feedback * chore: format * chore: format * fix: mermaid url syntax * chore: remove html elements from callouts * chore: format --------- Co-authored-by: vinckr <[email protected]>
1 parent ce56ea5 commit a1c2b6f

26 files changed

+209
-182
lines changed

code-examples/protect-page-login/dotnet/entrypoint.sh

100755100644
File mode changed.

code-examples/protect-page-login/expressjs/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ You can start the application with:
2727
npm run dev
2828
```
2929

30-
### 3. Run the Ory Proxy
30+
### 3. Run the Ory Tunnel
3131

32-
To ensure cookies are on the same domain, run the Ory Proxy with your project
32+
To ensure cookies are on the same domain, run the Ory Tunnel with your project
3333
ID:
3434

3535
```bash
36-
ORY_PROJECT_ID=<Project_ID> npm run proxy
36+
ORY_PROJECT_ID=<Project_ID> npm run tunnel
3737
```
3838

3939
Replace `<Project_ID>` with your actual Ory Project ID from the Ory Console.

code-examples/protect-page-login/expressjs/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const app = require("express")()
33
const sdk = require("@ory/client-fetch")
44

55
// highlight-start
6+
const basePath = process.env.ORY_SDK_URL || "http://localhost:4000"
67
const ory = new sdk.FrontendApi(
78
new sdk.Configuration({
8-
basePath: process.env.ORY_SDK_URL || "http://localhost:4000/.ory",
9+
basePath,
910
}),
1011
)
1112
// highlight-end
@@ -17,7 +18,7 @@ const requireAuth = async (req, res, next) => {
1718
req.session = session
1819
next()
1920
} catch (error) {
20-
res.redirect("/.ory/ui/login")
21+
res.redirect(basePath + "/ui/login")
2122
}
2223
}
2324
// highlight-end

code-examples/protect-page-login/expressjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "index.js",
55
"scripts": {
66
"dev": "nodemon index.js",
7-
"proxy": "ory proxy --project $ORY_PROJECT_ID --port 4000 http://localhost:3000/",
7+
"tunnel": "ory tunnel --project $ORY_PROJECT_ID --port 4000 --dev http://localhost:3000",
88
"start": "node index.js"
99
},
1010
"keywords": [],

code-examples/protect-page-login/go/main.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright © 2022 Ory Corp
2-
// SPDX-License-Identifier: Apache-2.0
3-
41
package main
52

63
import (
@@ -13,22 +10,26 @@ import (
1310
)
1411

1512
type App struct {
16-
ory *ory.APIClient
13+
ory *ory.APIClient
14+
tunnelUrl string
1715
}
1816

1917
func main() {
20-
proxyPort := os.Getenv("PROXY_PORT")
21-
if proxyPort == "" {
22-
proxyPort = "4000"
18+
tunnelPort := os.Getenv("TUNNEL_PORT")
19+
if tunnelPort == "" {
20+
tunnelPort = "4000"
2321
}
2422

25-
// register a new Ory client with the URL set to the Ory CLI Proxy
26-
// we can also read the URL from the env or a config file
23+
// Configure Ory client to use tunnel
2724
c := ory.NewConfiguration()
28-
c.Servers = ory.ServerConfigurations{{URL: fmt.Sprintf("http://localhost:%s/.ory", proxyPort)}}
25+
c.Servers = ory.ServerConfigurations{{URL: fmt.Sprintf("http://localhost:%s", tunnelPort)}}
26+
27+
// Store the tunnel URL for redirects
28+
tunnelUrl := fmt.Sprintf("http://localhost:%s", tunnelPort)
2929

3030
app := &App{
31-
ory: ory.NewAPIClient(c),
31+
ory: ory.NewAPIClient(c),
32+
tunnelUrl: tunnelUrl,
3233
}
3334
mux := http.NewServeMux()
3435

@@ -41,6 +42,9 @@ func main() {
4142
}
4243

4344
fmt.Printf("Application launched and running on http://127.0.0.1:%s\n", port)
45+
fmt.Printf("Make sure to run Ory Tunnel in another terminal:\n")
46+
fmt.Printf("npx @ory/cli tunnel --dev http://localhost:%s\n", port)
47+
4448
// start the server
4549
err := http.ListenAndServe(":"+port, mux)
4650
if errors.Is(err, http.ErrServerClosed) {

code-examples/protect-page-login/go/middleware.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ func (app *App) sessionMiddleware(next http.HandlerFunc) http.HandlerFunc {
2828
session, _, err := app.ory.FrontendAPI.ToSession(request.Context()).Cookie(cookies).Execute()
2929
// Check if a session exists and if it is active.
3030
// You could add your own logic here to check if the session is valid for the specific endpoint, e.g. using the `session.AuthenticatedAt` field.
31+
// Redirect to login if session doesn't exist or is inactive
3132
if err != nil || (err == nil && !*session.Active) {
32-
// redirect the user to the login UI, in this case we use the default browser flow
33-
http.Redirect(writer, request, "/.ory/self-service/login/browser", http.StatusSeeOther)
33+
log.Printf("No active session, redirecting to login\n")
34+
// Redirect to the tunnel URL, not the local app
35+
http.Redirect(writer, request, app.tunnelUrl+"/ui/login", http.StatusSeeOther)
3436
return
3537
}
3638

@@ -39,7 +41,6 @@ func (app *App) sessionMiddleware(next http.HandlerFunc) http.HandlerFunc {
3941

4042
// Continue to the next handler (the dashboard in the simple example).
4143
next.ServeHTTP(writer, request.WithContext(ctx))
42-
return
4344
}
4445
}
4546

code-examples/protect-page-login/php/app.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright © 2022 Ory Corp
2-
// SPDX-License-Identifier: Apache-2.0
3-
41
<?php
52

63
class App
@@ -24,7 +21,7 @@ public function validateSession()
2421
} catch (Exception $e) {
2522
error_log('Exception when calling toSession: ' . $e->getMessage());
2623
// this will initialize a new login flow and Kratos will redirect the user to the login UI
27-
header("Location: /.ory/self-service/login/browser", true, 303);
24+
header("Location: " . $this->tunnelUrl . "/ui/login", true, 303);
2825
die();
2926
}
3027
$this->session = $session;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"ory/client": "^v1.0.2",
3+
"ory/client": "^1.20",
44
"bramus/router": "^1.6"
55
}
66
}

code-examples/protect-page-login/php/composer.lock

+25-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code-examples/protect-page-login/php/index.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
// Copyright © 2022 Ory Corp
2-
// SPDX-License-Identifier: Apache-2.0
3-
41
<?php
52
require 'vendor/autoload.php';
63
require_once 'app.php';
74

85
error_reporting(E_ERROR | E_PARSE);
96

10-
$proxyPort = getenv("PROXY_PORT");
11-
if ($proxyPort == "") $proxyPort = "4000";
7+
$tunnelPort = getenv("TUNNEL_PORT");
8+
if ($tunnelPort == "")
9+
$tunnelPort = "4000";
1210

1311
$app = new App;
14-
// register a new Ory client with the URL set to the Ory CLI Proxy
15-
// we can also read the URL from the env or a config file
16-
$config = Ory\Client\Configuration::getDefaultConfiguration()->setHost(sprintf("http://localhost:%s/.ory", $proxyPort));
12+
// Configure Ory client to use tunnel port 4000
13+
$config = Ory\Client\Configuration::getDefaultConfiguration()->setHost(sprintf("http://localhost:%s", $tunnelPort));
1714
$app->ory = new Ory\Client\Api\FrontendApi(new GuzzleHttp\Client(), $config);
18-
15+
// Pass tunnel URL to the App class for redirects
16+
$app->tunnelUrl = sprintf("http://localhost:%s", $tunnelPort);
1917
$router = new \Bramus\Router\Router();
2018
$router->before('GET', '/', $app->validateSession());
2119
$router->get('/', $app->printDashboard());

code-examples/sdk/go/frontend/whoami-browser.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99
)
1010

1111
func whoami() {
12-
proxyPort := os.Getenv("PROXY_PORT")
13-
if proxyPort == "" {
14-
proxyPort = "4000"
12+
tunnelPort := os.Getenv("TUNNEL_PORT")
13+
if tunnelPort == "" {
14+
tunnelPort = "4000"
1515
}
16+
1617
cfg := ory.NewConfiguration()
17-
cfg.Servers = ory.ServerConfigurations{{URL: fmt.Sprintf("http://localhost:%s/.ory", proxyPort)}}
18+
cfg.Servers = ory.ServerConfigurations{{URL: fmt.Sprintf("http://localhost:%s", tunnelPort)}}
19+
1820
apiClient := ory.NewAPIClient(cfg)
1921
cookie := "ory_session_playground=<your-session-cookie-here>"
2022
resp, r, err := apiClient.FrontendApi.ToSession(context.Background()).Cookie(cookie).Execute()

docs/cli/ory-proxy.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: ory-proxy
3-
title: ory proxy
3+
title: ory proxy (deprecated)
44
description: ory proxy Run your app and Ory on the same domain using a reverse proxy
55
---
66

@@ -11,6 +11,10 @@ To improve this file please make your change against the appropriate "./cmd/*.go
1111
-->
1212
## ory proxy
1313

14+
15+
:::warning DEPRECATED
16+
Ory Proxy has been deprecated and is no longer recommended for new implementations. Please use [Ory Tunnel](./ory-tunnel.md) instead, which provides similar functionality with an improved architecture. For migration guidance, see the [Proxy and Tunnel documentation](../guides/cli/proxy-and-tunnel#migration-from-proxy-to-tunnel).
17+
:::
1418
Run your app and Ory on the same domain using a reverse proxy
1519

1620
### Synopsis
@@ -177,4 +181,3 @@ ory proxy http://localhost:3000
177181
### SEE ALSO
178182

179183
* [ory](ory) - The Ory CLI
180-

docs/cli/ory.md

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ The Ory CLI
3535
* [ory parse](ory-parse) - Parse Ory Network resources
3636
* [ory patch](ory-patch) - Patch resources
3737
* [ory perform](ory-perform) - Perform a flow
38-
* [ory proxy](ory-proxy) - Run your app and Ory on the same domain using a reverse proxy
3938
* [ory revoke](ory-revoke) - Revoke resources
4039
* [ory tunnel](ory-tunnel) - Mirror Ory APIs on your local machine for local development and testing
4140
* [ory update](ory-update) - Update resources

docs/getting-started/_common/going-to-prod.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ the same common domain, for example `https://ory.example.com` and `https://www.e
55
You can easily connect Ory to your subdomain. To do that,
66
[add a Custom Domain to your Ory Network project](../../guides/custom-domains.mdx).
77

8-
With the custom domain set up, you don't need to use Ory Proxy or Ory Tunnel to interact with Ory APIs. Instead, use the
9-
configured custom domain in your SDK calls:
8+
With the custom domain set up, you don't need to use Ory Tunnel to interact with Ory APIs. Instead, use the configured custom
9+
domain in your SDK calls:

0 commit comments

Comments
 (0)