Support personal API token authentication (read from file)#65
Open
kshepherd wants to merge 1 commit intothe-library-code:mainfrom
Open
Support personal API token authentication (read from file)#65kshepherd wants to merge 1 commit intothe-library-code:mainfrom
kshepherd wants to merge 1 commit intothe-library-code:mainfrom
Conversation
If no token is found, fall back to standard password auth
Collaborator
Author
|
@quintusdias would you like to try this small change out and give feedback re: implementing personal API token auth for DSpace CRIS instances? |
|
I don't have a DSpace CRIS instance at the moment, unfortunately. I can look into trying to set one up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DSpace-CRIS supports personal API tokens (JWTs with very long expiry) generated by users from their profile page.
DSpace core will soon support this too.
Partially addreses #23
This pull request adds support for token authentication instead of simple username and password auth.
Tokens are detected by the following methods, in order:
PERSONAL_API_TOKEN_FILEis set (e.g. by docker compose or in env while executing a script), try to read from a file path using the value of the env vara. To be clear, the value of the env var should NOT be the token itself, but a path to the token that the user executing the script can read.
.dspace-personal-api-token.secretexists in the current working directory of the script, try to read it.dspace-personal-api-token.secretexists in the current user's home directory, try to read itIf no token is found, fall back to standard password auth
If a token is found, it will be set as the Authorization Bearer header instead of requesting short-lived JWT bearer tokens.
I have given this a quick test on my demo CRIS instance and it appears to work but more testing would be appreciated. Standard password auth still works if no token is present. Would appreciate feedback about the token path candidates. If it is safer and less confusing to just require that _FILE env var, I can understand that.
Expected output:
Other notes:
THIS = os.environ(that)setup is ugly and not good style, and will eventually be cleaned up into nice__init__instance initialisation, but for now that's out of scope of this PR, I just want to try and support this auth method ASAP.