|
| 1 | +.. _pkce: |
| 2 | + |
| 3 | +*************************** |
| 4 | +Proof Key for Code Exchange |
| 5 | +*************************** |
| 6 | + |
| 7 | +------------ |
| 8 | +Introduction |
| 9 | +------------ |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +OAuth 2.0 public clients utilizing the Authorization Code Grant are |
| 14 | +susceptible to the authorization code interception attack. `RFC7636`_ |
| 15 | +describes the attack as well as a technique to mitigate |
| 16 | +against the threat through the use of Proof Key for Code Exchange |
| 17 | +(PKCE, pronounced "pixy"). |
| 18 | + |
| 19 | +------------- |
| 20 | +Configuration |
| 21 | +------------- |
| 22 | + |
| 23 | +You can set *code_challenge_length* and *code_challenge_method*. |
| 24 | +Both have defaults: |
| 25 | + |
| 26 | +- code_challenge_length: 64 and |
| 27 | +- code_challenge_method: S256 |
| 28 | + |
| 29 | +*S256* is mandatory to implement so there should be good reasons for |
| 30 | +not choosing it. To other defined method is *plain*. *plain* should only |
| 31 | +be used when you rely on the operating system and transport |
| 32 | +security not to disclose the request to an attacker. |
| 33 | + |
| 34 | +The security model relies on the fact that the code verifier is not |
| 35 | +learned or guessed by the attacker. It is vitally important to |
| 36 | +adhere to this principle. As such, the code verifier has to be |
| 37 | +created in such a manner that it is cryptographically random and has |
| 38 | +high entropy that it is not practical for the attacker to guess. |
| 39 | + |
| 40 | +The client SHOULD create a "code_verifier" with a minimum of 256 bits |
| 41 | +of entropy. This can be done by having a suitable random number |
| 42 | +generator create a 32-octet sequence. |
| 43 | + |
| 44 | +code_challenge_length is the length of that sequence. |
| 45 | + |
| 46 | +------- |
| 47 | +Example |
| 48 | +------- |
| 49 | + |
| 50 | +.. code:: python |
| 51 | +
|
| 52 | + "add_ons": { |
| 53 | + "pkce": { |
| 54 | + "function": "oidcrp.oauth2.add_on.pkce.add_support", |
| 55 | + "kwargs": { |
| 56 | + "code_challenge_length": 64, |
| 57 | + "code_challenge_method": "S256" |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +
|
| 62 | +.. _RFC7636: https://datatracker.ietf.org/doc/html/rfc7636 |
0 commit comments