@@ -40,6 +40,16 @@ To simplify URLs handling we install the [bramus/router](https://packagist.org/p
40
40
composer require bramus/router
41
41
```
42
42
43
+ ## Create a new Ory project
44
+
45
+ ``` mdx-code-block
46
+ import CreateProject from '../_common/create-project.mdx'
47
+
48
+ <CreateProject />
49
+ ```
50
+
51
+ ## Install Ory CLI
52
+
43
53
To install Ory CLI follow [ this guide] ( https://www.ory.sh/docs/guides/ory-cli-install-use )
44
54
45
55
### Why do I need the Ory CLI
@@ -52,36 +62,40 @@ import OryCLI from '../_common/ory-cli.mdx'
52
62
53
63
## Create an Entry Page
54
64
55
- This is a working example of basic ` index.php ` script which creates an Ory client, registers new route for our Dashboard and makes
56
- use of [ Before Route Middlewares] ( https://github.com/bramus/router#before-router-middlewares ) to validate if the user is allowed
57
- to view the Dashboard.
65
+ Create a new file called ` index.php ` and paste the following code:
58
66
59
67
``` mdx-code-block
60
68
import indexPHP from '!!raw-loader!../../../code-examples/protect-page-login/php/index.php'
61
69
import CodeBlock from '@theme/CodeBlock'
62
70
63
- <CodeBlock language="php" title="index.php">{indexPHP}</CodeBlock>
71
+ <CodeBlock language="php" title="./ index.php">{indexPHP}</CodeBlock>
64
72
```
65
73
66
- ## Validate and login
67
-
68
- Next we will create handler which will check with your Ory project if the user has a valid session. Notice here that we are taking
69
- the current ` request ` cookies and passing them along to the Ory client.
74
+ This entry script creates an Ory client, registers new route for our Dashboard and makes use of
75
+ [ Before Route Middlewares] ( https://github.com/bramus/router#before-router-middlewares ) to validate if the user is allowed to view
76
+ the Dashboard.
70
77
71
- If the session is not valid the request is redirected to the Ory project for login. At this point we have not set up any custom UI
72
- management and thus will be shown the Ory Account Experience login page.
78
+ We are yet to create an App class, let's do that now.
73
79
74
- For the last part we need to add the Dashboard handler (the page we would like to protect) which will render an HTML with the
75
- session data.
80
+ ## Validate and login
76
81
77
- This is accomplished by the simple ` App ` class stored in the ` app.php ` file :
82
+ Create a new file called ` app.php ` and paste the following code :
78
83
79
84
``` mdx-code-block
80
85
import appPHP from '!!raw-loader!../../../code-examples/protect-page-login/php/app.php'
81
86
82
87
<CodeBlock language="php" title="app.php">{appPHP}</CodeBlock>
83
88
```
84
89
90
+ Create a handler that checks with your Ory project to determine if the user has a valid session. We take the current ` request `
91
+ cookies and pass them to the Ory client.
92
+
93
+ This file validates the session and redirects to the login page if the session is invalid. If the session is not valid, the
94
+ request is redirected to the Ory project for login. At this stage, we have not set up any custom UI management, so the Ory Account
95
+ Experience login page will be displayed.
96
+
97
+ Finally, we added the Dashboard handler (the page we want to protect), which will render HTML with the session data.
98
+
85
99
## Run your app
86
100
87
101
Start your HTTP server and access the proxy URL
@@ -90,17 +104,11 @@ Start your HTTP server and access the proxy URL
90
104
php -S 127.0.0.1:3000
91
105
```
92
106
93
- ``` mdx-code-block
94
- import SdkEnvVar from '@site/src/components/SdkEnvVar'
95
-
96
- <SdkEnvVar />
97
- ```
98
-
99
107
Next open a new terminal window and start the Ory Proxy. Upon first start, the Ory Proxy will ask you to log into your Ory Console
100
108
account.
101
109
102
110
``` shell
103
- ory proxy http://localhost:3000
111
+ ory proxy --project < PROJECT_ID > http://localhost:3000
104
112
```
105
113
106
114
To access the PHP app through the ORY proxy open [ http://localhost:4000 ] ( http://localhost:4000 ) in your browser. You are presented
0 commit comments