Skip to content

feat: expose authentication method on action contexts - #117

Merged
gjtorikian merged 2 commits into
mainfrom
tars/actions-authentication-method
Aug 13, 2026
Merged

feat: expose authentication method on action contexts#117
gjtorikian merged 2 commits into
mainfrom
tars/actions-authentication-method

Conversation

@workos-tars

@workos-tars workos-tars Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to workos/workos#68754. Expose authentication_method on the typed ActionContext returned by the Actions helper for authentication and user registration payloads. This reuses the existing WorkOS.AuthenticateResponseAuthenticationMethod enum.

Documentation

No SDK documentation changes required. The Actions API documentation is covered by the API change; this PR only makes the existing payload field available through the Elixir helper.

Test plan

  • mix format lib/workos/action_context.ex test/workos/actions_test.exs
  • mix test test/workos/actions_test.exs

Requested by zac.burrage@workos.com via TARS

@workos-tars
workos-tars Bot requested a review from a team as a code owner August 12, 2026 17:50
@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR exposes the Actions API’s authentication_method field on WorkOS.ActionContext.

  • Adds the field to the struct and deserializes known values through the existing authentication-method enum caster.
  • Covers known, absent, and forward-compatible unknown authentication methods in Actions tests.

Confidence Score: 4/5

The PR is not yet safe to merge because its public ActionContext type contract remains inconsistent with the value returned for unknown authentication methods.

The new test establishes that unknown authentication methods are returned as strings, while the current typespec permits only known enum atoms or nil, leaving the previously reported contract defect outstanding.

Files Needing Attention: lib/workos/action_context.ex

Important Files Changed

Filename Overview
lib/workos/action_context.ex Adds authentication-method deserialization, but the field typespec still excludes raw strings returned for unknown enum values.
test/workos/actions_test.exs Adds coverage for known authentication methods, missing fields, and passthrough of future unknown values.

Reviews (2): Last reviewed commit: "fix: document authentication_method as s..." | Re-trigger Greptile

@type t :: %__MODULE__{
object: String.t() | nil,
id: String.t() | nil,
authentication_method: WorkOS.AuthenticateResponseAuthenticationMethod.t() | nil,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Include unknown enum strings

The reused caster preserves unrecognized authentication methods as raw strings, but this field typespec permits only known enum atoms or nil. This makes the declared contract inaccurate for forward-compatible API values and can mislead static analysis and callers into treating the atom variants as exhaustive.

Suggested change
authentication_method: WorkOS.AuthenticateResponseAuthenticationMethod.t() | nil,
authentication_method:
WorkOS.AuthenticateResponseAuthenticationMethod.t() | String.t() | nil,
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/workos/action_context.ex
Line: 36

Comment:
**Include unknown enum strings**

The reused caster preserves unrecognized authentication methods as raw strings, but this field typespec permits only known enum atoms or `nil`. This makes the declared contract inaccurate for forward-compatible API values and can mislead static analysis and callers into treating the atom variants as exhaustive.

```suggestion
          authentication_method:
            WorkOS.AuthenticateResponseAuthenticationMethod.t() | String.t() | nil,
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session restore failed HTTP 422: ENOSPC: no space left on device, write

@workos-tars

workos-tars Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

session restore failed HTTP 422: ENOSPC: no space left on device, write

…aths

The ActionContext moduledoc enumerates which fields are common to both
context variants, so adding authentication_method left that list
understating the shape. This file is hand-maintained precisely because
the Actions payload is absent from the OpenAPI spec, making its
moduledoc the only documentation of that shape.

Route the cast through WorkOS.Cast.enum/2 to match how every other enum
field is built (see authenticate_response.ex) and the WorkOS.Cast.nested
calls alongside it. Behavior is unchanged; cast/1 already returned nil
for nil via its catch-all clause.

Both existing payloads gained the field in place, which silently dropped
the absent-field coverage they used to provide. Add cases for the nil
path and for the lenient caster's unknown-value passthrough, the
forward-compatibility behavior that keeps a new server-side method from
crashing the SDK.

The typespec stays as t() | nil rather than gaining | String.t(): the
generated authenticate_response.ex declares the same field the same way
with the same lenient caster, and diverging here would make this the
only struct in the SDK spelling it differently.
@gjtorikian
gjtorikian merged commit 62c075b into main Aug 13, 2026
9 checks passed
@gjtorikian
gjtorikian deleted the tars/actions-authentication-method branch August 13, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant