test_that("client_secret optional when body auth + PKCE", { prov <- oauth_provider( name = "example", auth_url = "https://example.com/auth", token_url = "https://example.com/token", userinfo_url = NA_character_, introspection_url = NA_character_, issuer = NA_character_, use_nonce = FALSE, use_pkce = TRUE, pkce_method = "S256", userinfo_required = FALSE, id_token_required = FALSE, id_token_validation = FALSE, userinfo_id_token_match = FALSE, extra_auth_params = list(), extra_token_params = list(), extra_token_headers = character(), token_auth_style = "body", jwks_cache = cachem::cache_mem(max_age = 60), jwks_pins = character(), jwks_pin_mode = "any", allowed_algs = c("RS256", "ES256"), leeway = 60 ) expect_silent({ cl <- oauth_client( provider = prov, client_id = "abc", client_secret = "", # secretless public client redirect_uri = "http://localhost:8100", scopes = character(0) ) cl }) }) test_that("client_secret required when body auth without PKCE", { prov <- oauth_provider( name = "example", auth_url = "https://example.com/auth", token_url = "https://example.com/token", userinfo_url = NA_character_, introspection_url = NA_character_, issuer = NA_character_, use_nonce = FALSE, use_pkce = FALSE, pkce_method = "S256", userinfo_required = FALSE, id_token_required = FALSE, id_token_validation = FALSE, userinfo_id_token_match = FALSE, extra_auth_params = list(), extra_token_params = list(), extra_token_headers = character(), token_auth_style = "body", jwks_cache = cachem::cache_mem(max_age = 60), jwks_pins = character(), jwks_pin_mode = "any", allowed_algs = c("RS256", "ES256"), leeway = 60 ) expect_error( oauth_client( provider = prov, client_id = "abc", client_secret = "", redirect_uri = "http://localhost:8100", scopes = character(0) ), "client_secret is required unless using PKCE" ) }) test_that("client_secret required when header auth", { prov <- oauth_provider( name = "example", auth_url = "https://example.com/auth", token_url = "https://example.com/token", userinfo_url = NA_character_, introspection_url = NA_character_, issuer = NA_character_, use_nonce = FALSE, use_pkce = TRUE, # even with PKCE, header auth should require secret pkce_method = "S256", userinfo_required = FALSE, id_token_required = FALSE, id_token_validation = FALSE, userinfo_id_token_match = FALSE, extra_auth_params = list(), extra_token_params = list(), extra_token_headers = character(), token_auth_style = "header", jwks_cache = cachem::cache_mem(max_age = 60), jwks_pins = character(), jwks_pin_mode = "any", allowed_algs = c("RS256", "ES256"), leeway = 60 ) expect_error( oauth_client( provider = prov, client_id = "abc", client_secret = "", redirect_uri = "http://localhost:8100", scopes = character(0) ), "client_secret is required when token_auth_style = 'header'" ) })