Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(get_hydroseq)
export(get_node)
export(layer_exists)
export(lynker_spatial_auth)
export(lynker_spatial_url)
export(node_geometry)
export(read_hydrofabric)
export(read_sf_dataset)
Expand Down
19 changes: 15 additions & 4 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#' @param libs Supported libraries to configure auth for.
#' @param duckdb_con A DuckDB DBI connection to add a bearer token secret to.
#' @returns The `token` argument, or a newly provisioned token
#'
#' @details
#' lynker_spatial.auth.token
#'
#' @export
lynker_spatial_auth <- function(
token = NULL,
token = getOption("lynker_spatial.token"),
...,
libs = c("gdal", "duckdb"),
duckdb_con = NULL
Expand Down Expand Up @@ -79,19 +83,26 @@ lynker_spatial_client <- function() {
#' @keywords internal
lynker_spatial_token <- function(..., client = lynker_spatial_client()) {
# Get the token using the OIDC client
httr2::oauth_flow_auth_code(
token <- httr2::oauth_flow_auth_code(
client,
auth_url = client$provider$authorization_endpoint,
scope = "openid profile email phone",
redirect_uri = client$redirect_uri,
pkce = TRUE
)

options("lynker_spatial.token" = token)
token
}

#' Refresh an existing Lynker Spatial token
#' @keywords internal
lynker_spatial_refresh <- function(token, ..., client = lynker_spatial_client()) {
if (!inherits(token, "httr2_token")) {
lynker_spatial_refresh <- function(token = getOption("lynker_spatial.token"), ..., client = lynker_spatial_client()) {
if (inherits(token, "httr2_token")) {
refresh_token <- token$refresh_token
} else if (is.character(token)) {
refresh_token <- token
} else {
stop("token is malformed", call. = FALSE)
}

Expand Down
5 changes: 4 additions & 1 deletion man/lynker_spatial_auth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/lynker_spatial_refresh.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/lynker_spatial_url.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading