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

API key authentication for REST API's #3013

Merged
merged 5 commits into from Jan 11, 2023

Conversation

koolgax99
Copy link
Contributor

Description

This feature will introduce the concept of API keys in the PEcAn REST API's, an API key shall be passed by the user in the header X-API-Key

The API would be more secure now and in the future we can use this API key to track the requests from the user.

Review Time Estimate

  • Immediately
  • Within one week
  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@koolgax99 koolgax99 changed the title added API key authentication for REST API's API key authentication for REST API's Aug 10, 2022
Comment on lines +48 to +58
validate_api_key <- function(api_key) {
res <- tbl(global_db_pool, "users") %>%
filter(apikey == api_key) %>%
collect()

if (nrow(res) == 1) {
return(res)
}

return(NA)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure how you're planning on having the users store the API key, but often packages have users put it in a .Renviron file. Then, the validate_api_key can look for the key there by default. An example: https://github.com/ropensci/webchem/blob/18e551609c8f1aa371f83aad1b281540e9df1066/R/chemspider.R#L22

@mdietze mdietze merged commit 971a22e into PecanProject:develop Jan 11, 2023
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.

None yet

4 participants