Skip to content

Commit

Permalink
Deprecated authRequired in favor of security.authc.enabled (#202414)
Browse files Browse the repository at this point in the history
## Summary

Deprecated `authRequired` in favor of `security.authc.enabled`.


### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

__Closes: https://github.com/elastic/kibana/issues/191711__

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
elena-shostak and elasticmachine authored Dec 10, 2024
1 parent 62c1333 commit 4feed67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions dev_docs/tutorials/endpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class MyPlugin implements Plugin {
By default, when security is enabled, endpoints require the user to be authenticated to be accessed,
and will return a `401 - Unauthorized` otherwise.

It is possible to disable this requirement using the `authRequired` option of the route.
It is possible to disable this requirement using the `security.authc.enabled` option of the route.

```ts
import type { CoreSetup, Plugin } from '@kbn/core/server';
Expand All @@ -380,8 +380,11 @@ export class MyPlugin implements Plugin {
{
path: '/api/my_plugin/get_object',
validate: false,
options: {
authRequired: false,
security: {
authc: {
enabled: false,
reason: 'This endpoint does not require authentication',
},
},
},
async (context, request, response) => {
Expand All @@ -394,7 +397,7 @@ export class MyPlugin implements Plugin {
}
```

Note that in addition to `true` and `false`, `authRequired` accepts a third value, `'optional'`. When used,
Note that in addition to `true` and `false`, `security.authc.enabled` accepts a third value, `'optional'`. When used,
Kibana will try to authenticate the user but will allow access to the endpoint regardless of the result. In that
case, the developer needs to manually checks if the user is authenticated via `request.auth.isAuthenticated`.

Expand All @@ -416,8 +419,11 @@ export class MyPlugin implements Plugin {
{
path: '/api/my_plugin/get_object',
validate: false,
options: {
authRequired: false,
security: {
authc: {
enabled: false,
reason: 'This endpoint does not require authentication',
},
},
},
async (context, request, response) => {
Expand Down
1 change: 0 additions & 1 deletion legacy_rfcs/text/0005_route_handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interface KibanaRequest {
path: string;
method: 'get' | 'post' | ...
options: {
authRequired: boolean;
tags: string [];
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/http/core-http-server/src/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ export interface RouteConfigOptions<Method extends RouteMethod> {
* Can be useful when we grant access to a resource but want to identify a user if possible.
*
* Defaults to `true` if an auth mechanism is registered.
*
* @deprecated Use `security.authc.enabled` instead
*/
authRequired?: boolean | 'optional';

Expand Down

0 comments on commit 4feed67

Please sign in to comment.