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

OAuth docs #334

Merged
merged 32 commits into from
Oct 16, 2023
Merged

OAuth docs #334

merged 32 commits into from
Oct 16, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Oct 8, 2023

To do:

  • Add a section on caching that's inherited across all pages
  • Check all args passed through
  • Move cache_key and cache_disk to end of arg list
  • Review reference index
  • Update vignette

Fixes #330

@hadley hadley requested a review from jennybc October 8, 2023 21:21
@hadley
Copy link
Member Author

hadley commented Oct 8, 2023

@llrs please take a look and let me know if this makes it more clear how to actually authenticate a request with OAuth.

@maelle I'd love your feedback too, if you have time.

@hadley hadley marked this pull request as ready for review October 8, 2023 22:24
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
hadley and others added 3 commits October 10, 2023 07:26
Co-authored-by: Maximilian Girlich <maximilian.girlich@metoda.com>
Copy link

@llrs llrs left a comment

Choose a reason for hiding this comment

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

I see that now most of the documentation has moved to the req_oauth_auth_code help page and then some sections reused in other pages (But there are some missing the cache section).

I see oauth_flow_auth_code_url is now internal but not oauth_flow_auth_code_listen, oauth_flow_auth_code_parse or oauth_flow_auth_code_pkce. I'm not sure if this was on purpose or not.

I've left some comments in the vignette.
There is also a comment on a help page that hasn't changed in this PR, but I think it is in line with the title of the PR, and might help too other readers.

Thanks for keeping me in the loop.


I tried building the pkgdown to easily review the changes but I couldn't build it:

pkgdown::build_site()
## ...
## Reading 'vignettes/httr2.Rmd'
## -- RMarkdown error -------------------------------------------------------------
## 
## Quitting from lines 35-37 [unnamed-chunk-2] (httr2.Rmd)
## --------------------------------------------------------------------------------
## Error: 
## ! in callr subprocess.
## Caused by error in `map(.x, .f, ..., .progress = .progress)`:
## ! In index: 3.
## ℹ See `$stdout` for standard output.
## Type .Last.error to see the more details.

vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
R/oauth-flow-refresh.R Outdated Show resolved Hide resolved
@hadley
Copy link
Member Author

hadley commented Oct 11, 2023

Thanks @llrs! All the flows that can use caching should have the caching section, but quite a few don't support caching.

FWIW it's not the functions that are internal or doc, but the doc page, and all those functions are documented together.

Copy link
Contributor

@maelle maelle left a comment

Choose a reason for hiding this comment

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

Great to see more OAuth docs!

Before reviewing I re-read my own blog post and saw that in a comment I had wondered whether things would be simpler with httr2 😉 r-hub/blog#155 (comment)

I added a few comments.

vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Show resolved Hide resolved
This is going to be painful, but unfortunately there's no way around it.
I recommend using `with_verbosity()` so you can see exactly what httr2 is sending to the server.
You'll then need to carefully compare this to the API documentation and play "spot the difference".
You're very welcome to file an issue and I'll do my best to help you out.
Copy link
Contributor

Choose a reason for hiding this comment

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

also point to the community forum? it might be less intimidating.

Copy link
Member Author

Choose a reason for hiding this comment

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

Less intimidating, but I don't read them so also less helpful 😆

#'
#' Learn more about the overall OAuth authentication flow in `vignette("oauth")`.
#'
#' # Caching
Copy link
Contributor

Choose a reason for hiding this comment

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

this reminds me of one topic that is often a hurdle: how to use OAuth on a server, how to provide the token (maybe just a link to https://gargle.r-lib.org/articles/managing-tokens-securely.html since it shows the idea)

vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
Copy link
Contributor

@jonthegeek jonthegeek left a comment

Choose a reason for hiding this comment

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

This is great! It balances "oauth is hard and weird" vs "don't be afraid to play with it" well.

vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
hadley and others added 2 commits October 13, 2023 06:40
Co-authored-by: Jon Harmon <jonthegeek@gmail.com>
Copy link
Contributor

@jonthegeek jonthegeek left a comment

Choose a reason for hiding this comment

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

Even better! My biggest stumbling block learning oauth was getting past "But why are there all these steps???" The hierarchy of tokens helps with that quite a lot! Maybe mention "authorization code" in there as well (as the super short-lived but most capturable one)?

vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
Copy link
Contributor

@maelle maelle left a comment

Choose a reason for hiding this comment

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

Very useful new section! I added a few more comments, in particular about the refresh token.

vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Show resolved Hide resolved
hadley and others added 2 commits October 13, 2023 19:09
Co-authored-by: Jon Harmon <jonthegeek@gmail.com>
Copy link
Contributor

@jonthegeek jonthegeek left a comment

Choose a reason for hiding this comment

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

Just a couple typos.

vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
Co-authored-by: Jon Harmon <jonthegeek@gmail.com>
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
The process varies from API to API, but at the end of it you'll get a client id and in most cases a client secret.
The first step in working with any OAuth API is to create an **application** **client**.
It's called an application client because in the wider world OAuth is usually used with a web, phone, or tv app, but here your "app" is going to be your R package.
For this reason, httr2 calls the application client a **client**, but many APIs will call it an OAuth application.
Copy link
Member

Choose a reason for hiding this comment

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

FWIW it feels like Google thinks of "your piece of software / your project" as the application and then that application might make use of multiple clients, e.g. a desktop client, a web client, etc.

The vocabulary is sort of a nightmare, so, yeah, the main point is preparing an R user to not recognize themselves or their use case in any of the documentation.

vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Show resolved Hide resolved
vignettes/articles/oauth.Rmd Outdated Show resolved Hide resolved
hadley and others added 3 commits October 16, 2023 13:11
Co-authored-by: Jennifer (Jenny) Bryan <jenny.f.bryan@gmail.com>
#Conflicts:
#	NEWS.md
#	man/paginate_req_perform.Rd
Copy link
Contributor

@jonthegeek jonthegeek left a comment

Choose a reason for hiding this comment

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

Typo in news. I think I got the correct name for the deprecated function.


* httr2 now informs the user when a token is cached.

* `req_perform_stream()` replaces `req_perform_stream()`. `req_perform_stream()`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `req_perform_stream()` replaces `req_perform_stream()`. `req_perform_stream()`
* `req_perform_stream()` replaces `req_stream()`. `req_stream()`

@hadley hadley merged commit 0059238 into main Oct 16, 2023
@hadley hadley deleted the oauth-docs branch October 16, 2023 18:37
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.

Improve OAuth docs
6 participants