|
15 | 15 | #' model, with support for personal access tokens, OAuth machine-to-machine |
16 | 16 | #' credentials, and OAuth user-to-machine credentials supplied via Posit |
17 | 17 | #' Workbench or the Databricks CLI on desktop. It can also detect viewer-based |
18 | | -#' credentials on Posit Connect if the \pkg{connectcreds} package is |
19 | | -#' installed. All of these credentials are detected automatically if present |
20 | | -#' using [standard environment variables](https://docs.databricks.com/en/dev-tools/auth.html#environment-variables-and-fields-for-client-unified-authentication). |
| 18 | +#' and service principal credentials on Posit Connect if the \pkg{connectcreds} |
| 19 | +#' package is installed. All of these credentials are detected automatically if |
| 20 | +#' present using [standard environment variables](https://docs.databricks.com/en/dev-tools/auth.html#environment-variables-and-fields-for-client-unified-authentication). |
21 | 21 | #' |
22 | 22 | #' In addition, on macOS platforms, the `dbConnect()` method will check |
23 | 23 | #' for irregularities with how the driver is configured, |
|
49 | 49 | #' httpPath = "sql/protocolv1/o/4425955464597947/1026-023828-vn51jugj" |
50 | 50 | #' ) |
51 | 51 | #' |
52 | | -#' # Use credentials from the viewer (when possible) in a Shiny app |
53 | | -#' # deployed to Posit Connect. |
| 52 | +#' # Use credentials from the viewer or a service principal (when possible) in |
| 53 | +#' # a Shiny app deployed to Posit Connect. |
54 | 54 | #' library(connectcreds) |
55 | 55 | #' server <- function(input, output, session) { |
56 | 56 | #' conn <- DBI::dbConnect( |
57 | 57 | #' odbc::databricks(), |
| 58 | +#' workspace = "https://example.cloud.databricks.com", |
58 | 59 | #' httpPath = "sql/protocolv1/o/4425955464597947/1026-023828-vn51jugj" |
59 | 60 | #' ) |
60 | 61 | #' } |
@@ -134,9 +135,12 @@ databricks_args <- function(httpPath, |
134 | 135 | if (running_on_connect()) { |
135 | 136 | msg <- c( |
136 | 137 | msg, |
137 | | - "i" = "Or consider enabling Posit Connect's Databricks integration \ |
138 | | - for viewer-based credentials. See {.url \ |
139 | | - https://docs.posit.co/connect/user/oauth-integrations/#adding-oauth-integrations-to-deployed-content} |
| 138 | + "i" = "Or consider enabling Posit Connect's Databricks integration. \ |
| 139 | + For viewer-based credentials. See {.url \ |
| 140 | + https://docs.posit.co/connect/user/oauth-integrations/#viewer-oauth-integrations} |
| 141 | + for details. \ |
| 142 | + For service principal credentials, see {.url \ |
| 143 | + https://docs.posit.co/connect/user/oauth-integrations/#service-account-oauth-integrations} |
140 | 144 | for details." |
141 | 145 | ) |
142 | 146 | } |
@@ -227,6 +231,15 @@ databricks_auth_args <- function(host, uid = NULL, pwd = NULL) { |
227 | 231 | )) |
228 | 232 | } |
229 | 233 |
|
| 234 | + if (is_installed("connectcreds") && connectcreds::has_service_account_token(workspace)) { |
| 235 | + token <- connectcreds::connect_service_account_token(workspace) |
| 236 | + return(list( |
| 237 | + authMech = 11, |
| 238 | + auth_flow = 0, |
| 239 | + auth_accesstoken = token$access_token |
| 240 | + )) |
| 241 | + } |
| 242 | + |
230 | 243 | if (!is.null(uid) && !is.null(pwd)) { |
231 | 244 | return(list(uid = uid, pwd = pwd, authMech = 3)) |
232 | 245 | } else if (xor(is.null(uid), is.null(pwd))) { |
|
0 commit comments