使用 salesforce 连接的应用程序时 Symfony 出错

error in Symfony while using salesforce connected app

在我的 Symfony2 项目中,我需要 loginSalesforce 用户,所以我安装了 HwiOAuthBundle 并在 Salesforce 中创建了一个 connected app 以获得客户和密钥,但是当我在我的 Symfony2 应用程序中尝试 login 时,我得到了这个奇怪的错误:

error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

在咨询了许多论坛后,我认为我在 Salesforce 中遇到回调 url 问题。

我也有 facebook 配置,可以用 facebook 用户登录,它对我有用,但对 SalesForce 就不行。

这是 salesforce 中连接的应用程序的配置:

Connected App Name: testApp
Email: my own email
Logo Image URL  : i choosed the default one that salesforce provide
Icon URL    : same as Logo Image URL    
callback url:http://localhost/Annonces/web/app_dev.php/platform/oauth/callback
Selected OAuth Scopes : Full access

以及 Symfony 中的配置: config.yml

hwi_oauth:
  firewall_name: main
  http_client:
      verify_peer: false     
  resource_owners:
    facebook:
      type: facebook
      client_id: "%oauth.facebook.id%"
      client_secret: "%oauth.facebook.secret%"
      scope: "email"
    salesforce:
        type: salesforce
        client_id: "%oauth.salesforce.id%"
        client_secret: "%oauth.salesforce.secret%"

security.yml

security:

    acl:
        connection: default

    encoders:
        OC\UserBundle\Entity\User: sha512

    role_hierarchy:
        ROLE_USER:        ROLE_USER
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

    providers:        
        mine:
            id: ib_user.oauth_user_provider

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false                         

        main:
            pattern: ^/
            anonymous: true

            oauth:
                resource_owners:
                    facebook: "/login/check-facebook"
                    salesforce: "/login/check-salesforce"
                login_path: /login
                failure_path: /login
                default_target_path: /platform
                oauth_user_provider: 
                    service: ib_user.oauth_user_provider


    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, roles: ROLE_ADMIN }

routing.yml

oc_platform:
    resource: "@OCPlatformBundle/Resources/config/routing.yml"
    prefix:   /platform     

user_logout:
     resource: "@OCUserBundle/Resources/config/routing.yml"  
     prefix:   /logout 

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /login

hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect

facebook_login: 
    pattern: /login/check-facebook   

salesforce_login: 
    pattern: /login/check-salesforce      

我终于找到了解决方案:在 salesforce 中的 connected app 中,我将 callback url 参数设置为: http://localhost/Annonces/web/app_dev.php/login/check-salesforce

所以我刚刚添加:/login/check-salesforce 并且有效。