承接 nti/keycloak-security-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nti/keycloak-security-bundle

最新稳定版本:v2.0.0

Composer 安装命令:

composer require nti/keycloak-security-bundle

包简介

Allows you to easily handle you application security thanks to keycloak.

README 文档

README

This Symfony bundle is an alternative solution to FOSUserBundle, working with keycloak.

Installation

With composer:

$ composer require nti/keycloak-security-bundle

Configuration

If you want to set up keycloak locally you can download it here and follow instructions from the official documentation. In case that you want to use keycloak in docker go directly to configuration for Docker.

Bundle configuration

Basic

In case of you already have keycloak running locally on your machine or is running remotely but without proxy, here is the default configuration you should use:

# config/packages/nti_keycloak_security.yaml
nti_keycloak_security:
    server_url: 'http://localhost:8080/auth' # your accessible keycloak url
    # server_url: 'http://keycloak.example.com/auth' # example with public url
    realm: 'MyRealm'
    client_id: 'my-client'
    client_secret: '21d4cc5c-9ed6-4bf8-8528-6d659b66f216'
    default_target_path: 'home' # The route name you will be redirected to after sign in

Docker

If you want to use keycloak in docker you can base your stack on this sample.

Here is a stack example configuration for docker swarm:

# config/packages/nti_keycloak_security.yaml
nti_keycloak_security:
    server_public_url: 'http://keycloak.docker/auth' # your keycloak url accessible via your navigator
    server_private_url: 'http://keycloak:8080/auth' # your keycloak container reference in the network
    realm: 'MyRealm'
    client_id: 'my-client'
    client_secret: '21d4cc5c-9ed6-4bf8-8528-6d659b66f216'
    default_target_path: 'home' # The route you will be redirected to after sign in

Make sure that your php container in the container is attached to a network with keycloak, otherwise it will not be able to resolve "http://keycloak:8080/auth" and the public_server_url must be accessible through the port 80 because keycloak verify the issuer.

Route configuration

Create a new file in config/routes/ to load pre configured bundle routes.

# config/routes/nti_keycloak_security.yaml
KeycloakSecurityBundle:
    resource: "@KeycloakSecurityBundle/Resources/config/routing.yaml"
    prefix: /

Symfony security configuration

To link keycloak with symfony you must change the default security configuration in symfony.

Here is a simple configuration that restrict access to /admin/* routes only to user with role "ROLE_ADMIN" :

# config/packages/security.yaml
imports:
    - { resource: '@KeycloakSecurityBundle/Resources/config/security.yaml' } # import our security provider

security:

    firewalls:

        # Authorize everyone to try connecting (this route is imported from our bundle routing configuration)
        auth_connect:
            pattern: ^/auth/connect/.*
            security: false

        # This bundle is using security guard provided by symfony
        # Login form authentication
        secured_area:
            pattern: ^/admin
            guard:
                provider: nti_keycloak_security_provider
                authenticators:
                    - NTI\KeycloakSecurityBundle\Security\Authenticator\KeycloakAuthenticator

        # Bearer token authentication
        api:
            pattern: ^/api
            guard:
                provider: nti_keycloak_bearer_security_provider
                authenticators:
                    - NTI\KeycloakSecurityBundle\Security\Authenticator\KeycloakBearerAuthenticator

    role_hierarchy:
        ROLE_ADMIN: ROLE_USER

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/api, roles: ROLE_API }

Keycloak configuration

If you need help to use keycloak because it is the first time you work on it, we've made a little tutorial step by step describing a basic configuration of a keycloak realm that you can found here

TODO

  • Install bundle configuration with flex recipe.

统计信息

  • 总下载量: 1.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 49
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固