【问题标题】:Oauth2 in Symfony 5 error : Key path "file:///var/oauth/private.key" does not exist or is not readableSymfony 5 中的 Oauth2 错误:密钥路径“file:///var/oauth/private.key”不存在或不可读
【发布时间】:2020-08-03 20:37:23
【问题描述】:

我使用 Symfony 5 和 oauth2 捆绑包 trikoder/oauth2-bundle 在 Web 应用程序中构建了一个 oauth2 服务器,以便登录其他客户端站点的用户。当客户端站点激活授权请求时,我收到此错误。我在 Stackoverflow 上阅读了这个问题的答案,但他们回答的是 Laravel 问题,而不是 Symfony 5。 这是 .env 文件:

###> trikoder/oauth2-bundle ###

后备 OAuth2 加密密钥

请用安全值覆盖它:https://oauth2.thephpleague.com/installation/#string-password

OAUTH2_STRING_PASSWORD=4YUuCt##################x2wsEdg

OAUTH2_ENCRYPTION_KEY=def########################################## ###########cbf

这里是 config/packages/trikoder_oauth2.yaml 文件

trikoder_oauth2:

authorization_server:
    private_key: /var/oauth/private.key                     # Change this
    private_key_passphrase: null                            # Passphrase of the private key, if any

    encryption_key: '%env(string:OAUTH2_ENCRYPTION_KEY)%'   # (Optional) Change this
    encryption_key_type: "defuse"
    # How long the issued access token should be valid for.
        # The value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
    access_token_ttl:     PT1H

        # How long the issued refresh token should be valid for.
        # The value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
    refresh_token_ttl:    P1M

        # How long the issued auth code should be valid for.
        # The value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
    auth_code_ttl:        PT10M



resource_server:
    public_key: /var/oauth/public.key                       # Change this

persistence:
    doctrine: null

public.key 和 private.key 在 var/auth/ 路径中。 客户端是在 oauth2_client 表中创建的,带有两个参数 identifier 和 secret。 非常感谢您的回复! 阿兰·朱夫

【问题讨论】:

    标签: symfony oauth-2.0 private-key


    【解决方案1】:

    这只是你的配置中的一个错字吗?

    /var/oauth/private.key 而不是您描述的 /var/auth/private.key?

    【讨论】:

    • 非常感谢您的回答。路径真的是var/oauth/,我
    • 我的消息中的错误不在我的系统中。
    • 如果在服务器应用程序中识别出用户,则会发生此错误。但是如果没有用户登录,则呈现服务器的索引页面,而不是登录表单。
    • 对此我不确定,我需要运行一个示例并对其进行调试。但是错误“文件不存在或不可读”往往是读取权限的一些问题(如果它确实存在)。你检查正确了吗?
    • 问题已解决:trikoder_oauth2.yaml 文件中的路径错误:/var/oauth/ 代替了正确的 var/oauth/。
    【解决方案2】:

    您只需更改 public.key 和 private.key 的文件所有者,如下所示:

    sudo chown -R www:data:www-data public.key private.key
    

    这应该可以解决您的问题,如果不让我知道,我会帮助您。

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多