Prepare an OAuth 2.0 authorization request and build its URL
Source:R/methods__login.R
prepare_call.RdPrepare a login request and return the URL to open in the user's browser.
Use this when your application controls the browser redirect and callback
handling itself but needs shinyOAuth to construct the OAuth 2.0 authorization
request. Pair it with handle_callback() to complete the code flow.
Arguments
- client
An OAuthClient object.
- browser_token
Browser-bound token used to tie the login attempt to the current browser session.
- request_uri_publisher
Optional function used when
request_object_mode = "request_uri". It must acceptrequest_object,request_handle_id,expires_at, andoauth_clientarguments and return an absolute HTTPS request-object URL that the provider can fetch.- oauth_client
Compatibility alias for
client. Supply only one spelling.
Value
A length-1 string containing the authorization URL to send the user
to. When PAR is used, the returned string also carries
shinyOAuth.par_request_uri, shinyOAuth.par_expires_in, and
shinyOAuth.par_expires_at attributes so callers can tell when the pushed
authorization request should be regenerated.
Details
In a Shiny app using oauth_module_server(), call auth[["request_login"]]()
to start login through the module, which manages both operations and the
reactive session state.
The helper records one-time state and creates any required PKCE and nonce
values. Custom callers must preserve the browser binding and process the
returning callback themselves.
For an explicitly configured POST client, use prepare_authorization_request()
instead. This URL-only helper rejects POST before storing a transaction.
Examples
# Advanced example: your code supplies browser redirects and callback handling.
# For a Shiny app, oauth_module_server() manages these steps for you.
if (interactive()) {
# Define client
client <- oauth_client(
provider = oauth_provider_github(),
client_id = Sys.getenv("GITHUB_OAUTH_CLIENT_ID"),
client_secret = Sys.getenv("GITHUB_OAUTH_CLIENT_SECRET"),
redirect_uri = "http://127.0.0.1:8100"
)
# Get the login URL and store state in client's state store
# `<browser_token>` must be unpredictable and persisted for this transaction
# in storage bound to the application's exact origin (scheme, host, port).
# The module combines origin-scoped storage with an independent marker cookie
# and checks both on return. A cookie alone does not provide this boundary:
# cookies can be shared by applications on different ports of the same host.
# Shiny applications should use oauth_module_server() for the complete flow.
authorization_url <- prepare_call(client, "<browser_token>")
# Redirect user to authorization URL; retrieve code & state from the query;
# recover this transaction's `<browser_token>` through the origin-bound flow
# and verify its independent marker before calling handle_callback().
code <- "..."
state <- "..."
browser_token <- "..."
# Handle callback, exchanging code for token and validating state
token <- handle_callback(client, code, state, browser_token)
}