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

feat: API to login and get user username, name and email #7455

Merged
merged 1 commit into from
Oct 10, 2022
Merged

Conversation

stephanegigandet
Copy link
Contributor

@stephanegigandet stephanegigandet commented Oct 7, 2022

This is to address #7361 so that the Flutter app can get the username and name of an user who authenticated with an email address.

but it could also be a step to have a more uniform handling of errors in the API (specifically errors related to users not identified or bad logins and passwords supplied).

I'm proposing that we extend the /cgi/auth.pl API which currently:

  • checks if an user is identified (either through a session cookie on the *.openfoodfacts.org domain, or by passing user_id and password)
  • returns a 200 status code if the user is logged in, or a 403 otherwise

The extension would be to add a JSON body:

  • when the user is logged in:
{
    "status": 1,
    "status_verbose": "user signed-in",
    "user": {
        "email": "my email",
        "name": "Stéphane Gigandet"
    },
    "user_id": "test2"
}
  • when the user is not logged in:
{
    "status": 0,
    "status_verbose": "user not signed-in"
}

With the proposed code, this behaviour would only apply to /cgi/auth.pl

But we could decide to extend it to all other API calls (e.g. product edit). If invalid userid / password are supplied, we return a JSON body to explain why (instead of returning an HTML content today).

I think we could keep the existing status: 0 that we have in most APIs I think (get and search product, product edit, auth), and maybe add an "error" id + and "error_message" in the language requested.

cc @VaiTon @M123-dev @monsieurtanuki @g123k

@sonarcloud
Copy link

sonarcloud bot commented Oct 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@M123-dev
Copy link
Member

M123-dev commented Oct 7, 2022

I love the response body, as long as the Status Codes don't change and so break the older versions I really like this feature.

Same goes for the other api calls. It will be a relieve if we can just foreward a consistent error to the sdk user instead of manually parsing the html and extracting errors out of it. Especially if the messages are translated.

@alexgarel
Copy link
Member

@stephanegigandet would you add it to the api.yml file ?

cgi/auth.pl Show resolved Hide resolved
@stephanegigandet
Copy link
Contributor Author

@stephanegigandet would you add it to the api.yml file ?

Yes, I wanted to discuss it a bit before writing the documentation.

@hangy
Copy link
Member

hangy commented Oct 7, 2022

What's the integration story for Ory's Hydra & Kratos? It seems like there might be some feature overlap with OIDC profile claims.

@alexgarel
Copy link
Member

What's the integration story for Ory's Hydra & Kratos? It seems like there might be some feature overlap with OIDC profile claims.

We might take info from Ory Kratos when it's integrated, but it will take some times.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

LGTM.

Maybe, if you can, document before merging :-) (or after then)

@monsieurtanuki
Copy link
Contributor

Cool feature! Ready to implement it on off-dart when it's merged here.

@VaiTon VaiTon merged commit e142269 into main Oct 10, 2022
@VaiTon VaiTon deleted the auth-api branch October 10, 2022 14:56
@teolemon teolemon added the 🔐 API auth The API requires auth in order to perform editing.There is a common mechanism & a Robotoff mechanism label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔐 API auth The API requires auth in order to perform editing.There is a common mechanism & a Robotoff mechanism Display
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants