Creating a User Using a Remote Authentication Provider (LDAP)
Problem
You want to create a user and your Posit Connect server is configured with LDAP authentication.
Solution
Obtain a temporary ticket using the remote users API and then create the user.
from posit import connect
= "francism"
USERNAME
= connect.Client()
client = client.get("v1/users/remote", params={"prefix": USERNAME})
response = response.json()['results'] results
The results
object contains a single entry with the username francism. Notice that the guid
field is empty, which means that the user has not been created on Connect.
>>> import polars as pl
>>> pl.DataFrame(results)
1, 12)
shape: (
┌───────────────┬──────────┬────────────┬───────────┬───┬───────────┬────────┬──────┬──────────────┐
│ email ┆ username ┆ first_name ┆ last_name ┆ … ┆ confirmed ┆ locked ┆ guid ┆ temp_ticket │--- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ ┆ bool ┆ bool ┆ null ┆ str │
│
╞═══════════════╪══════════╪════════════╪═══════════╪═══╪═══════════╪════════╪══════╪══════════════╡@posit┆ francism ┆ Myra ┆ Francis ┆ … ┆ true ┆ false ┆ null ┆ QNb7ST5XTnQ9 │
│ FrancisM-9.com ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ /nX2pIy9xRNB │
│
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ LeKafO… │ └───────────────┴──────────┴────────────┴───────────┴───┴───────────┴────────┴──────┴──────────────┘
The field temp_ticket
can be used in a subsequent request to create an account on Connect.
= results[0]['temp_ticket']
ticket = client.put("v1/users", json={"temp_ticket": ticket})
response = response.json() user
>>> pl.DataFrame(user)
1, 11)
shape: (
┌────────────┬──────────┬────────────┬───────────┬───┬────────────┬───────────┬────────┬───────────┐
│ email ┆ username ┆ first_name ┆ last_name ┆ … ┆ active_tim ┆ confirmed ┆ locked ┆ guid │--- ┆ --- ┆ --- ┆ --- ┆ ┆ e ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ ┆ --- ┆ bool ┆ bool ┆ str │
│
│ ┆ ┆ ┆ ┆ ┆ null ┆ ┆ ┆ │
╞════════════╪══════════╪════════════╪═══════════╪═══╪════════════╪═══════════╪════════╪═══════════╡@p ┆ francism ┆ Myra ┆ Francis ┆ … ┆ null ┆ true ┆ false ┆ deb96ce5- │
│ FrancisM-9.com ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ e865-4fce │
│ osit-8b46-999 │
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆
│ ┆ ┆ ┆ ┆ ┆ ┆ ┆ ┆ be9… │ └────────────┴──────────┴────────────┴───────────┴───┴────────────┴───────────┴────────┴───────────┘
Full example
from posit import connect
= "francism"
USERNAME
= connect.Client()
client
= client.get("v1/users/remote", params={"prefix": USERNAME})
response = response.json()['results'][0]['temp_ticket']
ticket = client.put("v1/users", json={"temp_ticket": ticket})
response = response.json() user
Call the users_create_remote
function to create a user.
library(connectapi)
= "francism"
USERNAME
<- connect()
client <- users_create_remote(client, prefix = USERNAME) users
When the call succeeds, the response contains a non-NULL
guid
value, which is a unique identifier for the user’s account on Connect.
> users
# A tibble: 1 × 11
email username first_name last_name user_role created_time updated_time active_time confirmed locked guid<chr> <chr> <chr> <chr> <chr> <dttm> <dttm> <dttm> <lgl> <lgl> <chr>
1 FrancisM@posit-9.c… francism Myra Francis viewer 2024-06-07 19:35:30 2024-06-07 19:35:30 NA TRUE FALSE deb96ce5-e86…