From: "Shan Shaji" <s.shaji@proxmox.com>
To: "Azharul Haque" <haque@azharul.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH dart-api-client v3 2/2] fix #4281: access: add OpenID Connect auth-url/login helpers
Date: Wed, 26 Aug 2026 14:49:43 +0200 [thread overview]
Message-ID: <DKYVZDHBOYC8.2TEA2FBVRQ9U0@proxmox.com> (raw)
In-Reply-To: <20260821034147.30194-3-haque@azharul.com>
Hi Azharul,
Thanks for factoring out the block. IMHO, we could separate the addition
of helper and openID functions into two patches.
1. Factor out the helper.
2. Add the OpenID specific functions.
On Fri Aug 21, 2026 at 5:41 AM CEST, Azharul Haque wrote:
> Add openIdAuthUrl() and openIdLogin(), mirroring the existing
> authenticate()/accessDomains() functions used by the login form
> before an authenticated ProxmoxApiClient exists.
>
> openIdAuthUrl() requests the provider's authorization URL for a
> realm from /access/openid/auth-url. openIdLogin() exchanges the
> state/code obtained from the provider's redirect for a PVE ticket
> via /access/openid/login, the same way authenticate() does for
> password realms.
>
> The OpenID login response carries the authenticated username in its
> body rather than it being known upfront by the caller, so
> handleOpenIdLoginResponse() is added alongside the existing
> handleAccessTicketResponse() to build Credentials from it. Its ticket
> regex only matches PVE tickets (not PMG), since OpenID login is only
> ever performed against a PVE realm; because the two regexes therefore
> differ, the regex match stays in each handler while the shared tail
> (deriving the expiration time and detecting an accompanying TFA
> challenge) is factored into a common helper used by both.
>
> Suggested-by: Shan Shaji <s.shaji@proxmox.com>
> Signed-off-by: Azharul Haque <haque@azharul.com>
> ---
[snip]
> Future<List<PveAccessDomainModel?>> accessDomains(
> Uri apiBaseUrl,
> bool validateSSL, {
> diff --git a/lib/src/handle_ticket_response.dart b/lib/src/handle_ticket_response.dart
> index ba2128f..f4bffde 100644
> --- a/lib/src/handle_ticket_response.dart
> +++ b/lib/src/handle_ticket_response.dart
> @@ -5,6 +5,29 @@ import 'package:proxmox_dart_api_client/src/credentials.dart';
> import 'package:proxmox_dart_api_client/src/extentions.dart';
> import 'package:proxmox_dart_api_client/src/tfa_challenge.dart';
>
> +/// Shared tail of parsing a ticket response: derives the ticket's
> +/// expiration time from its embedded timestamp, and determines whether a
> +/// TFA challenge accompanies it (either encoded in the ticket itself, or
> +/// flagged via the legacy `NeedTFA` field).
> +({DateTime expiration, TfaChallenge? tfa}) _parseTicketExpirationAndTfa(
> + RegExpMatch ticketMatch,
> + String ticket,
> + Map<String, dynamic> bodyJson,
> +) {
> + final expiration = DateTime.fromMillisecondsSinceEpoch(
> + int.parse(ticketMatch.group(3)!, radix: 16) * 1000);
> +
> + TfaChallenge? tfa;
> + if (ticket.startsWith('PVE:!tfa!')) {
> + tfa = TfaChallenge.fromJson(
> + jsonDecode(Uri.decodeComponent(ticket.substring(9).split(':')[0])));
> + } else if (bodyJson['NeedTFA'] != null && bodyJson['NeedTFA'] == 1) {
> + tfa = TfaChallenge.legacy();
> + }
> +
> + return (expiration: expiration, tfa: tfa);
> +}
> +
> Credentials handleAccessTicketResponse(
> http.Response response, Credentials unauthenticatedCredentials) {
> response.validate(false);
> @@ -15,27 +38,46 @@ Credentials handleAccessTicketResponse(
>
> final csrfToken = bodyJson['CSRFPreventionToken'];
>
> - final ticketRegex = RegExp(r'(PVE|PMG)(?:QUAR)?:(?:(\S+):)?([A-Z0-9]{8})::')
> - .firstMatch(bodyJson['ticket'])!;
> + final ticketMatch = RegExp(r'(PVE|PMG)(?:QUAR)?:(?:(\S+):)?([A-Z0-9]{8})::')
> + .firstMatch(ticket)!;
>
> - final time = DateTime.fromMillisecondsSinceEpoch(
> - int.parse(ticketRegex.group(3)!, radix: 16) * 1000);
> -
> - TfaChallenge? tfa;
> - if (ticket.startsWith('PVE:!tfa!')) {
> - tfa = TfaChallenge.fromJson(
> - jsonDecode(Uri.decodeComponent(ticket.substring(9).split(':')[0])));
> - } else if (bodyJson['NeedTFA'] != null && bodyJson['NeedTFA'] == 1) {
> - tfa = TfaChallenge.legacy();
> - }
> + final parsed = _parseTicketExpirationAndTfa(ticketMatch, ticket, bodyJson);
>
> return Credentials(
> unauthenticatedCredentials.apiBaseUrl,
> unauthenticatedCredentials.username,
> ticket: ticket,
> csrfToken: csrfToken,
> - expiration: time,
> - tfa: tfa,
> + expiration: parsed.expiration,
> + tfa: parsed.tfa,
> + );
> +}
> +
Above changes could itself be another preparatory patch.
[snip]
next prev parent reply other threads:[~2026-08-26 12:49 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 5:40 [PATCH 0/2] android: register OpenID Connect callback activity for #4281 Azharul Haque
2026-08-10 5:40 ` [PATCH 1/2] fix #4281: android: register OpenID Connect callback activity Azharul Haque
2026-08-10 5:40 ` [PATCH 2/2] fix #4281: android: match renamed OpenID callback scheme Azharul Haque
2026-08-10 13:59 ` [PATCH 0/2] android: register OpenID Connect callback activity for #4281 Shan Shaji
2026-08-10 14:47 ` [PATCH v2 0/7] app: implement OpenID Connect (OAuth) realm login (#4281) Azharul Haque
2026-08-10 14:47 ` [PATCH dart-api-client v2 1/2] fix #4281: access: add `type` property to `PveAccessDomainModel` Azharul Haque
2026-08-20 9:17 ` Shan Shaji
2026-08-20 13:37 ` Azharul Haque
2026-08-20 14:39 ` Shan Shaji
2026-08-21 2:56 ` Azharul Haque
2026-08-21 8:00 ` Shan Shaji
2026-08-10 14:47 ` [PATCH dart-api-client v2 2/2] fix #4281: access: add OpenID Connect auth-url/login helpers Azharul Haque
2026-08-20 9:48 ` Shan Shaji
2026-08-20 13:41 ` Azharul Haque
2026-08-10 14:47 ` [PATCH login-manager v2 1/3] fix #4281: ui: add OpenID Connect login flow to login form Azharul Haque
2026-08-20 12:31 ` Shan Shaji
2026-08-10 14:47 ` [PATCH login-manager v2 2/3] fix #4281: ui: fix stale Continue button state on realm switch Azharul Haque
2026-08-10 14:47 ` [PATCH login-manager v2 3/3] fix #4281: ui: use a namespaced OpenID callback scheme Azharul Haque
2026-08-20 14:28 ` Shan Shaji
2026-08-10 14:47 ` [PATCH flutter-frontend v2 1/2] fix #4281: android: register OpenID Connect callback activity Azharul Haque
2026-08-20 14:01 ` Shan Shaji
2026-08-10 14:47 ` [PATCH flutter-frontend v2 2/2] fix #4281: android: match renamed OpenID callback scheme Azharul Haque
2026-08-21 3:41 ` [PATCH v3 00/10] app: implement OpenID Connect (OAuth) realm login (#4281) Azharul Haque
2026-08-21 3:41 ` [PATCH dart-api-client v3 1/2] fix #4281: access: add `type` property to `PveAccessDomainModel` Azharul Haque
2026-08-21 3:41 ` [PATCH dart-api-client v3 2/2] fix #4281: access: add OpenID Connect auth-url/login helpers Azharul Haque
2026-08-26 12:49 ` Shan Shaji [this message]
2026-08-21 3:41 ` [PATCH login-manager v3 1/5] fix #4281: deps: add flutter_web_auth_2 dependency Azharul Haque
2026-08-21 3:41 ` [PATCH login-manager v3 2/5] refactor: ui: factor out shared login tail into _finishLogin Azharul Haque
2026-08-26 13:41 ` Shan Shaji
2026-08-21 3:41 ` [PATCH login-manager v3 3/5] refactor: ui: split password form into its own widget Azharul Haque
2026-08-26 9:32 ` Shan Shaji
2026-08-21 3:41 ` [PATCH login-manager v3 4/5] fix #4281: ui: add OpenID Connect login flow to login form Azharul Haque
2026-08-21 3:41 ` [PATCH login-manager v3 5/5] fix #4281: ui: fix stale Continue button state on realm switch Azharul Haque
2026-08-26 10:24 ` Shan Shaji
2026-08-21 3:41 ` [PATCH flutter-frontend v3 1/3] chore: regenerate plugin registrant for flutter_web_auth_2 Azharul Haque
2026-08-21 3:41 ` [PATCH flutter-frontend v3 2/3] fix #4281: android: set taskAffinity="" on MainActivity Azharul Haque
2026-08-21 3:41 ` [PATCH flutter-frontend v3 3/3] fix #4281: android: register OpenID Connect callback activity Azharul Haque
2026-08-26 11:41 ` [PATCH v3 00/10] app: implement OpenID Connect (OAuth) realm login (#4281) Shan Shaji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DKYVZDHBOYC8.2TEA2FBVRQ9U0@proxmox.com \
--to=s.shaji@proxmox.com \
--cc=haque@azharul.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox