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

Improve API client usability #1368

Merged
merged 70 commits into from
Sep 17, 2022
Merged

Improve API client usability #1368

merged 70 commits into from
Sep 17, 2022

Conversation

qwerty287
Copy link
Contributor

  • add an API token system. This assigns a token to every user which you can view, reset, copy etc. This token allows authorized access to API endpoints using the Authorization header.
  • do not require Content-Type and Accept headers, if they allow any type or are missing, ignore them, only if they are wrong an exception is thrown.
  • add an endpoint User::getCurrent which allows to get the user which is currently logged in

Closes #1356

@qwerty287
Copy link
Contributor Author

Does anybody know why the SQLite rollback migration fails and how I can fix it?

@codecov
Copy link

codecov bot commented Jun 26, 2022

Codecov Report

Merging #1368 (fc3fd82) into master (ed4240e) will decrease coverage by 0.50%.
The diff coverage is 97.14%.

❗ Current head fc3fd82 differs from pull request most recent head 35bac96. Consider uploading reports for the commit 35bac96 to get more accurate results

Additional details and impacted files

@qwerty287
Copy link
Contributor Author

qwerty287 commented Jun 26, 2022

I think CI failure is not related. (Only pgsql fails, MariaDB and locally SQLite work)

Copy link
Contributor

@kamil4 kamil4 left a comment

Choose a reason for hiding this comment

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

I left some (hopefully useful) comments, but somebody with a greater understanding of the api_key feature should have a look (I've never used it or even bothered to fully understand it).

app/Http/Middleware/AcceptContentType.php Outdated Show resolved Hide resolved
app/Http/Middleware/ContentType.php Outdated Show resolved Hide resolved
app/Http/Middleware/VerifyCsrfToken.php Outdated Show resolved Hide resolved
@ildyria
Copy link
Member

ildyria commented Jul 16, 2022

  • Merged from master.
  • fixed conflicts.
  • tested.
  • add possibility to disable the token feature by leaving it "empty".

Copy link
Member

@ildyria ildyria left a comment

Choose a reason for hiding this comment

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

Tested - LGTM.

@ildyria
Copy link
Member

ildyria commented Jul 16, 2022

@qwerty287 can you check if you are happy with my changes? :)

@nagmat84
Copy link
Collaborator

Please give me the chance to do a review, too, before merge.

@qwerty287
Copy link
Contributor Author

qwerty287 commented Jul 17, 2022

@ildyria in general yes, but adding the old api key for the admin means that an api key that had no permissions before now has admin permissions. I can fix it.

Copy link
Collaborator

@nagmat84 nagmat84 left a comment

Choose a reason for hiding this comment

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

No text (just a "review" such that GH remembers what I have already seen)

app/Http/Middleware/HasUserCheck.php Outdated Show resolved Hide resolved
app/Models/User.php Show resolved Hide resolved
Copy link
Collaborator

@nagmat84 nagmat84 left a comment

Choose a reason for hiding this comment

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

The only thing which remains to be done now, is step-debugging through user authentication middleware.

@nagmat84
Copy link
Collaborator

While I believe that the code is correct, I am currently unable to write proper tests for it. Again, the problem is that the application object survives between tests. As we already have had this problem once or twice and posted this question laravel/framework#44086.

In the past we could always help ourselves with some workaround, but in this case I am lost. I hope some answers.

@nagmat84
Copy link
Collaborator

And another one: laravel/framework#44088

@nagmat84
Copy link
Collaborator

I fixed the tests. While SessionOrTokenGuard has become more complicated than I initially thought, I am rather convinced that it should be fine. We have 96% test coverage and the only two lines which are not tested affect the "remember-me" token which we don't use.

Only two things remain:

@qwerty287 please check if you are fine with my changes and if the PR still does what you want it to do.

The issue #1368 (comment) needs to be addressed.

@qwerty287
Copy link
Contributor Author

How should I fix the sqlite issue? Don't remove the column if it's SQLite?

Changes are fine otherwise.

@nagmat84
Copy link
Collaborator

How should I fix the sqlite issue? Don't remove the column if it's SQLite?

For the same issue in other cases, we decided to not delete the column for any DBMS in order to keep the tables consistent between SQLite, MySQL and PostgreSQL. Otherwise it will be a nightmare to clean it up later.

Simply add the column to #1321 such that we do not forget about it. When I will be ready with an PR for #1462, the tables need an extensive change such that we can clean up all the postponed changes, too.

@qwerty287
Copy link
Contributor Author

Let's wait for the tests and merge then.

@qwerty287
Copy link
Contributor Author

Hmm GH Actions seems not to work 🤔

@nagmat84 nagmat84 merged commit 8c0bcb4 into master Sep 17, 2022
@nagmat84 nagmat84 deleted the api-tokens branch September 24, 2022 12:19
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.

[Enhancement] make API really usable with external clients
5 participants