Support resource field for legacy ROPC flow; normalize expires_in handling#351
Support resource field for legacy ROPC flow; normalize expires_in handling#351simonrob merged 9 commits intosimonrob:mainfrom
Conversation
…dling Enable the resource parameter for ROPC against v1 token endpoints and coerce any string expires_in values to integers on receipt, preventing int + str errors in expiry calculations.
simonrob
left a comment
There was a problem hiding this comment.
Thanks for the PR! I've reviewed it and left some comments. Can you point to documentation for the syntax of this flow?
The main documentation that I referenced to was this: https://www.cnblogs.com/CQman/p/16469223.html (in Chinese). The 21Vianet server does not accept a scope value. Resource is required for authentication. |
|
I've updated the code to fix most of the problems mentioned in your comments. Thanks! |
|
Thanks for the updates. I've fixed an indentation issue, cast |
|
It works! Checks have been completed on my own server, authentication successful with a resource parameter sent to 21Vianet. |
|
I have updated the configuration file with regards to this change. |
|
Excellent – I made a few final very minor refinements, but I think this is now ready to go. Thanks for the contribution! |
This pull request enhances the OAuth 2.0 authentication flow in
emailproxy.pyby introducing support foroauth2_resourceas an alternative tooauth2_scope, refining the handling of different OAuth 2.0 flows, and improving error handling and token normalization. Below are the key changes grouped by theme:Support for
oauth2_resource:oauth2_resourceas an optional configuration parameter retrieved viaAppConfig.get_option_with_catch_all_fallback. This allows specifying a resource instead of a scope for OAuth 2.0 flows. ([emailproxy.pyR742](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88R742))oauth2_scopeoroauth2_resourcewhentoken_urlandclient_idare provided. ([emailproxy.pyL755-R756](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88L755-R756))get_oauth2_authorisation_tokensmethod to includeoauth2_resourcein the request parameters when applicable. ([[1]](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88L1169-R1176),[[2]](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88L1195-R1237))Refinements to OAuth 2.0 flow handling:
authorization_codeunless the flow is explicitly specified asdeviceorpassword. ([emailproxy.pyR887](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88R887))Improved error handling and token normalization:
expires_invalue to an integer, with error logging for invalid values. ([emailproxy.pyL1195-R1237](https://github.com/simonrob/email-oauth2-proxy/pull/351/files#diff-8068eda2feddbc61595ced559aa73f8502813cf5cb1190a21e111ab1e8d19e88L1195-R1237))