|
| 1 | +# Troubleshooting guide |
| 2 | + |
| 3 | +This guide describes the most common errors you can experience when using the API and the solutions to fix them. |
| 4 | + |
| 5 | +## Missing client id |
| 6 | + |
| 7 | +Two problems can be the cause of the following response when authenticating to the API: |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "code": 422, |
| 12 | + "message": "Parameter "client_id" is missing or does not match any client, or secret is invalid" |
| 13 | +} |
| 14 | +``` |
| 15 | + |
| 16 | +### Base 64 not correctly encoded |
| 17 | + |
| 18 | +You are not correctly encoding client and secret in base 64. |
| 19 | +We encourage you to use the [Postman collection](/getting-started-postman-collection.html) or the [PHP client](/php-client/introduction.html), that handle it automatically for you. |
| 20 | + |
| 21 | +If you use the command line to generate the base 64, please ensure that you do it this way: |
| 22 | + |
| 23 | +```bash |
| 24 | +echo -n "client_id:secret" | base64 |
| 25 | +``` |
| 26 | + |
| 27 | +Do note the option `-n` to avoid to print the trailing newline character and encode it. |
| 28 | + |
| 29 | +If you still experience the same error, please follow the second solution. |
| 30 | + |
| 31 | +### Apache strip the authentication header |
| 32 | + |
| 33 | +If you are sure to provide the correct base 64 of the client and secret, it probably means that Apache is not correctly set up. |
| 34 | +Various Apache modules can strip the authorization header “Authorization: Basic base64client_id:secret”. |
| 35 | + |
| 36 | +Add the following line in your virtual host file: |
| 37 | + |
| 38 | +``` |
| 39 | +SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 |
| 40 | +``` |
| 41 | + |
| 42 | +## Redirection on connection page |
| 43 | + |
| 44 | +When requesting the API, you are redirected to the API, with any endpoints. |
| 45 | + |
| 46 | +This problem occurs when the project has been updated from version 1.6. |
| 47 | +It is coming from the security file `app/config/security.yml` in the PIM project. |
| 48 | + |
| 49 | +The declaration order of the keys is important in this file. |
| 50 | +If the key `security.firewalls.main` is before the keys `security.firewalls.token`, `security.firewalls.api_index` and `security.firewalls.api`, you will be redirected on requesting page when using the API. |
| 51 | + |
| 52 | +Please check that the keys under `security.firewalls` are in this following order: |
| 53 | +``` |
| 54 | +oauth_token: |
| 55 | + pattern: ^/api/oauth/v1/token |
| 56 | + security: false |
| 57 | +
|
| 58 | +api_index: |
| 59 | + pattern: ^/api/rest/v1$ |
| 60 | + security: false |
| 61 | +
|
| 62 | +api: |
| 63 | + pattern: ^/api |
| 64 | + fos_oauth: true |
| 65 | + stateless: true |
| 66 | + access_denied_handler: pim_api.security.access_denied_handler |
| 67 | +
|
| 68 | +main: |
| 69 | + pattern: ^/ |
| 70 | + provider: chain_provider |
| 71 | + form_login: |
| 72 | + csrf_token_generator: security.csrf.token_manager |
| 73 | + check_path: oro_user_security_check |
| 74 | + login_path: oro_user_security_login |
| 75 | + logout: |
| 76 | + path: oro_user_security_logout |
| 77 | + remember_me: |
| 78 | + secret: "%secret%" |
| 79 | + name: BAPRM |
| 80 | + lifetime: 1209600 # stay logged for two weeks |
| 81 | + anonymous: false |
| 82 | +``` |
| 83 | + |
0 commit comments