Skip to content

Add auth to State#10

Merged
nemanjabogdanovic merged 4 commits into
mainfrom
add_auth_to_state
May 20, 2026
Merged

Add auth to State#10
nemanjabogdanovic merged 4 commits into
mainfrom
add_auth_to_state

Conversation

@nemanjabogdanovic

Copy link
Copy Markdown
Contributor

No description provided.

@nemanjabogdanovic nemanjabogdanovic requested a review from a team May 18, 2026 12:44
@nemanjabogdanovic nemanjabogdanovic self-assigned this May 18, 2026
@nemanjabogdanovic nemanjabogdanovic added the enhancement New feature or request label May 18, 2026

@bdebinska bdebinska left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not entirely convinced this is necessary. Why does "auth" have to be a top level key? Can't it be part of the action itself?

Comment thread lib/actions/http.ex
max_retries: max_retries,
decode_body: decode_body
)
|> Req.update(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe use Req.merge?

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.

Good catch, but it's older code and not super-relevant for this PR, so I'd prefer handling it separately if that's okay

@bdebinska

Copy link
Copy Markdown
Member

Another comment from my side: This branch and PR should be linked to the ticket

@nemanjabogdanovic

Copy link
Copy Markdown
Contributor Author

I'm not entirely convinced this is necessary. Why does "auth" have to be a top level key? Can't it be part of the action itself?

It's so that the services themselves (e.g. Batch Service) can generate and set the auth key outside a single action/step (a step shouldn't be involved in the auth of the calling services).

@nemanjabogdanovic nemanjabogdanovic changed the title Add auth to State PD-4147 Add auth to State May 18, 2026
@bdebinska

Copy link
Copy Markdown
Member

I'm not entirely convinced this is necessary. Why does "auth" have to be a top level key? Can't it be part of the action itself?

It's so that the services themselves (e.g. Batch Service) can generate and set the auth key outside a single action/step (a step shouldn't be involved in the auth of the calling services).

Bad formulation on my side sorry. I meant more that it seems that having a separate "auth" action/step, instead of having it in the state directly seems more fitting to me.

@nemanjabogdanovic

Copy link
Copy Markdown
Contributor Author

I'm not entirely convinced this is necessary. Why does "auth" have to be a top level key? Can't it be part of the action itself?

It's so that the services themselves (e.g. Batch Service) can generate and set the auth key outside a single action/step (a step shouldn't be involved in the auth of the calling services).

Bad formulation on my side sorry. I meant more that it seems that having a separate "auth" action/step, instead of having it in the state directly seems more fitting to me.

Hm, maybe.. My line of thinking was always that the current workflows shouldn't be affected/touched, so I put everything on the services. We could discuss this other way as well

@iStefo

iStefo commented May 18, 2026

Copy link
Copy Markdown
Contributor

Hi all 👋

I'd like to throw a different suggestion into the ring: Make authentication a callback-based operation (optional of course). This brings flexibility while keeping complexity out of workflow engine.

While I haven't fully thought this through, I could image it looking like this:

defmodule MyApp.WorkflowEngine do
  use WorkflowEngine,def authenticate(:http, target, auth_context) do
    {:ok, {:bearer, "foobar"}}
  end

  def authenticate(_action_type, _target, _auth_context), do: {:ok, nil}
end

where :http is hardcoded based on the action type, target would depend on the action type (for HTTP it could be either the full URL or a {method, host, path} tuple) and auth_context is a struct with

%{
  state: %WorkflowEngine.State{},
  action: %{}, # action JSON being executed
  workflow: %{} # whole workflow JSON definition or identifier?
}

Information about the acting entity would be placed into a new key in the workflow engine's state when calling execute. But then no token needs to be fetched or created if the workflow doesn't even ask for auth, while automatically centralizing authentication code for all workflow executions.

The return format would depend on the action type, for HTTP you could initially support {:ok, nil} or {:ok, {:bearer, "token"}} and then later also basic auth etc. when needed. Other actions might need different auth formats (SSH or API keys, client certificates...)

To make it easy to use, WorkflowEngine should add/generate a get_auth method that can be used by actions to fetch auth for the current action if the callback has been implemented by the hosting application.

@nemanjabogdanovic

Copy link
Copy Markdown
Contributor Author

Hi all 👋

I'd like to throw a different suggestion into the ring: Make authentication a callback-based operation (optional of course). This brings flexibility while keeping complexity out of workflow engine.

While I haven't fully thought this through, I could image it looking like this:
...

Heyy, thanks for the suggestion! I like the idea overall, I'll try and see if I can cook something up around it

@nemanjabogdanovic nemanjabogdanovic changed the title PD-4147 Add auth to State Add auth to State May 20, 2026

@bdebinska bdebinska left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code-wise looks good, but I'm still not convinced we should add this feature if we won't be meaningfully using it in the foreseeable future

@mpneuried mpneuried left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code wise it looks good.
Only some small doc extensions would be nice.

I partially agree with BDE, on the other side we now put effort in it and it's covered by tests. So I'm fine with it.

Comment thread lib/auth.ex Outdated
Comment thread README.md Outdated
@nemanjabogdanovic nemanjabogdanovic merged commit 3a21fbd into main May 20, 2026
11 checks passed
@nemanjabogdanovic nemanjabogdanovic deleted the add_auth_to_state branch May 20, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants