Skip to content

Generation of api tokens and the use of said tokens for the api endpoints - #1170

Open
AlexandreDoneux wants to merge 5 commits into
INGInious:mainfrom
AlexandreDoneux:api_token
Open

AlexandreDoneux wants to merge 5 commits into
INGInious:mainfrom
AlexandreDoneux:api_token

Conversation

@AlexandreDoneux

Copy link
Copy Markdown
Contributor

As discussed, we divide PR #1121 into smaller ones. This is the first of those.

This PR focuses on the token generation and it's use for the current endpoints. A user can generate up to 20 tokens and giving to each a description. With these tokens he can use the submissions, courses and tasks endpoints, instead of using the flask session and authenticating with the related endpoint. Note the flask session is still a valid way to authenticate to the endpoints.
A user can of course delete a token if needed.

A PR will follow addressing the security concerns made by @nrybowski and hide information sent back to the user (course not found, task not found, etc.).

I thought about adding a page to the docs regarding the use of the endpoints (authentication with the two different methods). Where should it be located in the docs ?

@codacy-production

codacy-production Bot commented Sep 9, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 critical · 2 medium

Alerts:
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
Security 2 critical
Complexity 2 medium

View in Codacy

🟢 Metrics 34 complexity · 0 duplication

Metric Results
Complexity 34
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@AlexandreDoneux

Copy link
Copy Markdown
Contributor Author

Also note this PR is based on #1169.

@anthonygego anthonygego left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Things are getting better but there is still issues to be addressed.

Please also add some docs in the developer section.

Comment thread inginious/frontend/models/user.py Outdated
Comment thread inginious/frontend/models/user.py Outdated
Comment thread inginious/frontend/models/user.py Outdated
Comment thread inginious/frontend/pages/api/_api_page.py Outdated
Comment thread inginious/frontend/pages/api/_api_page.py Outdated
Comment thread inginious/frontend/templates/apitoken.html Outdated
Comment thread inginious/frontend/templates/apitoken.html Outdated
Comment thread inginious/frontend/templates/apitoken.html Outdated
Comment thread inginious/frontend/installer.py Outdated
Comment thread configuration.deploy.yaml Outdated
@AlexandreDoneux

Copy link
Copy Markdown
Contributor Author

I will address the model validation remarks in a following PR to not overcharge this one.

Comment thread doc/dev_doc/API/api_usage.rst Outdated
Comment thread inginious/frontend/pages/api/submissions.py Outdated
Comment thread inginious/frontend/pages/preferences/apitoken.py
Comment thread inginious/frontend/installer.py Outdated
Comment thread inginious/frontend/task_problems.py Outdated
Comment thread doc/dev_doc/API/api_usage.rst Outdated
Comment thread doc/dev_doc/API/api_usage.rst Outdated
Comment thread doc/dev_doc/API/api_usage.rst Outdated
Comment thread doc/dev_doc/API/api_usage.rst Outdated
Comment thread inginious/frontend/models/user.py Outdated
Comment thread inginious/frontend/pages/api/_api_page.py Outdated
Comment thread inginious/frontend/pages/api/submissions.py Outdated
Comment thread inginious/frontend/app.py Outdated
Comment thread inginious/frontend/submission_manager.py Outdated
Comment thread inginious/frontend/submission_manager.py Outdated

@anthonygego anthonygego left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has eventually reached my acceptance level.

@nrybowski can you perform a last pass on this ?

Comment on lines +265 to 273
if session.is_lti: # TODO : refactor not to use session here
lti_info = session.lti.to_mongo().to_dict()
for key in lti_info:
if key == "consumer_key" or key.startswith("outcome"): # Skip "consumer_key" and "outcome*"
continue
self._logger.debug("LTI data : %s, %s",key, lti_info[key])
# Add @lti_ prefix
key_str = "@lti_" + key
inputdata[key_str] = lti_info[key]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note : I actually don't see any good reason for keeping this code. I don't find any usage in our own task database, it forwards host-platform specific information, it is not documented, and it only filters out LTI 1.1 critical fields.

I think it can just be removed in another PR.

This branch has not been deployed

No deployments
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