Debian Codegraph @

docs/oauth-client.md

raw
1 # OAuth2 client
2
3 The login uses the OAuth2 **authorization code** flow with **PKCE**, run as a
4 **public client**: there is no client secret, and nothing you need to obtain.
5 Your Cookidoo account is the only credential:
6
7 ```python
8 from cookidoo_api import Cookidoo, CookidooConfig
9
10 cookidoo = Cookidoo(
11 session,
12 cfg=CookidooConfig(
13 email=os.environ["EMAIL"],
14 password=os.environ["PASSWORD"],
15 ),
16 )
17 ```
18
19 ## Why there is no secret
20
21 An OAuth2 client is identified by a **client id** and a **redirect uri**, and
22 *may* additionally authenticate itself with a **client secret**. The Cookidoo
23 identity provider (CIAM, a cidaas deployment) does not require the third one
24 here: when the token request carries a PKCE `code_verifier`, the client secret
25 is not verified at all.
26
27 Observed against the production token endpoint, exchanging the same
28 authorization code:
29
30 | token request | result |
31 | --- | --- |
32 | `client_id` + `code_verifier`, no secret | `200` — token |
33 | `client_id` + `code_verifier` + *wrong* secret | `200` — token |
34 | `client_id` + `code_verifier` + correct secret | `200` — token |
35 | `client_id`, **no** `code_verifier`, no secret | `400 invalid_client` |
36 | `code_verifier`, no `client_id` | `400 invalid_client` |
37
38 A deliberately wrong secret being accepted is the decisive one: the secret is
39 not part of what the server checks. It is PKCE that binds the exchange to the
40 client instance that started the flow — which is exactly what PKCE exists for,
41 and why [RFC 8252][rfc8252] prescribes this shape for native apps, whose
42 "secrets" cannot stay secret in a distributed binary anyway.
43
44 So the library sends the client id in the token request body and no
45 `Authorization` header, and the resulting bearer token is indistinguishable
46 from one obtained with a secret — same audience, same scopes, same roles, and
47 the same access to both the Cookidoo API and the remote-monitoring (`iot-api`)
48 backend.
49
50 ## What is shipped, and why that is not a secret
51
52 Two values are built in as defaults:
53
54 - `client_id` — `mobile-android`. A client id is a public identifier by
55 definition. [RFC 6749 §2.2][rfc6749-2.2]: *"The client identifier is not a
56 secret; it is exposed to the resource owner and MUST NOT be used alone for
57 client authentication."*
58 - `redirect_uri` — `com.vorwerk.cookidoo://code-grant`. The app's URL scheme.
59 It travels in the query string of every authorize request, is declared in the
60 app manifest, and is registered with the provider precisely so it can be
61 matched publicly.
62
63 Neither is a credential, so neither is withheld from you or from this
64 repository.
65
66 ## Overriding them
67
68 They are still plain config fields, should the app's registration ever change
69 before this library catches up:
70
71 ```python
72 CookidooConfig(
73 email=...,
74 password=...,
75 client_id="mobile-ios",
76 redirect_uri="com.vorwerk.cookidoo://code-grant",
77 )
78 ```
79
80 Setting either to an empty string raises `CookidooConfigException` at `login()`
81 rather than producing a confusing `invalid_client` from the server.
82
83 If the authorize step starts rejecting the built-in client id, the app's
84 registration has changed. The current value can be read back out of a copy of
85 the app you own: the client id is a short kebab identifier and the redirect uri
86 a custom URI scheme, both plain strings in the APK's `classes*.dex` string
87 pools and its manifest. Please open an issue so the default can be updated for
88 everyone.
89
90 [rfc6749-2.2]: https://datatracker.ietf.org/doc/html/rfc6749#section-2.2
91 [rfc8252]: https://datatracker.ietf.org/doc/html/rfc8252#section-8.5