hikari
hikari copied to clipboard
Add OAuthCredentialsStrategy
Summary
Add OAuthCredentialsStrategy
to hikari\impl\rest.py
similar to ClientCredentialsStrategy
to allow simple OAuth2 token generation and refreshing.
I have used this code on my own project and it works from my testing.
I do not know how to make the tests for this except by copying from the ones for ClientCredentialsStrategy
and I tried but I do not know how to use the mock stuff. I am also not sure which tests I will need. Don't be afraid to be harsh giving feedback on what to do or I did.
Idea from: https://discord.com/channels/574921006817476608/1088176194874257428
Checklist
- [x] I have run
nox
and all the pipelines have passed. - [x] I have made unittests according to the code I have added/modified/deleted.
Related issues
- None
I ran into an issue with making the tests for OAuthCredentialsStrategy
and the last tests I have done are getting the error TypeError: object Mock can't be used in 'await' expression
. The code is the only tests that are erroring and all for that same error. Altered from ClientCredentialsStrategy
Use a mock.AsyncMock
instead of mock.Mock
Getting an error of pytest.PytestUnraisableExceptionWarning: Exception ignored in: <coroutine object AsyncMockMixin._execute_mock_call at 0x00000267A82C7A70>
Full Nox Traceback: https://pastebin.com/f6qkWLkU Failing Test Code: https://pastebin.com/MzV1D7BX Updated Class: https://pastebin.com/TbHKr2Ad
Thought I fixed those typing errors for mypy. Will fix when back home
Everything should be ready
I don't know how I feel about this tbh. The reason this wasn't implemented in the first place was since it felt like having this implemented as a standard thing would just be encouraging bad behaviour (which is still the case).
When handling Oauth2 tokens you'd really want to be storing the current version of the token (likely in a database) to persist it between bot restarts and only refreshing it after it's expired but this doesn't really allow for that.
Also I'm not sure what the use case is for this.
I was thinking of using it for a restapp for interacting with user's information. If this isn't used, I'll use it for my personal project without it being in hikari itself.
When handling Oauth2 tokens you'd really want to be storing the current version of the token (likely in a database) to persist it between bot restarts and only refreshing it after it's expired but this doesn't really allow for that.
Could that be fixed by just allowing passing the token and refresh token to the strategy?