You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
res = iam_server.test_client.post(res.location, data={"answer": "accept"})
142
+
143
+
# 6. load your application authorization endpoint
144
+
res = test_client.get(res.location)
145
+
146
+
# 7. now you have access to the protected page
147
+
res = test_client.get("/protected")
148
+
149
+
What happened?
150
+
151
+
1. A simulation of an access to a protected page on your application. As the page is protected,
152
+
it returns a redirection to the IAM login page.
153
+
2. The IAM test client loads the login page and get redirected to the login form.
154
+
3. The login form is filled, and returns a redirection to the password form.
155
+
4. The password form is filled, and returns a redirection to the consent form.
156
+
5. The consent form is filled, and return a redirection to your application authorization endpoint with a OAuth code grant.
157
+
6. You client authorization endpoint is loaded, it reaches the IAM and exchanges the code grant with a token. This is generally where you fill the session to keep users logged in.
158
+
7. The protected page is loaded, and now you should be able to access it.
159
+
160
+
Steps 2, 3 and 4 can be quite redundant, so pytest-iam provides shortcuts with the
161
+
:meth:`~pytest_iam.Server.login` and :meth:`~pytest_iam.Server.consent` methods.
162
+
They allow you to skip the login, password and consent pages:
163
+
164
+
.. code-block:: python
165
+
:caption: Fast login and consent workflow to get an access token
res =requests.get(res.location, allow_redirects=False)
175
+
res =iam_server.test_client.get(res.location)
136
176
137
177
# 3. load your application authorization endpoint
138
-
res =testclient.get(res.headers["Location"], status=302)
178
+
res =test_client.get(res.location)
139
179
140
-
# 4. redirect to the protected page
141
-
res =res.follow(status=200)
180
+
# 4. now you have access to the protected page
181
+
res =test_client.get("/protected")
142
182
143
-
What happened?
144
-
145
-
1. A simulation of an access to a protected page on your application.
146
-
2. That redirects to the IAM authorization endpoint. Since the users are already
147
-
logged and their consent already given, the IAM redirects to your application
148
-
authorization configured redirect_uri, with the authorization code passed in
149
-
the query string. Note that ``requests`` is used in this example to perform
150
-
the request. Indeed, generally testclient such as the werkzeug one cannot
151
-
perform real HTTP requests.
152
-
3. Access your application authorization endpoint that will exchange the
153
-
authorization code against a token and check the user credentials.
154
-
4. For instance, your application can redirect the users back to the page
155
-
they attempted to access in the first place.
156
-
157
-
Error cases
158
-
-----------
183
+
Authentication workflow errors
184
+
------------------------------
159
185
160
186
The `OAuth2 <https://datatracker.ietf.org/doc/html/rfc6749>`_ and the `OpenID Connect <https://openid.net/specs/openid-connect-core-1_0.html>`_ specifications details how things might go wrong:
161
187
@@ -183,3 +209,49 @@ The `OIDC error codes <https://openid.net/specs/openid-connect-core-1_0.html#Aut
183
209
184
210
You might or might not be interested in testing how your application behaves when it encounters those situations,
185
211
depending on the situation and how much you trust the libraries that helps your application perform the authentication process.
212
+
213
+
Account creation workflow
214
+
-------------------------
215
+
216
+
The `Initiating User Registration via OpenID Connect 1.0 <https://openid.net/specs/openid-connect-prompt-create-1_0.html>`_
217
+
specification details how to initiate an account creation workflow at the IAM
218
+
by setting the ``prompt=create`` authorization request parameter.
219
+
220
+
In the following example, we suppose that the ``/create`` endpoint redirects
221
+
to the IAM authorization endpoint with the ``prompt=create`` parameters.
0 commit comments