我浏览了几个使用集中登录服务的解决方案。
我的情况如下:
- login.domain.tld 下的中央登录
- backend.domain.tld 下的后端
- 客户服务位于:support.domain.tld
- frontend.domain.tld 下的前端
- accounts.domain.tld 下的帐户和发票
我使用正确的路由设置 Symfony oauth 服务器的朋友,如配置中提到的,包括表等。
我还为 backend.domain.tld 添加了 oauth 登录令牌等
据我所知,一切都按原样设置。(配置不多)
在后端我安装了版本 0.6.x 的 hwi_oauth 包
这些是配置文件:
httplug.yaml:
httplug:
plugins:
redirect:
preserve_header: true
discovery:
client: 'auto'
clients:
default:
factory: 'httplug.factory.curl'
app:
http_methods_client: true
plugins:
- 'httplug.plugin.content_length'
- 'httplug.plugin.redirect'
hwi_special:
factory: 'httplug.factory.guzzle6'
config: # You pass here the Guzzle configuration, exactly like before.
timeout: 10
verify: false
max_redirects: 1
ignore_errors: false
HWI_oauth.yaml
hwi_oauth:
http:
client: httplug.client.hwi_special
firewall_names: [ main ]
resource_owners:
domain_oauth:
type: oauth2
client_id: '%env(OAUTH_CLIENT_ID)%'
client_secret: '%env(OAUTH_CLIENT_TOKEN)%'
access_token_url: '%env(OAUTH_PROVIDER)%'
authorization_url: '%env(OAUTH_AUTHORISATION)%'
options:
csrf: true
infos_url: '%env(OAUTH_USERINFO)%'
scope: "read"
user_response_class: HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse
paths:
identifier: id
nickname: username
realname: fullname
env 文件是必需的,因为我需要替换开发系统 url(xxx.domain.test 与其生产对应)
安全.yaml
security:
access_control:
- path: ^/login
roles: [ IS_AUTHENTICATED_ANONYMOUSLY ]
requires_channel: https
- path: ^/
roles: ROLE_STAFF
requires_channel: https
providers:
domain_provider:
entity:
class: Domain\Library\EntitiesBundle\Entities\User\User
property: email
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
oauth:
resource_owners:
domain_oauth: "/login/domainLogin"
login_path: "/login"
use_forward: true
failure_path: "/login"
oauth_user_provider:
service: Domain\Library\ClientAuthBundle\Authorisation\HwiOAuthProvider
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
role_hierarchy:
ROLE_GUEST:
ROLE_USER: [ ROLE_GUEST ]
ROLE_STAFF: [ ROLE_USER ]
Bundle Domain\Library\EntitiesBundle\Entities\User\User 是一个私有包,包含所有迁移数据和实体表。
最后但并非最不重要的 twi_oauth_routing.yaml
# app/config/routing.yml
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect_41.xml"
prefix: /connect
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect_41.xml"
prefix: /connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login_41.xml"
prefix: /login
domain_oauth_login:
path: /login/domainLogin
我目前面临的困难是,当我调用 backend.domain.test/login 时,我看不到登录系统上的连接尝试我看到一个指向 /connect/domain-oauth 的链接(我从来没有在任何地方配置)。如果我点击它,它会将我重定向到 /login 但我在日志中看不到连接。
我监督的任何线索?我试图让这个工作大约一个星期。通过几个例子工作,但我无法让它正常工作。
任何帮助表示赞赏。
软件:Symfony 4.2、PHP7.3 MySQL 8、Redis 作为缓存
更新:到目前为止,我能够让它工作。我缺少 /connect/.... 路径的 access_control 规则。
现在我可以看到一个允许/拒绝按钮。
但是只要我允许我进入分析器,以下 url 就会被重定向到登录页面:
我错过了什么?我不知道这个错误试图告诉我什么。