首页 文章

symfony4 UserProviderInterface实现与api调用authentification

提问于
浏览
2

我正在开发一个symfony4 webapp . 用户帐户存储在可通过API访问的DB中 .

我想实现这个UserProviderInterface,因为advised by the symfony4 documentation使用symfony4安全模块功能 .

如果我理解,实现此接口需要API(或服务或db ...)返回将由symfony安全性检查的数据(例如散列密码/ salt) .

有没有办法使用symfony安全模块而无需从用户提供程序获取此类数据?

例如,将用户以登录形式输入的用户名和密码发送到api,这将检查它是否正确并返回bool?

1 回答

  • 1

    您可以实现自己的 Guard Authenticator 来手动执行身份验证检查 .

    文档章节中描述了一个很好的示例实现:

    How to Create a Custom Authentication System with Guard

    示例配置如下所示:

    security:
      firewalls:
        firewall_api:
          pattern: '^/(.*)+$'
          host:    '^api\.mypage\.com$'
          stateless: true
          anonymous: false
          guard:
            # list of authenticators to try
            authenticators:
              - 'My\Bridge\Symfony\Security\Authenticator\Guard\JWTTokenAuthenticator'
              - 'My\Bridge\Symfony\Security\Authenticator\Guard\FacebookAuthenticator'
            # This authenticator's start() method is called
            entry_point: 'My\Bridge\Symfony\Security\Authenticator\Guard\JWTTokenAuthenticator'
    

相关问题