ima/keycloak-bearer-only-adapter-bundle
Composer 安装命令:
composer require ima/keycloak-bearer-only-adapter-bundle
包简介
Keycloak security adapter for bearer only clients
README 文档
README
This Symfony bundle is an adapter that allows securing API using keycloak Bearer Only clients.
Installation
Befor installing the bundle, automatic packages configuration can be activated with the following command:
composer config extra.symfony.allow-contrib true
With composer:
composer require ima/keycloak-bearer-only-adapter-bundle
Configuration
If you want to set up keycloak locally you can download it here and follow instructions from the official documentation.
Bundle configuration
Via a recipe (Automatic)
This bundle hase a Symfony recipe that allow the automation of configuration via the Symfony Flex Composer plugin. To enable recipe for your project, run the following command:
composer config extra.symfony.allow-contrib true
Manual
Having a running keycloak locally or in Docker and already configured a client with Access Type = bearer-only here is the configuration to use:
# config/packages/ima_keycloak_bearer_only_adapter.yaml ima_keycloak_bearer_only_adapter: issuer: '%env(OAUTH_KEYCLOAK_ISSUER)%' # your accessible keycloak url realm: '%env(OAUTH_KEYCLOAK_REALM)%' # your keycloak realm name client_id: '%env(OAUTH_KEYCLOAK_CLIENT_ID)%' # your keycloak client id client_secret: '%env(OAUTH_KEYCLOAK_CLIENT_SECRET)%' # your keycloak client secret #ssl_verification: False # by default ssl_verification is set to False
The best practice is to load your configuration from .env file.
# .env
...
###> Ima_keycloak_bearer_only_adapter ###
OAUTH_KEYCLOAK_ISSUER=keycloak:8080
OAUTH_KEYCLOAK_REALM=my_realm
OAUTH_KEYCLOAK_CLIENT_ID=my_bearer_client
OAUTH_KEYCLOAK_CLIENT_SECRET=my_bearer_client_secret
###< Ima_keycloak_bearer_only_adapter ###
...
Since Keycloak 17 the default distribution is now powered by Quarkus, while the legacy WildFly powered distribution will still be around until June 2022
The new distribution introduces a number of breaking changes, including:
/authremoved from the default context path
⚠️ If you are using a legacy version make sure to include /auth in OAUTH_KEYCLOAK_ISSUER
Example:keycloak:8080/auth
In case of using Keycloak with Docker locally replace issuer value with your keycloak container reference in the network
For example, you can use the service name, or container IPAdresse that you can get using this command:
docker inspect <container id> | grep "IPAddress"
Symfony security configuration
To secure your API with Keycloak you must change the default security configuration in symfony.
Here is a simple configuration that restrict access to /api/* routes only to user with role ROLE_USER :
# config/packages/security.yaml security: providers: keycloak_bearer_user_provider: id: IMA\Bundle\keycloakBearerOnlyAdapterBundle\Security\User\KeycloakBearerUserProvider firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false api: pattern: ^/api/ provider: keycloak_bearer_user_provider custom_authenticators: - IMA\Bundle\keycloakBearerOnlyAdapterBundle\Security\Authenticator\KeycloakBearerAuthenticator stateless: true access_control: - { path: ^/api/, roles: [ROLE_USER] }
ℹ️ Referring to Symfony documentation, roles must start with ROLE_ (otherwise, things won't work as expected)
Keycloak configuration
To configure keycloak to work with this bundle, here is a step by step documentation for a basic configuration of keycloak.
Compatibility
| Bundle Version | Symfony Version |
|---|---|
| V1.0.0 | >=6.4.0 |
ima/keycloak-bearer-only-adapter-bundle 适用场景与选型建议
ima/keycloak-bearer-only-adapter-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 623 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ima/keycloak-bearer-only-adapter-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ima/keycloak-bearer-only-adapter-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 623
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-18