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

Implement oauth_token_cached() #349

Merged
merged 4 commits into from
Oct 20, 2023
Merged

Implement oauth_token_cached() #349

merged 4 commits into from
Oct 20, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Oct 16, 2023

Fixes #328

@fh-mthomson does this look like it will be adequate for your needs? I think your code would look something like this:

oauth_token <- function() {
  OAUTH_AUTHORIZE_ENDPOINT <- "https://<X>.okta.com/oauth2/<X>/v1/authorize"
  REDIRECT_URI <- "https://<X>"
  SCOPE <- "session:role-any"
  
  oauth_token_cached(
    client = client,
    flow = oauth_flow_auth_code,
    flow_params = list(
      auth_url = OAUTH_AUTHORIZE_ENDPOINT,
      scope = SCOPE,
      redirect_uri = REDIRECT_URI
    ),
    cache_disk = TRUE
  )
}

oauth_client <- function() {
  OAUTH_CLIENT_ID <- "<X>"
  OAUTH_TOKEN_ENDPOINT <- "https://<X>.okta.com/oauth2/<X>/v1/token"
  
  httr2::oauth_client(
    id = OAUTH_CLIENT_ID,
    token_url = OAUTH_TOKEN_ENDPOINT,
    name = "oauth_client"
  )
}

@fh-mthomson
Copy link
Contributor

This is exactly what I was hoping for! Thank you!

R/oauth.R Outdated Show resolved Hide resolved
@hadley hadley merged commit adc3a62 into main Oct 20, 2023
12 checks passed
@hadley hadley deleted the token-cache branch October 20, 2023 22:03
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.

Move token (a) caching and (b) refresh token layer from req_oauth_*() to oauth_flow*()
2 participants