Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mbapi #134

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Feature/mbapi #134

wants to merge 4 commits into from

Conversation

frwg
Copy link
Contributor

@frwg frwg commented Nov 4, 2024

  1. The key pair is generated using bin/console lexik:jwt:generate-keypair, with keys stored in application/config/jwt. This directory is excluded from version control via .gitignore and is integrated into the bootstrap command.

  2. When merging, ensure the dependent branch on mapbender/mapbender is merged first, then update composer.json and composer.lock to reflect any dependency changes.

  3. The JWT token can be obtained by sending authentication data (in JSON format: { "username": "<username>", "password": "<password>" }) to <server_url>/api/login_check.

Example Curl command:

curl -X POST http://mapbender.localhost/api/login_check  -H "Content-Type: application/json"  -d '{"username": "<username>", "password": "<password>"}'`
  1. Extend your virtual host configuration according to https://github.com/lexik/LexikJWTAuthenticationBundle/blob/3.x/Resources/doc/index.rst#important-note-for-apache-users

  2. The class responsible for handling API requests is located in mapbender/mapbender at application/mapbender/src/Mapbender/CoreBundle/Controller/ApiController.php. Access to endpoints such as <server_url>/api/example or <server_url>/api/my_custom_command is granted through this authentication token.

Example curl command:

curl -X GET -H "Authorization: Bearer <token>" http://mapbender.localhost/api/example

application/config/packages/doctrine.yaml Outdated Show resolved Hide resolved
application/.env Outdated Show resolved Hide resolved
application/symfony.lock Show resolved Hide resolved
@@ -15,6 +15,20 @@ security:
login:
pattern: ^/user/login$
security: false

jwt_login:
pattern: ^/api/login_check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the login check creates a html symfony message if the user does not exist, this should not happen in an API and rather return an appropriate error code:

grafik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should the response look like? Simple JSON containing an error code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, HTTP Code 401 should remain and IMO as body something like {"error": "User <username> not found"} is sufficient.

…from .env file and autogenerate it in bootstrap/remove database reference in doctrine.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants