Skip to content

[74542] Add an authentication strategy for the wikis module#23115

Open
shiroginne wants to merge 9 commits intodevfrom
implementation/74542-add-auth-strategy
Open

[74542] Add an authentication strategy for the wikis module#23115
shiroginne wants to merge 9 commits intodevfrom
implementation/74542-add-auth-strategy

Conversation

@shiroginne
Copy link
Copy Markdown
Contributor

Ticket

Follow up for the 74542

What are you trying to accomplish?

  • Add BearerToken auth strategy and all the code required by it
  • Updated UserQuery to use BearerToken auth strategy instead of just passing the token

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

- Add `BearerToken` auth strategy and all the code required by it
- Updated `UserQuery` to use `BearerToken` auth strategy instead of just passing the token
@shiroginne shiroginne self-assigned this May 7, 2026
@shiroginne shiroginne marked this pull request as ready for review May 7, 2026 15:16
@shiroginne shiroginne requested a review from a team May 7, 2026 15:16
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct

Copy link
Copy Markdown
Contributor

@NobodysNightmare NobodysNightmare left a comment

Choose a reason for hiding this comment

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

I'd suggest to extend the scope of this PR to all the queries (and callers of those queries) that we already built. Mostly, because this gives a more complete picture on the real requirements we have.

We already have services calling queries. And we already have working queries for the internal provider. In its current state, this PR wouldn't be able to work for internal provider queries, because there is no internal.authentication.user_bound strategy registered.

Trying to apply the current state of the PR to the existing services would've also shown that these now need to obtain token information that's:

  • hard to obtain for a service (they would have to go to the access tokens table as well)
  • not necessary for all queries

One additional note for internal.authentication.user_bound: Assuming we build authentication strategies to accept a user: So far the internal queries implicitly use User.current for authentication. I think once auth strategies are in place in makes sense to pass the user into the queries via the auth strategy. E.g. a WikiPage.visible could then become something like

auth_strategy.call do |user|
  WikiPage.visible(user)
end

def extract_origin_user_id(token)
resolve("queries.user").call(Wikis::Adapters::Input::UserQuery.new(access_token: token.access_token))
auth_strategy = Wikis::Adapters::Registry
.resolve("xwiki.authentication.user_bound")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 This could also be self.resolve("authentication.user_bound"), which is the much more likely call pattern for a generic caller.

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.

Changed to the

    def extract_origin_user_id(token)
      auth_strategy = auth_strategy_for(token.user)
      resolve("queries.user").call(auth_strategy:)
    end

self here is not needed, and rubocop would cut it out 😄

resolve("queries.user").call(Wikis::Adapters::Input::UserQuery.new(access_token: token.access_token))
auth_strategy = Wikis::Adapters::Registry
.resolve("xwiki.authentication.user_bound")
.call(token.access_token)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 This doesn't change a lot for callers yet. The caller still has to obtain an access token from a random database table first to use this authentication strategy.

Even worse: Imagine building code for a caller that doesn't know which provider is going to be called. Such a caller also wouldn't know which underlying strategy (here: Bearer token) would be used. So they couldn't possibly know that calling the strategy with a bearer token is the correct thing to do.

Every authentication strategy should be able to work from the same interface. For example one thing that could most likely work is to pass a user into the auth strategy and let the auth strategy figure out how to get to the data that it needs based on the user and the provider (the latter would by default be passed through a provider.resolve(...) call.

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.

Fair point. The user passed to the strategy is the way to go 👍🏻

@shiroginne
Copy link
Copy Markdown
Contributor Author

shiroginne commented May 8, 2026

I'd suggest to extend the scope of this PR to all the queries (and callers of those queries) that we already built. Mostly, because this gives a more complete picture on the real requirements we have.

Alright, let's do it. I've added some code and pushed it as well, but it still WIP.
Thanks for having a look at the PR! 🍺

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.

2 participants