rstudio / rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
http://rstudio.github.io/rsconnect/
131 stars 80 forks source link

connectApiUser generates partial configuration #402

Closed jeffkeller87 closed 4 years ago

jeffkeller87 commented 4 years ago

The rsconnect::connectApiUser function doesn't appear to generate a usable account configuration.

server_url <- "https://connect.my-company.io/"
server_name <- "connect.my-company.io"
account <- "jeff.keller@my-company.com"
apiKey <- Sys.getenv("RSTUDIO_CONNECT_API_KEY")
rsconnect::addServer(url = server_url, name = server_name)
rsconnect::connectApiUser(account = account, server = server_name, apiKey = apiKey)

This generates the file

~/.config/R/rsconnect/accounts/connect.my-company.io/jeff.keller@my-company.com

with contents

username: jeff.keller@my-company.com
accountId: 0
apiKey: <REDACTED>
server: connect.my-company.io

Which doesn't work for publishing content to Connect. If I "reconnect" the account through the RStudio GUI, the contents of the .dcf file become:

username: jeff.keller@my-company.com
accountId: 3
token: <REDACTED>
server: connect.my-company.io
private_key:
           <REDACTED>

Which works fine for publishing. How can I use rsconnect:connectApiUser to publish content without authenticating via the browser?

Software versions rsconnect v0.8.16 RStudio Connect v1.7.8-7 Build "1144ac9"

jeffkeller87 commented 4 years ago

Additional info: our RStudio Connect installation uses SAML to integrate with Okta for account management.

schloerke commented 4 years ago

The Shiny team would like to use this feature and are running into this issue as well. (Getting the accountId would get the team unstuck.)

rsconnect::connectApiUser(
  "barret", 
  "beta.rstudioconnect.com", 
  apiKey = "supersecretkey"
)
#> 
#> Account registered successfully: barret

rsconnect::accounts()
#>              name                      server
#> 1          barret     beta.rstudioconnect.com

rsconnect::accountInfo("barret", "beta.rstudioconnect.com")
#> $username
#> [1] "barret"
#> 
#> $accountId
#> [1] "0"
#> 
#> $apiKey
#> [1] "supersecretkey"
#> 
#> $server
#> [1] "beta.rstudioconnect.com"
adamconroy commented 4 years ago

Understood, I will be starting work on this on Feb 22 and will update with my progress.

jeffkeller87 commented 3 years ago

I am still having issues with connectUserApi() using rsconnect 0.8.17. It now correctly generates a .dcf account file with a non-zero account ID, but when I attempt to deploy a document, I get a 404 error from the Connect server.

> rsconnect::deployDoc(doc = "test.Rmd")
# Discovering document dependencies... OK
# Preparing to deploy document...Error: HTTP 404
# GET https://connect.decision-science.io/applications/483

Reconnecting the account via the RStudio GUI allows me to publish as expected, but this has the effect of modifying the account .dcf file to use a token and private key rather than the API key.

Possibly related to #507.

jeffkeller87 commented 3 years ago

I got this working. The server URL in my original example was incomplete. It needs the /__api__ path:

rsconnect::addServer(url = "https://connect.my-company.io/__api__", name = "connect.my-company.io")
rsconnect::connectApiUser(account = "jeff.keller@my-company.com", server = "connect.my-company.io", apiKey = "MY_KEY")
luma-sb commented 1 year ago

I got this working. The server URL in my original example was incomplete. It needs the /__api__ path:

rsconnect::addServer(url = "https://connect.my-company.io/__api__", name = "connect.my-company.io")
rsconnect::connectApiUser(account = "jeff.keller@my-company.com", server = "connect.my-company.io", apiKey = "MY_KEY")

Thank you for sharing your solution @jeffkeller87 - nearly 2 years later and I've run into the exact same issue and adding /__api__ to path resolved for me as well. Wish this was better documented.

aronatkins commented 1 year ago

The rsconnect::addConnectServer function helps make sure that the Connect URL includes /__api__. Agreed that we should include additional/better examples and documentation.