Skip to content

fix(client): persist cookies so the MFA session survives calls - #27

Open
lakhansamani wants to merge 2 commits into
mainfrom
fix/cookie-jar-for-mfa-session
Open

fix(client): persist cookies so the MFA session survives calls#27
lakhansamani wants to merge 2 commits into
mainfrom
fix/cookie-jar-for-mfa-session

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor

Problem

Every call built its own http.Client with no cookie jar, so the session cookie set by the server on signup/login was dropped before the next request.

Since server 2.4.0, MFA is on by default: signup/login withhold the access token, return "Proceed to mfa setup", and identify the pending user by that cookie. SkipMfaSetup and VerifyOtp resolve it only if the cookie is replayed.

So both failed with invalid sessionthe entire MFA surface was unreachable from Go, while the methods existed and read as correct. Found by running examples/with-go against a default 2.4.0 server.

Fix

One shared cookie-aware http.Client on AuthorizerClient, used by the GraphQL, token and revoke paths. Exposed via HTTPClient(), which lazily initialises so a zero-value struct or an older construction path still gets a jar.

Tests

  • TestClientPersistsCookiesAcrossCalls — httptest server sets a cookie on call 1 and asserts it is replayed on call 2. Verified to fail with the jar removed, reporting the exact invalid session symptom.
  • TestHTTPClientAlwaysHasAJar — no construction path yields a jar-less client.

Verification

go build · go vet · go test ./... all pass. End-to-end against a live 2.4.0 server, signup → MFA offer → skip → token → profile → admin now completes.

Each call built its own http.Client with no jar, so the session cookie
the server sets on signup/login was dropped before the next request.

Since server 2.4.0 MFA is on by default: signup/login withhold the
access token, return "Proceed to mfa setup", and identify the pending
user by that cookie. SkipMfaSetup and VerifyOtp resolve it only if the
cookie comes back, so both failed with "invalid session" — the whole
MFA surface was unreachable from Go while the methods existed and read
as correct.

Share one cookie-aware client on AuthorizerClient, exposed via
HTTPClient() so a zero-value struct lazily gains a jar too.
The cookie jar landed on the GraphQL transport only. REST kept using
http.DefaultClient (jar-less) and gRPC had no cookie handling at all, so
the MFA session set by signup/login was dropped on both and SkipMfaSetup
answered "invalid session" — the MFA surface stayed unreachable over two
of three protocols.

REST now uses the client's shared http.Client. gRPC gets a unary
interceptor that replays jar cookies as `cookie` metadata and stores the
server's `set-cookie` header metadata back into the jar, which is the
cookie bridge the server's grpc transport already expects.

test: resolve the default MFA offer in the integration suite

Since server 2.4.0 MFA is on by default: signup/login withhold the access
token and offer enrollment. The suite assumed the old behaviour and had 16
failures across graphql/rest/grpc. Shared signUp/login helpers decline the
offer via SkipMfaSetup and return the withheld token; a response that is
not an MFA offer passes through untouched, so a genuinely missing token
still fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant